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