Tighten gitsync public boundary · Entire

Tighten gitsync public boundary

d63bbb8main·

Soph·3mo ago·8 files·+362 added/-155 removed

Sessions

f2725f595f5cView transcript

Changes

8

134 unmodified lines

135
136
137
138
138
139
140
141
142
143
144

134 unmodified lines

if err != nil {
 return err
 }
 cfg.Scope.Mappings = append(cfg.Scope.Mappings, mapping)
 cfg.Scope.Mappings = append(cfg.Scope.Mappings, gitsync.RefMapping{
 Source: mapping.Source,
 Target: mapping.Target,
 })
 }

srcURL, err := normalizeRepoURL(cfg.SourceURL)

Mcmd/git-sync-bench/main.go+4/-1

104 unmodified lines

105
106
107
108
108
109
110
111
112
113
114
82 unmodified lines

197
198
199
197
200
201
202
203
204
205
206

104 unmodified lines

if err != nil {
 return err
 }
 req.Scope.Mappings = append(req.Scope.Mappings, mapping)
 req.Scope.Mappings = append(req.Scope.Mappings, gitsync.RefMapping{
 Source: mapping.Source,
 Target: mapping.Target,
 })
 }

if req.Source.URL == "" || req.Target.URL == "" {
82 unmodified lines

if req.Source.URL == "" || req.Target.URL == "" {

Mcmd/git-sync/main.go+8/-2

4 unmodified lines

5
6
7
8
9
10
11
67 unmodified lines

79
80
81
81
82
82
83
84
84
85
86
87
88
88
89
90
91
92
93
94
95
96
97
89
90
91
92
100
101
102
103
93
94
95
96
97
98
99
37 unmodified lines

137
138
139
140
141
142
143
144
145
146
147
148
4 unmodified lines

153
154
155
156
157
158
159
160
161
162
163
164
1 unmodified line

166
167
168
169
170
171
172
173
174
11 unmodified lines

186
187
188
189
190
191
192
193
194
195
196
197
183
198
199
200
201
9 unmodified lines

211
212
213
214
215
216
217
218
219
220
221
222
223
224

4 unmodified lines

fmt"
 net/http"

"github.com/soph/git-sync/internal/validation"
 "github.com/soph/git-sync/pkg/gitsync/internalbridge"
 }

67 unmodified lines

if err != nil {
 return internalbridge.Config{}, err
 }
 source := bridgeEndpoint(req.Source)
 sourceResolved := bridgeEndpointAuth(sourceAuth)
 var target *internalbridge.Endpoint
 targetAuth := internalbridge.EndpointAuth{}
 if req.Target != nil {
 targetAuth, err := c.authFor(ctx, *req.Target, TargetRole)
 resolvedTargetAuth, err := c.authFor(ctx, *req.Target, TargetRole)
 if err != nil {
 return internalbridge.Config{}, err
 }
 return internalbridge.ProbeConfig(
 source,
 sourceResolved,
 ptr(bridgeEndpoint(*req.Target)),
 bridgeEndpointAuth(targetAuth),
 internalbridge.ProtocolMode(req.Protocol),
 req.IncludeTags,
 req.CollectStats,
 c.httpClient,
 ), nil
 target = ptr(bridgeEndpoint(*req.Target))
 targetAuth = bridgeEndpointAuth(resolvedTargetAuth)
 }
 return internalbridge.ProbeConfig(
 source,
 sourceResolved,
 nil,
 internalbridge.EndpointAuth{},
 bridgeEndpoint(req.Source),
 bridgeEndpointAuth(sourceAuth),
 target,
 targetAuth,
 internalbridge.ProtocolMode(req.Protocol),
 req.IncludeTags,
 req.CollectStats,
 37 unmodified lines

if r.Target.URL == "" {
 return fmt.Errorf("target URL is required")
 }
 if _, err := validation.NormalizeProtocolMode(string(r.Policy.Protocol)); err != nil {
 return err
 }
 if _, err := validation.ValidateMappings(validationMappings(r.Scope.Mappings)); err != nil {
 return err
 }
 return nil
 }

4 unmodified lines

1 unmodified line

if r.Source.URL == "" {
 return fmt.Errorf("source URL is required")
 }
 if _, err := validation.NormalizeProtocolMode(string(r.Protocol)); err != nil {
 return err
 }
}

11 unmodified lines

}

func bridgeScope(scope RefScope) internalbridge.RefScope {
 mappings := make([]internalbridge.RefMapping, 0, len(scope.Mappings))
 for _, mapping := range scope.Mappings {
 mappings = append(mappings, internalbridge.RefMapping{
 Source: mapping.Source,
 Target: mapping.Target,
 })
 }
 return internalbridge.RefScope{
 Branches: append([]string(nil), scope.Branches...),
 Mappings: append([]internalbridge.RefMapping(nil), scope.Mappings...),
 Mappings: mappings,
 }
}

9 unmodified lines

func ptr[T any](v T) *T {
 return &v
}

func validationMappings(mappings []RefMapping) []validation.RefMapping {
 out := make([]validation.RefMapping, 0, len(mappings))
 for _, mapping := range mappings {
 out = append(out, validation.RefMapping{
 Source: mapping.Source,
 Target: mapping.Target,
 })
 }
 return out
}

Mpkg/gitsync/client.go+44/-18

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
11
12
13
17
18
19
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
20
21
22
10 unmodified lines

33
34
35
88
89
90
91
92
93
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
62
69
70
71
72
1 unmodified line

74
75
76
70
77
78
79
73
74
80
81
82
83
77
78
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

9 unmodified lines

type ProtocolMode string

type Config = syncer.Config
type Config struct {
 raw syncer.Config
}

const ProtocolAuto ProtocolMode = validation.ProtocolAuto
const ProtocolV1 ProtocolMode = validation.ProtocolV1
const ProtocolV2 ProtocolMode = validation.ProtocolV2

// Endpoint identifies a remote Git endpoint.
type Endpoint struct {
 URL string
 Protocol ProtocolMode
}

func ProbeConfig(source Endpoint, sourceAuth EndpointAuth, target *Endpoint, targetAuth EndpointAuth, protocol ProtocolMode, includeTags, collectStats bool, httpClient *http.Client) syncer.Config {
 func ProbeConfig(source Endpoint, sourceAuth EndpointAuth, target *Endpoint, targetAuth EndpointAuth, protocol ProtocolMode, includeTags, collectStats bool, httpClient *http.Client) Config {
 cfg := syncer.Config{
 Source: syncer.Endpoint{URL: source.URL, Username: sourceAuth.Username, Token: sourceAuth.Token, BearerToken: sourceAuth.BearerToken, SkipTLSVerify: sourceAuth.SkipTLSVerify},
 Source: ToSyncerEndpoint(source, sourceAuth),
 HTTPClient: httpClient,
 IncludeTags: includeTags,
 ShowStats: collectStats,
 ProtocolMode: protocolString(protocol),
}
 if target != nil {
 cfg.Target = syncer.Endpoint{URL: target.URL, Username: targetAuth.Username, Token: targetAuth.Token, BearerToken: targetAuth.BearerToken, SkipTLSVerify: targetAuth.SkipTLSVerify}
}
 return cfg
}
return Config{raw: cfg}
}

func SyncConfig(source Endpoint, sourceAuth EndpointAuth, target Endpoint, targetAuth EndpointAuth, scope RefScope, policy SyncPolicy, collectStats, dryRun bool, httpClient *http.Client) syncer.Config {
 return syncer.Config{
 Source: syncer.Endpoint{URL: source.URL, Username: sourceAuth.Username, Token: sourceAuth.Token, BearerToken: sourceAuth.BearerToken, SkipTLSVerify: sourceAuth.SkipTLSVerify},
 Target: syncer.Endpoint{URL: target.URL, Username: targetAuth.Username, Token: targetAuth.Token, BearerToken: targetAuth.BearerToken, SkipTLSVerify: targetAuth.SkipTLSVerify},
func SyncConfig(source Endpoint, sourceAuth EndpointAuth, target Endpoint, targetAuth EndpointAuth, scope RefScope, policy SyncPolicy, collectStats, dryRun bool, httpClient *http.Client) Config {
 return Config{raw: syncer.Config{
 Source: ToSyncerEndpoint(source, sourceAuth),
 Target: ToSyncerEndpoint(target, targetAuth),
 HTTPClient: httpClient,
 Branches: append([]string(nil), scope.Branches...),
 Mappings: append([]RefMapping(nil), scope.Mappings...),
 Mappings: validationMappings(scope.Mappings),
 IncludeTags: policy.IncludeTags,
 DryRun: dryRun,
 ShowStats: collectStats,
}}
}