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