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