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