github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/commandregistry/dependency.go (about) 1 package commandregistry 2 3 import ( 4 "fmt" 5 "io" 6 "os" 7 "time" 8 9 "path/filepath" 10 11 "code.cloudfoundry.org/cli/cf/actors" 12 "code.cloudfoundry.org/cli/cf/actors/brokerbuilder" 13 "code.cloudfoundry.org/cli/cf/actors/planbuilder" 14 "code.cloudfoundry.org/cli/cf/actors/pluginrepo" 15 "code.cloudfoundry.org/cli/cf/actors/servicebuilder" 16 "code.cloudfoundry.org/cli/cf/api" 17 "code.cloudfoundry.org/cli/cf/appfiles" 18 "code.cloudfoundry.org/cli/cf/configuration" 19 "code.cloudfoundry.org/cli/cf/configuration/confighelpers" 20 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 21 "code.cloudfoundry.org/cli/cf/configuration/pluginconfig" 22 "code.cloudfoundry.org/cli/cf/manifest" 23 "code.cloudfoundry.org/cli/cf/net" 24 "code.cloudfoundry.org/cli/cf/terminal" 25 "code.cloudfoundry.org/cli/cf/trace" 26 "code.cloudfoundry.org/cli/plugin/models" 27 "code.cloudfoundry.org/cli/util" 28 "code.cloudfoundry.org/cli/util/randomword" 29 ) 30 31 //go:generate counterfeiter . RandomWordGenerator 32 33 type RandomWordGenerator interface { 34 Babble() string 35 } 36 37 type Dependency struct { 38 UI terminal.UI 39 Config coreconfig.Repository 40 RepoLocator api.RepositoryLocator 41 PluginConfig pluginconfig.PluginConfiguration 42 ManifestRepo manifest.Repository 43 AppManifest manifest.App 44 Gateways map[string]net.Gateway 45 TeePrinter *terminal.TeePrinter 46 PluginRepo pluginrepo.PluginRepo 47 PluginModels *PluginModels 48 ServiceBuilder servicebuilder.ServiceBuilder 49 BrokerBuilder brokerbuilder.Builder 50 PlanBuilder planbuilder.PlanBuilder 51 ServiceHandler actors.ServiceActor 52 ServicePlanHandler actors.ServicePlanActor 53 WordGenerator RandomWordGenerator 54 AppZipper appfiles.Zipper 55 AppFiles appfiles.AppFiles 56 PushActor actors.PushActor 57 RouteActor actors.RouteActor 58 ChecksumUtil util.Sha1Checksum 59 WildcardDependency interface{} //use for injecting fakes 60 Logger trace.Printer 61 } 62 63 type PluginModels struct { 64 Application *plugin_models.GetAppModel 65 AppsSummary *[]plugin_models.GetAppsModel 66 Organizations *[]plugin_models.GetOrgs_Model 67 Organization *plugin_models.GetOrg_Model 68 Spaces *[]plugin_models.GetSpaces_Model 69 Space *plugin_models.GetSpace_Model 70 OrgUsers *[]plugin_models.GetOrgUsers_Model 71 SpaceUsers *[]plugin_models.GetSpaceUsers_Model 72 Services *[]plugin_models.GetServices_Model 73 Service *plugin_models.GetService_Model 74 OauthToken *plugin_models.GetOauthToken_Model 75 } 76 77 func NewDependency(writer io.Writer, logger trace.Printer, envDialTimeout string) Dependency { 78 deps := Dependency{} 79 deps.TeePrinter = terminal.NewTeePrinter(writer) 80 deps.UI = terminal.NewUI(os.Stdin, writer, deps.TeePrinter, logger) 81 82 errorHandler := func(err error) { 83 if err != nil { 84 deps.UI.Failed(fmt.Sprintf("Config error: %s", err)) 85 } 86 } 87 88 configPath, err := confighelpers.DefaultFilePath() 89 if err != nil { 90 errorHandler(err) 91 } 92 deps.Config = coreconfig.NewRepositoryFromFilepath(configPath, errorHandler) 93 94 deps.ManifestRepo = manifest.NewDiskRepository() 95 deps.AppManifest = manifest.NewGenerator() 96 97 pluginPath := filepath.Join(confighelpers.PluginRepoDir(), ".cf", "plugins") 98 deps.PluginConfig = pluginconfig.NewPluginConfig( 99 errorHandler, 100 configuration.NewDiskPersistor(filepath.Join(pluginPath, "config.json")), 101 pluginPath, 102 ) 103 104 terminal.UserAskedForColors = deps.Config.ColorEnabled() 105 terminal.InitColorSupport() 106 107 deps.Gateways = map[string]net.Gateway{ 108 "cloud-controller": net.NewCloudControllerGateway(deps.Config, time.Now, deps.UI, logger, envDialTimeout), 109 "uaa": net.NewUAAGateway(deps.Config, deps.UI, logger, envDialTimeout), 110 "routing-api": net.NewRoutingAPIGateway(deps.Config, time.Now, deps.UI, logger, envDialTimeout), 111 } 112 deps.RepoLocator = api.NewRepositoryLocator(deps.Config, deps.Gateways, logger, envDialTimeout) 113 114 deps.PluginModels = &PluginModels{Application: nil} 115 116 deps.PlanBuilder = planbuilder.NewBuilder( 117 deps.RepoLocator.GetServicePlanRepository(), 118 deps.RepoLocator.GetServicePlanVisibilityRepository(), 119 deps.RepoLocator.GetOrganizationRepository(), 120 ) 121 122 deps.ServiceBuilder = servicebuilder.NewBuilder( 123 deps.RepoLocator.GetServiceRepository(), 124 deps.PlanBuilder, 125 ) 126 127 deps.BrokerBuilder = brokerbuilder.NewBuilder( 128 deps.RepoLocator.GetServiceBrokerRepository(), 129 deps.ServiceBuilder, 130 ) 131 132 deps.PluginRepo = pluginrepo.NewPluginRepo() 133 134 deps.ServiceHandler = actors.NewServiceHandler( 135 deps.RepoLocator.GetOrganizationRepository(), 136 deps.BrokerBuilder, 137 deps.ServiceBuilder, 138 ) 139 140 deps.ServicePlanHandler = actors.NewServicePlanHandler( 141 deps.RepoLocator.GetServicePlanRepository(), 142 deps.RepoLocator.GetServicePlanVisibilityRepository(), 143 deps.RepoLocator.GetOrganizationRepository(), 144 deps.PlanBuilder, 145 deps.ServiceBuilder, 146 ) 147 148 deps.WordGenerator = randomword.NewGenerator() 149 150 deps.AppZipper = appfiles.ApplicationZipper{} 151 deps.AppFiles = appfiles.ApplicationFiles{} 152 153 deps.RouteActor = actors.NewRouteActor(deps.UI, deps.RepoLocator.GetRouteRepository(), deps.RepoLocator.GetDomainRepository()) 154 deps.PushActor = actors.NewPushActor(deps.RepoLocator.GetApplicationBitsRepository(), deps.AppZipper, deps.AppFiles, deps.RouteActor) 155 156 deps.ChecksumUtil = util.NewSha1Checksum("") 157 158 deps.Logger = logger 159 160 return deps 161 }