forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repository_locator.go
496 lines (406 loc) · 19.4 KB
/
repository_locator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
72
73
74
75
76
77
78
79
80
81
82
83
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
package api
import (
"crypto/tls"
"net/http"
"strconv"
"time"
"code.cloudfoundry.org/cli/cf/api/appevents"
api_appfiles "code.cloudfoundry.org/cli/cf/api/appfiles"
"code.cloudfoundry.org/cli/cf/api/appinstances"
"code.cloudfoundry.org/cli/cf/api/applicationbits"
"code.cloudfoundry.org/cli/cf/api/applications"
"code.cloudfoundry.org/cli/cf/api/authentication"
"code.cloudfoundry.org/cli/cf/api/copyapplicationsource"
"code.cloudfoundry.org/cli/cf/api/environmentvariablegroups"
"code.cloudfoundry.org/cli/cf/api/featureflags"
"code.cloudfoundry.org/cli/cf/api/logs"
"code.cloudfoundry.org/cli/cf/api/organizations"
"code.cloudfoundry.org/cli/cf/api/password"
"code.cloudfoundry.org/cli/cf/api/quotas"
"code.cloudfoundry.org/cli/cf/api/securitygroups"
"code.cloudfoundry.org/cli/cf/api/securitygroups/defaults/running"
"code.cloudfoundry.org/cli/cf/api/securitygroups/defaults/staging"
securitygroupspaces "code.cloudfoundry.org/cli/cf/api/securitygroups/spaces"
"code.cloudfoundry.org/cli/cf/api/spacequotas"
"code.cloudfoundry.org/cli/cf/api/spaces"
"code.cloudfoundry.org/cli/cf/api/stacks"
"code.cloudfoundry.org/cli/cf/appfiles"
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
"code.cloudfoundry.org/cli/cf/net"
"code.cloudfoundry.org/cli/cf/terminal"
"code.cloudfoundry.org/cli/cf/trace"
"code.cloudfoundry.org/cli/cf/v3/repository"
v3client "github.com/cloudfoundry/go-ccapi/v3/client"
"github.com/cloudfoundry/noaa/consumer"
)
type RepositoryLocator struct {
authRepo authentication.Repository
curlRepo CurlRepository
endpointRepo coreconfig.EndpointRepository
organizationRepo organizations.OrganizationRepository
quotaRepo quotas.QuotaRepository
spaceRepo spaces.SpaceRepository
appRepo applications.Repository
appBitsRepo applicationbits.CloudControllerApplicationBitsRepository
appSummaryRepo AppSummaryRepository
appInstancesRepo appinstances.Repository
appEventsRepo appevents.Repository
appFilesRepo api_appfiles.Repository
domainRepo DomainRepository
routeRepo RouteRepository
routingAPIRepo RoutingAPIRepository
stackRepo stacks.StackRepository
serviceRepo ServiceRepository
serviceKeyRepo ServiceKeyRepository
serviceBindingRepo ServiceBindingRepository
routeServiceBindingRepo RouteServiceBindingRepository
serviceSummaryRepo ServiceSummaryRepository
userRepo UserRepository
passwordRepo password.Repository
logsRepo logs.Repository
authTokenRepo ServiceAuthTokenRepository
serviceBrokerRepo ServiceBrokerRepository
servicePlanRepo CloudControllerServicePlanRepository
servicePlanVisibilityRepo ServicePlanVisibilityRepository
userProvidedServiceInstanceRepo UserProvidedServiceInstanceRepository
buildpackRepo BuildpackRepository
buildpackBitsRepo BuildpackBitsRepository
securityGroupRepo securitygroups.SecurityGroupRepo
stagingSecurityGroupRepo staging.SecurityGroupsRepo
runningSecurityGroupRepo running.SecurityGroupsRepo
securityGroupSpaceBinder securitygroupspaces.SecurityGroupSpaceBinder
spaceQuotaRepo spacequotas.SpaceQuotaRepository
featureFlagRepo featureflags.FeatureFlagRepository
environmentVariableGroupRepo environmentvariablegroups.Repository
copyAppSourceRepo copyapplicationsource.Repository
v3Repository repository.Repository
}
const noaaRetryDefaultTimeout = 5 * time.Second
func NewRepositoryLocator(config coreconfig.ReadWriter, gatewaysByName map[string]net.Gateway, logger trace.Printer, envDialTimeout string) (loc RepositoryLocator) {
cloudControllerGateway := gatewaysByName["cloud-controller"]
routingAPIGateway := gatewaysByName["routing-api"]
uaaGateway := gatewaysByName["uaa"]
loc.authRepo = authentication.NewUAARepository(uaaGateway, config, net.NewRequestDumper(logger))
// ensure gateway refreshers are set before passing them by value to repositories
cloudControllerGateway.SetTokenRefresher(loc.authRepo)
uaaGateway.SetTokenRefresher(loc.authRepo)
loc.appBitsRepo = applicationbits.NewCloudControllerApplicationBitsRepository(config, cloudControllerGateway)
loc.appEventsRepo = appevents.NewCloudControllerAppEventsRepository(config, cloudControllerGateway)
loc.appFilesRepo = api_appfiles.NewCloudControllerAppFilesRepository(config, cloudControllerGateway)
loc.appRepo = applications.NewCloudControllerRepository(config, cloudControllerGateway)
loc.appSummaryRepo = NewCloudControllerAppSummaryRepository(config, cloudControllerGateway)
loc.appInstancesRepo = appinstances.NewCloudControllerAppInstancesRepository(config, cloudControllerGateway)
loc.authTokenRepo = NewCloudControllerServiceAuthTokenRepository(config, cloudControllerGateway)
loc.curlRepo = NewCloudControllerCurlRepository(config, cloudControllerGateway)
loc.domainRepo = NewCloudControllerDomainRepository(config, cloudControllerGateway)
loc.endpointRepo = NewEndpointRepository(cloudControllerGateway)
tlsConfig := net.NewTLSConfig([]tls.Certificate{}, config.IsSSLDisabled())
var noaaRetryTimeout time.Duration
convertedTime, err := strconv.Atoi(envDialTimeout)
if err != nil {
noaaRetryTimeout = noaaRetryDefaultTimeout
} else {
noaaRetryTimeout = time.Duration(convertedTime) * 3 * time.Second
}
consumer := consumer.New(config.DopplerEndpoint(), tlsConfig, http.ProxyFromEnvironment)
consumer.SetDebugPrinter(terminal.DebugPrinter{Logger: logger})
loc.logsRepo = logs.NewNoaaLogsRepository(config, consumer, loc.authRepo, noaaRetryTimeout)
loc.organizationRepo = organizations.NewCloudControllerOrganizationRepository(config, cloudControllerGateway)
loc.passwordRepo = password.NewCloudControllerRepository(config, uaaGateway)
loc.quotaRepo = quotas.NewCloudControllerQuotaRepository(config, cloudControllerGateway)
loc.routeRepo = NewCloudControllerRouteRepository(config, cloudControllerGateway)
loc.routeServiceBindingRepo = NewCloudControllerRouteServiceBindingRepository(config, cloudControllerGateway)
loc.routingAPIRepo = NewRoutingAPIRepository(config, routingAPIGateway)
loc.stackRepo = stacks.NewCloudControllerStackRepository(config, cloudControllerGateway)
loc.serviceRepo = NewCloudControllerServiceRepository(config, cloudControllerGateway)
loc.serviceKeyRepo = NewCloudControllerServiceKeyRepository(config, cloudControllerGateway)
loc.serviceBindingRepo = NewCloudControllerServiceBindingRepository(config, cloudControllerGateway)
loc.serviceBrokerRepo = NewCloudControllerServiceBrokerRepository(config, cloudControllerGateway)
loc.servicePlanRepo = NewCloudControllerServicePlanRepository(config, cloudControllerGateway)
loc.servicePlanVisibilityRepo = NewCloudControllerServicePlanVisibilityRepository(config, cloudControllerGateway)
loc.serviceSummaryRepo = NewCloudControllerServiceSummaryRepository(config, cloudControllerGateway)
loc.spaceRepo = spaces.NewCloudControllerSpaceRepository(config, cloudControllerGateway)
loc.userProvidedServiceInstanceRepo = NewCCUserProvidedServiceInstanceRepository(config, cloudControllerGateway)
loc.userRepo = NewCloudControllerUserRepository(config, uaaGateway, cloudControllerGateway)
loc.buildpackRepo = NewCloudControllerBuildpackRepository(config, cloudControllerGateway)
loc.buildpackBitsRepo = NewCloudControllerBuildpackBitsRepository(config, cloudControllerGateway, appfiles.ApplicationZipper{})
loc.securityGroupRepo = securitygroups.NewSecurityGroupRepo(config, cloudControllerGateway)
loc.stagingSecurityGroupRepo = staging.NewSecurityGroupsRepo(config, cloudControllerGateway)
loc.runningSecurityGroupRepo = running.NewSecurityGroupsRepo(config, cloudControllerGateway)
loc.securityGroupSpaceBinder = securitygroupspaces.NewSecurityGroupSpaceBinder(config, cloudControllerGateway)
loc.spaceQuotaRepo = spacequotas.NewCloudControllerSpaceQuotaRepository(config, cloudControllerGateway)
loc.featureFlagRepo = featureflags.NewCloudControllerFeatureFlagRepository(config, cloudControllerGateway)
loc.environmentVariableGroupRepo = environmentvariablegroups.NewCloudControllerRepository(config, cloudControllerGateway)
loc.copyAppSourceRepo = copyapplicationsource.NewCloudControllerCopyApplicationSourceRepository(config, cloudControllerGateway)
client := v3client.NewClient(config.APIEndpoint(), config.AuthenticationEndpoint(), config.AccessToken(), config.RefreshToken(), config.UAAOAuthClient(), config.UAAOAuthClientSecret())
loc.v3Repository = repository.NewRepository(config, client)
return
}
func (locator RepositoryLocator) SetAuthenticationRepository(repo authentication.Repository) RepositoryLocator {
locator.authRepo = repo
return locator
}
func (locator RepositoryLocator) GetAuthenticationRepository() authentication.Repository {
return locator.authRepo
}
func (locator RepositoryLocator) SetCurlRepository(repo CurlRepository) RepositoryLocator {
locator.curlRepo = repo
return locator
}
func (locator RepositoryLocator) GetCurlRepository() CurlRepository {
return locator.curlRepo
}
func (locator RepositoryLocator) GetEndpointRepository() coreconfig.EndpointRepository {
return locator.endpointRepo
}
func (locator RepositoryLocator) SetEndpointRepository(e coreconfig.EndpointRepository) RepositoryLocator {
locator.endpointRepo = e
return locator
}
func (locator RepositoryLocator) SetOrganizationRepository(repo organizations.OrganizationRepository) RepositoryLocator {
locator.organizationRepo = repo
return locator
}
func (locator RepositoryLocator) GetOrganizationRepository() organizations.OrganizationRepository {
return locator.organizationRepo
}
func (locator RepositoryLocator) SetQuotaRepository(repo quotas.QuotaRepository) RepositoryLocator {
locator.quotaRepo = repo
return locator
}
func (locator RepositoryLocator) GetQuotaRepository() quotas.QuotaRepository {
return locator.quotaRepo
}
func (locator RepositoryLocator) SetSpaceRepository(repo spaces.SpaceRepository) RepositoryLocator {
locator.spaceRepo = repo
return locator
}
func (locator RepositoryLocator) GetSpaceRepository() spaces.SpaceRepository {
return locator.spaceRepo
}
func (locator RepositoryLocator) SetApplicationRepository(repo applications.Repository) RepositoryLocator {
locator.appRepo = repo
return locator
}
func (locator RepositoryLocator) GetApplicationRepository() applications.Repository {
return locator.appRepo
}
func (locator RepositoryLocator) GetApplicationBitsRepository() applicationbits.Repository {
return locator.appBitsRepo
}
func (locator RepositoryLocator) SetAppSummaryRepository(repo AppSummaryRepository) RepositoryLocator {
locator.appSummaryRepo = repo
return locator
}
func (locator RepositoryLocator) SetUserRepository(repo UserRepository) RepositoryLocator {
locator.userRepo = repo
return locator
}
func (locator RepositoryLocator) GetAppSummaryRepository() AppSummaryRepository {
return locator.appSummaryRepo
}
func (locator RepositoryLocator) SetAppInstancesRepository(repo appinstances.Repository) RepositoryLocator {
locator.appInstancesRepo = repo
return locator
}
func (locator RepositoryLocator) GetAppInstancesRepository() appinstances.Repository {
return locator.appInstancesRepo
}
func (locator RepositoryLocator) SetAppEventsRepository(repo appevents.Repository) RepositoryLocator {
locator.appEventsRepo = repo
return locator
}
func (locator RepositoryLocator) GetAppEventsRepository() appevents.Repository {
return locator.appEventsRepo
}
func (locator RepositoryLocator) SetAppFileRepository(repo api_appfiles.Repository) RepositoryLocator {
locator.appFilesRepo = repo
return locator
}
func (locator RepositoryLocator) GetAppFilesRepository() api_appfiles.Repository {
return locator.appFilesRepo
}
func (locator RepositoryLocator) SetDomainRepository(repo DomainRepository) RepositoryLocator {
locator.domainRepo = repo
return locator
}
func (locator RepositoryLocator) GetDomainRepository() DomainRepository {
return locator.domainRepo
}
func (locator RepositoryLocator) SetRouteRepository(repo RouteRepository) RepositoryLocator {
locator.routeRepo = repo
return locator
}
func (locator RepositoryLocator) GetRoutingAPIRepository() RoutingAPIRepository {
return locator.routingAPIRepo
}
func (locator RepositoryLocator) SetRoutingAPIRepository(repo RoutingAPIRepository) RepositoryLocator {
locator.routingAPIRepo = repo
return locator
}
func (locator RepositoryLocator) GetRouteRepository() RouteRepository {
return locator.routeRepo
}
func (locator RepositoryLocator) SetStackRepository(repo stacks.StackRepository) RepositoryLocator {
locator.stackRepo = repo
return locator
}
func (locator RepositoryLocator) GetStackRepository() stacks.StackRepository {
return locator.stackRepo
}
func (locator RepositoryLocator) SetServiceRepository(repo ServiceRepository) RepositoryLocator {
locator.serviceRepo = repo
return locator
}
func (locator RepositoryLocator) GetServiceRepository() ServiceRepository {
return locator.serviceRepo
}
func (locator RepositoryLocator) SetServiceKeyRepository(repo ServiceKeyRepository) RepositoryLocator {
locator.serviceKeyRepo = repo
return locator
}
func (locator RepositoryLocator) GetServiceKeyRepository() ServiceKeyRepository {
return locator.serviceKeyRepo
}
func (locator RepositoryLocator) SetRouteServiceBindingRepository(repo RouteServiceBindingRepository) RepositoryLocator {
locator.routeServiceBindingRepo = repo
return locator
}
func (locator RepositoryLocator) GetRouteServiceBindingRepository() RouteServiceBindingRepository {
return locator.routeServiceBindingRepo
}
func (locator RepositoryLocator) SetServiceBindingRepository(repo ServiceBindingRepository) RepositoryLocator {
locator.serviceBindingRepo = repo
return locator
}
func (locator RepositoryLocator) GetServiceBindingRepository() ServiceBindingRepository {
return locator.serviceBindingRepo
}
func (locator RepositoryLocator) GetServiceSummaryRepository() ServiceSummaryRepository {
return locator.serviceSummaryRepo
}
func (locator RepositoryLocator) SetServiceSummaryRepository(repo ServiceSummaryRepository) RepositoryLocator {
locator.serviceSummaryRepo = repo
return locator
}
func (locator RepositoryLocator) GetUserRepository() UserRepository {
return locator.userRepo
}
func (locator RepositoryLocator) SetPasswordRepository(repo password.Repository) RepositoryLocator {
locator.passwordRepo = repo
return locator
}
func (locator RepositoryLocator) GetPasswordRepository() password.Repository {
return locator.passwordRepo
}
func (locator RepositoryLocator) SetLogsRepository(repo logs.Repository) RepositoryLocator {
locator.logsRepo = repo
return locator
}
func (locator RepositoryLocator) GetLogsRepository() logs.Repository {
return locator.logsRepo
}
func (locator RepositoryLocator) SetServiceAuthTokenRepository(repo ServiceAuthTokenRepository) RepositoryLocator {
locator.authTokenRepo = repo
return locator
}
func (locator RepositoryLocator) GetServiceAuthTokenRepository() ServiceAuthTokenRepository {
return locator.authTokenRepo
}
func (locator RepositoryLocator) SetServiceBrokerRepository(repo ServiceBrokerRepository) RepositoryLocator {
locator.serviceBrokerRepo = repo
return locator
}
func (locator RepositoryLocator) GetServiceBrokerRepository() ServiceBrokerRepository {
return locator.serviceBrokerRepo
}
func (locator RepositoryLocator) GetServicePlanRepository() ServicePlanRepository {
return locator.servicePlanRepo
}
func (locator RepositoryLocator) SetUserProvidedServiceInstanceRepository(repo UserProvidedServiceInstanceRepository) RepositoryLocator {
locator.userProvidedServiceInstanceRepo = repo
return locator
}
func (locator RepositoryLocator) GetUserProvidedServiceInstanceRepository() UserProvidedServiceInstanceRepository {
return locator.userProvidedServiceInstanceRepo
}
func (locator RepositoryLocator) SetBuildpackRepository(repo BuildpackRepository) RepositoryLocator {
locator.buildpackRepo = repo
return locator
}
func (locator RepositoryLocator) GetBuildpackRepository() BuildpackRepository {
return locator.buildpackRepo
}
func (locator RepositoryLocator) SetBuildpackBitsRepository(repo BuildpackBitsRepository) RepositoryLocator {
locator.buildpackBitsRepo = repo
return locator
}
func (locator RepositoryLocator) GetBuildpackBitsRepository() BuildpackBitsRepository {
return locator.buildpackBitsRepo
}
func (locator RepositoryLocator) SetSecurityGroupRepository(repo securitygroups.SecurityGroupRepo) RepositoryLocator {
locator.securityGroupRepo = repo
return locator
}
func (locator RepositoryLocator) GetSecurityGroupRepository() securitygroups.SecurityGroupRepo {
return locator.securityGroupRepo
}
func (locator RepositoryLocator) SetStagingSecurityGroupRepository(repo staging.SecurityGroupsRepo) RepositoryLocator {
locator.stagingSecurityGroupRepo = repo
return locator
}
func (locator RepositoryLocator) GetStagingSecurityGroupsRepository() staging.SecurityGroupsRepo {
return locator.stagingSecurityGroupRepo
}
func (locator RepositoryLocator) SetRunningSecurityGroupRepository(repo running.SecurityGroupsRepo) RepositoryLocator {
locator.runningSecurityGroupRepo = repo
return locator
}
func (locator RepositoryLocator) GetRunningSecurityGroupsRepository() running.SecurityGroupsRepo {
return locator.runningSecurityGroupRepo
}
func (locator RepositoryLocator) SetSecurityGroupSpaceBinder(repo securitygroupspaces.SecurityGroupSpaceBinder) RepositoryLocator {
locator.securityGroupSpaceBinder = repo
return locator
}
func (locator RepositoryLocator) GetSecurityGroupSpaceBinder() securitygroupspaces.SecurityGroupSpaceBinder {
return locator.securityGroupSpaceBinder
}
func (locator RepositoryLocator) GetServicePlanVisibilityRepository() ServicePlanVisibilityRepository {
return locator.servicePlanVisibilityRepo
}
func (locator RepositoryLocator) GetSpaceQuotaRepository() spacequotas.SpaceQuotaRepository {
return locator.spaceQuotaRepo
}
func (locator RepositoryLocator) SetSpaceQuotaRepository(repo spacequotas.SpaceQuotaRepository) RepositoryLocator {
locator.spaceQuotaRepo = repo
return locator
}
func (locator RepositoryLocator) SetFeatureFlagRepository(repo featureflags.FeatureFlagRepository) RepositoryLocator {
locator.featureFlagRepo = repo
return locator
}
func (locator RepositoryLocator) GetFeatureFlagRepository() featureflags.FeatureFlagRepository {
return locator.featureFlagRepo
}
func (locator RepositoryLocator) SetEnvironmentVariableGroupsRepository(repo environmentvariablegroups.Repository) RepositoryLocator {
locator.environmentVariableGroupRepo = repo
return locator
}
func (locator RepositoryLocator) GetEnvironmentVariableGroupsRepository() environmentvariablegroups.Repository {
return locator.environmentVariableGroupRepo
}
func (locator RepositoryLocator) SetCopyApplicationSourceRepository(repo copyapplicationsource.Repository) RepositoryLocator {
locator.copyAppSourceRepo = repo
return locator
}
func (locator RepositoryLocator) GetCopyApplicationSourceRepository() copyapplicationsource.Repository {
return locator.copyAppSourceRepo
}
func (locator RepositoryLocator) GetV3Repository() repository.Repository {
return locator.v3Repository
}
func (locator RepositoryLocator) SetV3Repository(r repository.Repository) RepositoryLocator {
locator.v3Repository = r
return locator
}