github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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  	"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  	passwordRepo                    password.Repository
    61  	logsRepo                        logs.Repository
    62  	authTokenRepo                   ServiceAuthTokenRepository
    63  	serviceBrokerRepo               ServiceBrokerRepository
    64  	servicePlanRepo                 CloudControllerServicePlanRepository
    65  	servicePlanVisibilityRepo       ServicePlanVisibilityRepository
    66  	userProvidedServiceInstanceRepo UserProvidedServiceInstanceRepository
    67  	buildpackRepo                   BuildpackRepository
    68  	buildpackBitsRepo               BuildpackBitsRepository
    69  	securityGroupRepo               securitygroups.SecurityGroupRepo
    70  	stagingSecurityGroupRepo        staging.SecurityGroupsRepo
    71  	runningSecurityGroupRepo        running.SecurityGroupsRepo
    72  	securityGroupSpaceBinder        securitygroupspaces.SecurityGroupSpaceBinder
    73  	spaceQuotaRepo                  spacequotas.SpaceQuotaRepository
    74  	featureFlagRepo                 featureflags.FeatureFlagRepository
    75  	environmentVariableGroupRepo    environmentvariablegroups.Repository
    76  	copyAppSourceRepo               copyapplicationsource.Repository
    77  }
    78  
    79  const noaaRetryDefaultTimeout = 5 * time.Second
    80  
    81  func NewRepositoryLocator(config coreconfig.ReadWriter, gatewaysByName map[string]net.Gateway, logger trace.Printer, envDialTimeout string) (loc RepositoryLocator) {
    82  	cloudControllerGateway := gatewaysByName["cloud-controller"]
    83  	routingAPIGateway := gatewaysByName["routing-api"]
    84  	uaaGateway := gatewaysByName["uaa"]
    85  	loc.authRepo = authentication.NewUAARepository(uaaGateway, config, net.NewRequestDumper(logger))
    86  
    87  	// ensure gateway refreshers are set before passing them by value to repositories
    88  	cloudControllerGateway.SetTokenRefresher(loc.authRepo)
    89  	uaaGateway.SetTokenRefresher(loc.authRepo)
    90  
    91  	loc.appBitsRepo = applicationbits.NewCloudControllerApplicationBitsRepository(config, cloudControllerGateway)
    92  	loc.appEventsRepo = appevents.NewCloudControllerAppEventsRepository(config, cloudControllerGateway)
    93  	loc.appFilesRepo = api_appfiles.NewCloudControllerAppFilesRepository(config, cloudControllerGateway)
    94  	loc.appRepo = applications.NewCloudControllerRepository(config, cloudControllerGateway)
    95  	loc.appSummaryRepo = NewCloudControllerAppSummaryRepository(config, cloudControllerGateway)
    96  	loc.appInstancesRepo = appinstances.NewCloudControllerAppInstancesRepository(config, cloudControllerGateway)
    97  	loc.authTokenRepo = NewCloudControllerServiceAuthTokenRepository(config, cloudControllerGateway)
    98  	loc.curlRepo = NewCloudControllerCurlRepository(config, cloudControllerGateway)
    99  	loc.domainRepo = NewCloudControllerDomainRepository(config, cloudControllerGateway)
   100  	loc.endpointRepo = NewEndpointRepository(cloudControllerGateway)
   101  
   102  	tlsConfig := net.NewTLSConfig([]tls.Certificate{}, config.IsSSLDisabled())
   103  
   104  	var noaaRetryTimeout time.Duration
   105  	convertedTime, err := strconv.Atoi(envDialTimeout)
   106  	if err != nil {
   107  		noaaRetryTimeout = noaaRetryDefaultTimeout
   108  	} else {
   109  		noaaRetryTimeout = time.Duration(convertedTime) * 3 * time.Second
   110  	}
   111  
   112  	consumer := consumer.New(config.DopplerEndpoint(), tlsConfig, http.ProxyFromEnvironment)
   113  	consumer.SetDebugPrinter(terminal.DebugPrinter{Logger: logger})
   114  	loc.logsRepo = logs.NewNoaaLogsRepository(config, consumer, loc.authRepo, noaaRetryTimeout)
   115  
   116  	loc.organizationRepo = organizations.NewCloudControllerOrganizationRepository(config, cloudControllerGateway)
   117  	loc.passwordRepo = password.NewCloudControllerRepository(config, uaaGateway)
   118  	loc.quotaRepo = quotas.NewCloudControllerQuotaRepository(config, cloudControllerGateway)
   119  	loc.routeRepo = NewCloudControllerRouteRepository(config, cloudControllerGateway)
   120  	loc.routeServiceBindingRepo = NewCloudControllerRouteServiceBindingRepository(config, cloudControllerGateway)
   121  	loc.routingAPIRepo = NewRoutingAPIRepository(config, routingAPIGateway)
   122  	loc.stackRepo = stacks.NewCloudControllerStackRepository(config, cloudControllerGateway)
   123  	loc.serviceRepo = NewCloudControllerServiceRepository(config, cloudControllerGateway)
   124  	loc.serviceKeyRepo = NewCloudControllerServiceKeyRepository(config, cloudControllerGateway)
   125  	loc.serviceBindingRepo = NewCloudControllerServiceBindingRepository(config, cloudControllerGateway)
   126  	loc.serviceBrokerRepo = NewCloudControllerServiceBrokerRepository(config, cloudControllerGateway)
   127  	loc.servicePlanRepo = NewCloudControllerServicePlanRepository(config, cloudControllerGateway)
   128  	loc.servicePlanVisibilityRepo = NewCloudControllerServicePlanVisibilityRepository(config, cloudControllerGateway)
   129  	loc.serviceSummaryRepo = NewCloudControllerServiceSummaryRepository(config, cloudControllerGateway)
   130  	loc.spaceRepo = spaces.NewCloudControllerSpaceRepository(config, cloudControllerGateway)
   131  	loc.userProvidedServiceInstanceRepo = NewCCUserProvidedServiceInstanceRepository(config, cloudControllerGateway)
   132  	loc.userRepo = NewCloudControllerUserRepository(config, uaaGateway, cloudControllerGateway)
   133  	loc.buildpackRepo = NewCloudControllerBuildpackRepository(config, cloudControllerGateway)
   134  	loc.buildpackBitsRepo = NewCloudControllerBuildpackBitsRepository(config, cloudControllerGateway, appfiles.ApplicationZipper{})
   135  	loc.securityGroupRepo = securitygroups.NewSecurityGroupRepo(config, cloudControllerGateway)
   136  	loc.stagingSecurityGroupRepo = staging.NewSecurityGroupsRepo(config, cloudControllerGateway)
   137  	loc.runningSecurityGroupRepo = running.NewSecurityGroupsRepo(config, cloudControllerGateway)
   138  	loc.securityGroupSpaceBinder = securitygroupspaces.NewSecurityGroupSpaceBinder(config, cloudControllerGateway)
   139  	loc.spaceQuotaRepo = spacequotas.NewCloudControllerSpaceQuotaRepository(config, cloudControllerGateway)
   140  	loc.featureFlagRepo = featureflags.NewCloudControllerFeatureFlagRepository(config, cloudControllerGateway)
   141  	loc.environmentVariableGroupRepo = environmentvariablegroups.NewCloudControllerRepository(config, cloudControllerGateway)
   142  	loc.copyAppSourceRepo = copyapplicationsource.NewCloudControllerCopyApplicationSourceRepository(config, cloudControllerGateway)
   143  
   144  	return
   145  }
   146  
   147  func (locator RepositoryLocator) SetAuthenticationRepository(repo authentication.Repository) RepositoryLocator {
   148  	locator.authRepo = repo
   149  	return locator
   150  }
   151  
   152  func (locator RepositoryLocator) GetAuthenticationRepository() authentication.Repository {
   153  	return locator.authRepo
   154  }
   155  
   156  func (locator RepositoryLocator) SetCurlRepository(repo CurlRepository) RepositoryLocator {
   157  	locator.curlRepo = repo
   158  	return locator
   159  }
   160  
   161  func (locator RepositoryLocator) GetCurlRepository() CurlRepository {
   162  	return locator.curlRepo
   163  }
   164  
   165  func (locator RepositoryLocator) GetEndpointRepository() coreconfig.EndpointRepository {
   166  	return locator.endpointRepo
   167  }
   168  
   169  func (locator RepositoryLocator) SetEndpointRepository(e coreconfig.EndpointRepository) RepositoryLocator {
   170  	locator.endpointRepo = e
   171  	return locator
   172  }
   173  
   174  func (locator RepositoryLocator) SetOrganizationRepository(repo organizations.OrganizationRepository) RepositoryLocator {
   175  	locator.organizationRepo = repo
   176  	return locator
   177  }
   178  
   179  func (locator RepositoryLocator) GetOrganizationRepository() organizations.OrganizationRepository {
   180  	return locator.organizationRepo
   181  }
   182  
   183  func (locator RepositoryLocator) SetQuotaRepository(repo quotas.QuotaRepository) RepositoryLocator {
   184  	locator.quotaRepo = repo
   185  	return locator
   186  }
   187  
   188  func (locator RepositoryLocator) GetQuotaRepository() quotas.QuotaRepository {
   189  	return locator.quotaRepo
   190  }
   191  
   192  func (locator RepositoryLocator) SetSpaceRepository(repo spaces.SpaceRepository) RepositoryLocator {
   193  	locator.spaceRepo = repo
   194  	return locator
   195  }
   196  
   197  func (locator RepositoryLocator) GetSpaceRepository() spaces.SpaceRepository {
   198  	return locator.spaceRepo
   199  }
   200  
   201  func (locator RepositoryLocator) SetApplicationRepository(repo applications.Repository) RepositoryLocator {
   202  	locator.appRepo = repo
   203  	return locator
   204  }
   205  
   206  func (locator RepositoryLocator) GetApplicationRepository() applications.Repository {
   207  	return locator.appRepo
   208  }
   209  
   210  func (locator RepositoryLocator) GetApplicationBitsRepository() applicationbits.Repository {
   211  	return locator.appBitsRepo
   212  }
   213  
   214  func (locator RepositoryLocator) SetAppSummaryRepository(repo AppSummaryRepository) RepositoryLocator {
   215  	locator.appSummaryRepo = repo
   216  	return locator
   217  }
   218  
   219  func (locator RepositoryLocator) SetUserRepository(repo UserRepository) RepositoryLocator {
   220  	locator.userRepo = repo
   221  	return locator
   222  }
   223  
   224  func (locator RepositoryLocator) GetAppSummaryRepository() AppSummaryRepository {
   225  	return locator.appSummaryRepo
   226  }
   227  
   228  func (locator RepositoryLocator) SetAppInstancesRepository(repo appinstances.Repository) RepositoryLocator {
   229  	locator.appInstancesRepo = repo
   230  	return locator
   231  }
   232  
   233  func (locator RepositoryLocator) GetAppInstancesRepository() appinstances.Repository {
   234  	return locator.appInstancesRepo
   235  }
   236  
   237  func (locator RepositoryLocator) SetAppEventsRepository(repo appevents.Repository) RepositoryLocator {
   238  	locator.appEventsRepo = repo
   239  	return locator
   240  }
   241  
   242  func (locator RepositoryLocator) GetAppEventsRepository() appevents.Repository {
   243  	return locator.appEventsRepo
   244  }
   245  
   246  func (locator RepositoryLocator) SetAppFileRepository(repo api_appfiles.Repository) RepositoryLocator {
   247  	locator.appFilesRepo = repo
   248  	return locator
   249  }
   250  
   251  func (locator RepositoryLocator) GetAppFilesRepository() api_appfiles.Repository {
   252  	return locator.appFilesRepo
   253  }
   254  
   255  func (locator RepositoryLocator) SetDomainRepository(repo DomainRepository) RepositoryLocator {
   256  	locator.domainRepo = repo
   257  	return locator
   258  }
   259  
   260  func (locator RepositoryLocator) GetDomainRepository() DomainRepository {
   261  	return locator.domainRepo
   262  }
   263  
   264  func (locator RepositoryLocator) SetRouteRepository(repo RouteRepository) RepositoryLocator {
   265  	locator.routeRepo = repo
   266  	return locator
   267  }
   268  
   269  func (locator RepositoryLocator) GetRoutingAPIRepository() RoutingAPIRepository {
   270  	return locator.routingAPIRepo
   271  }
   272  
   273  func (locator RepositoryLocator) SetRoutingAPIRepository(repo RoutingAPIRepository) RepositoryLocator {
   274  	locator.routingAPIRepo = repo
   275  	return locator
   276  }
   277  
   278  func (locator RepositoryLocator) GetRouteRepository() RouteRepository {
   279  	return locator.routeRepo
   280  }
   281  
   282  func (locator RepositoryLocator) SetStackRepository(repo stacks.StackRepository) RepositoryLocator {
   283  	locator.stackRepo = repo
   284  	return locator
   285  }
   286  
   287  func (locator RepositoryLocator) GetStackRepository() stacks.StackRepository {
   288  	return locator.stackRepo
   289  }
   290  
   291  func (locator RepositoryLocator) SetServiceRepository(repo ServiceRepository) RepositoryLocator {
   292  	locator.serviceRepo = repo
   293  	return locator
   294  }
   295  
   296  func (locator RepositoryLocator) GetServiceRepository() ServiceRepository {
   297  	return locator.serviceRepo
   298  }
   299  
   300  func (locator RepositoryLocator) SetServiceKeyRepository(repo ServiceKeyRepository) RepositoryLocator {
   301  	locator.serviceKeyRepo = repo
   302  	return locator
   303  }
   304  
   305  func (locator RepositoryLocator) GetServiceKeyRepository() ServiceKeyRepository {
   306  	return locator.serviceKeyRepo
   307  }
   308  
   309  func (locator RepositoryLocator) SetRouteServiceBindingRepository(repo RouteServiceBindingRepository) RepositoryLocator {
   310  	locator.routeServiceBindingRepo = repo
   311  	return locator
   312  }
   313  
   314  func (locator RepositoryLocator) GetRouteServiceBindingRepository() RouteServiceBindingRepository {
   315  	return locator.routeServiceBindingRepo
   316  }
   317  
   318  func (locator RepositoryLocator) SetServiceBindingRepository(repo ServiceBindingRepository) RepositoryLocator {
   319  	locator.serviceBindingRepo = repo
   320  	return locator
   321  }
   322  
   323  func (locator RepositoryLocator) GetServiceBindingRepository() ServiceBindingRepository {
   324  	return locator.serviceBindingRepo
   325  }
   326  
   327  func (locator RepositoryLocator) GetServiceSummaryRepository() ServiceSummaryRepository {
   328  	return locator.serviceSummaryRepo
   329  }
   330  func (locator RepositoryLocator) SetServiceSummaryRepository(repo ServiceSummaryRepository) RepositoryLocator {
   331  	locator.serviceSummaryRepo = repo
   332  	return locator
   333  }
   334  
   335  func (locator RepositoryLocator) GetUserRepository() UserRepository {
   336  	return locator.userRepo
   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  }