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