コード例 #1
0
ファイル: dependency.go プロジェクト: tools-alexuser01/cli
func NewDependency() Dependency {
	deps := Dependency{}
	deps.TeePrinter = terminal.NewTeePrinter()
	deps.Ui = terminal.NewUI(os.Stdin, deps.TeePrinter)
	deps.ManifestRepo = manifest.NewManifestDiskRepository()

	errorHandler := func(err error) {
		if err != nil {
			deps.Ui.Failed(fmt.Sprintf("Config error: %s", err))
		}
	}
	deps.Config = core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), errorHandler)
	deps.PluginConfig = plugin_config.NewPluginConfig(errorHandler)
	deps.Detector = &detection.JibberJabberDetector{}

	terminal.UserAskedForColors = deps.Config.ColorEnabled()
	terminal.InitColorSupport()

	if os.Getenv("CF_TRACE") != "" {
		trace.Logger = trace.NewLogger(os.Getenv("CF_TRACE"))
	} else {
		trace.Logger = trace.NewLogger(deps.Config.Trace())
	}

	deps.Gateways = map[string]net.Gateway{
		"auth":             net.NewUAAGateway(deps.Config, deps.Ui),
		"cloud-controller": net.NewCloudControllerGateway(deps.Config, time.Now, deps.Ui),
		"uaa":              net.NewUAAGateway(deps.Config, deps.Ui),
	}
	deps.RepoLocator = api.NewRepositoryLocator(deps.Config, deps.Gateways)

	deps.PluginModels = &pluginModels{Application: nil}

	return deps
}
コード例 #2
0
func getAppGuid(cliConnection plugin.CliConnection, appName string) string {
	repo := core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), func(err error) {
		if err != nil {
			fmt.Println("\nERROR:", err)
			os.Exit(1)
		}
	})
	spaceGuid := repo.SpaceFields().Guid

	cmd := []string{"curl", fmt.Sprintf("/v2/spaces/%v/apps?q=name:%v&inline-relations-depth=1", spaceGuid, appName)}
	output, err := cliConnection.CliCommandWithoutTerminalOutput(cmd...)
	if err != nil {
		for _, e := range output {
			fmt.Println(e)
		}
		os.Exit(1)
	}

	search := &Search{}
	if err := json.Unmarshal([]byte(strings.Join(output, "")), &search); err != nil {
		fmt.Println("\nERROR:", err)
		os.Exit(1)
	}

	return search.Resources[0].Metadata.Guid
}
コード例 #3
0
func getSpaceGuid() string {
	configRepo := core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), func(err error) {
		if err != nil {
			fmt.Printf("Config error: %s", err)
		}
	})

	return configRepo.SpaceFields().Guid
}
コード例 #4
0
ファイル: registry.go プロジェクト: tools-alexuser01/cli
func initI18nFunc() bool {
	errorHandler := func(err error) {
		if err != nil {
			fmt.Println(FailureColor("FAILED"))
			fmt.Println("Error read/writing config: ", err.Error())
			os.Exit(1)
		}
	}
	T = Init(core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), errorHandler), &detection.JibberJabberDetector{})
	return true
}
コード例 #5
0
//WildcardCommand creates a new instance of this plugin
//this is the actual implementation
//one method per command
func InitializeCliDependencies() {
	errorHandler := func(err error) {
		if err != nil {
			fmt.Sprintf("Config error: %s", err)
		}
	}
	cc_config := core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), errorHandler)
	T = Init(cc_config, &detection.JibberJabberDetector{})
	if os.Getenv("CF_TRACE") != "" {
		trace.Logger = trace.NewLogger(os.Getenv("CF_TRACE"))
	} else {
		trace.Logger = trace.NewLogger(cc_config.Trace())
	}
}
コード例 #6
0
ファイル: cfservices.go プロジェクト: jrbudnack/cf-sql-broker
func New(ccTarget string, uaaTarget string, username string, password string) (*CFServices, error) {
	cfs := CFServices{
		CCTarget:  ccTarget,
		UAATarget: uaaTarget,
		Username:  username,
		Password:  password,
		SessionID: uuid.New(),
	}
	cfs.gateways = make(map[string]net.Gateway)
	cfs.configFilePath = strings.Replace(config_helpers.DefaultFilePath(), ".json", "."+cfs.SessionID+".json", -1)
	cfs.config = core_config.NewRepositoryFromFilepath(cfs.configFilePath,
		func(err error) {
			if err != nil {
				fmt.Printf("Config error: %s", err)
			}
		})
	cfs.config.SetApiEndpoint(ccTarget)
	cfs.config.SetAuthenticationEndpoint(uaaTarget)
	cfs.config.SetUaaEndpoint(uaaTarget)
	cfs.config.SetSSLDisabled(true)

	cfs.teePrinter = terminal.NewTeePrinter()
	cfs.termUI = terminal.NewUI(os.Stdin, cfs.teePrinter)
	cfs.detector = &detection.JibberJabberDetector{}

	T = Init(cfs.config, cfs.detector)
	terminal.UserAskedForColors = cfs.config.ColorEnabled()
	terminal.InitColorSupport()

	cfs.gateways["cloud-controller"] = net.NewCloudControllerGateway(cfs.config, time.Now, cfs.termUI)
	cfs.gateways["auth"] = net.NewUAAGateway(cfs.config, cfs.termUI)
	cfs.gateways["uaa"] = net.NewUAAGateway(cfs.config, cfs.termUI)

	cfs.authRepo = authentication.NewUAAAuthenticationRepository(cfs.gateways["uaa"], cfs.config)

	cfs.Organizations = organizations.NewCloudControllerOrganizationRepository(cfs.config, cfs.gateways["cloud-controller"])
	cfs.Spaces = spaces.NewCloudControllerSpaceRepository(cfs.config, cfs.gateways["cloud-controller"])
	cfs.Services = api.NewCloudControllerServiceRepository(cfs.config, cfs.gateways["cloud-controller"])
	cfs.Plans = api.NewCloudControllerServicePlanRepository(cfs.config, cfs.gateways["cloud-controller"])

	err := cfs.authRepo.Authenticate(map[string]string{
		"username": username,
		"password": password,
	})

	return &cfs, err
}
コード例 #7
0
ファイル: console.go プロジェクト: tianhonglouis/cf-console
func (plugin ConsolePlugin) FindAppGuid(cliConnection plugin.CliConnection, appName string) (string, AppSearchEntity) {

	plugin.Log(fmt.Sprintf("Finding app guid for %v ... ", appName), false)

	confRepo := core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), fatalIf)
	spaceGuid := confRepo.SpaceFields().Guid

	appQuery := fmt.Sprintf("/v2/spaces/%v/apps?q=name:%v&inline-relations-depth=1", spaceGuid, appName)
	cmd := []string{"curl", appQuery}

	output, _ := cliConnection.CliCommandWithoutTerminalOutput(cmd...)
	res := &AppSearchResults{}
	json.Unmarshal([]byte(strings.Join(output, "")), &res)

	plugin.Log(fmt.Sprintf("%v \n", res.Resources[0].Metadata.Guid), true)

	return res.Resources[0].Metadata.Guid, res.Resources[0].Entity
}
コード例 #8
0
ファイル: main.go プロジェクト: raghulsid/cli
func setupDependencies() (deps *cliDependencies) {
	deps = new(cliDependencies)

	deps.teePrinter = terminal.NewTeePrinter()

	deps.termUI = terminal.NewUI(os.Stdin, deps.teePrinter)

	deps.manifestRepo = manifest.NewManifestDiskRepository()

	errorHandler := func(err error) {
		if err != nil {
			deps.termUI.Failed(fmt.Sprintf("Config error: %s", err))
		}
	}
	deps.configRepo = core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), errorHandler)
	deps.pluginConfig = plugin_config.NewPluginConfig(errorHandler)
	deps.detector = &detection.JibberJabberDetector{}

	T = Init(deps.configRepo, deps.detector)

	terminal.UserAskedForColors = deps.configRepo.ColorEnabled()
	terminal.InitColorSupport()

	if os.Getenv("CF_TRACE") != "" {
		trace.Logger = trace.NewLogger(os.Getenv("CF_TRACE"))
	} else {
		trace.Logger = trace.NewLogger(deps.configRepo.Trace())
	}

	deps.gateways = map[string]net.Gateway{
		"auth":             net.NewUAAGateway(deps.configRepo, deps.termUI),
		"cloud-controller": net.NewCloudControllerGateway(deps.configRepo, time.Now, deps.termUI),
		"uaa":              net.NewUAAGateway(deps.configRepo, deps.termUI),
	}
	deps.apiRepoLocator = api.NewRepositoryLocator(deps.configRepo, deps.gateways)

	return
}
コード例 #9
0
func NewDependency(logger trace.Printer) Dependency {
	deps := Dependency{}
	deps.TeePrinter = terminal.NewTeePrinter()
	deps.Ui = terminal.NewUI(os.Stdin, deps.TeePrinter, logger)

	errorHandler := func(err error) {
		if err != nil {
			deps.Ui.Failed(fmt.Sprintf("Config error: %s", err))
		}
	}
	deps.Config = core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), errorHandler)

	deps.ManifestRepo = manifest.NewManifestDiskRepository()
	deps.AppManifest = manifest.NewGenerator()
	deps.PluginConfig = plugin_config.NewPluginConfig(errorHandler)

	terminal.UserAskedForColors = deps.Config.ColorEnabled()
	terminal.InitColorSupport()

	deps.Gateways = map[string]net.Gateway{
		"cloud-controller": net.NewCloudControllerGateway(deps.Config, time.Now, deps.Ui, logger),
		"uaa":              net.NewUAAGateway(deps.Config, deps.Ui, logger),
		"routing-api":      net.NewRoutingApiGateway(deps.Config, time.Now, deps.Ui, logger),
	}
	deps.RepoLocator = api.NewRepositoryLocator(deps.Config, deps.Gateways, logger)

	deps.PluginModels = &PluginModels{Application: nil}

	deps.PlanBuilder = plan_builder.NewBuilder(
		deps.RepoLocator.GetServicePlanRepository(),
		deps.RepoLocator.GetServicePlanVisibilityRepository(),
		deps.RepoLocator.GetOrganizationRepository(),
	)

	deps.ServiceBuilder = service_builder.NewBuilder(
		deps.RepoLocator.GetServiceRepository(),
		deps.PlanBuilder,
	)

	deps.BrokerBuilder = broker_builder.NewBuilder(
		deps.RepoLocator.GetServiceBrokerRepository(),
		deps.ServiceBuilder,
	)

	deps.PluginRepo = plugin_repo.NewPluginRepo()

	deps.ServiceHandler = actors.NewServiceHandler(
		deps.RepoLocator.GetOrganizationRepository(),
		deps.BrokerBuilder,
		deps.ServiceBuilder,
	)

	deps.ServicePlanHandler = actors.NewServicePlanHandler(
		deps.RepoLocator.GetServicePlanRepository(),
		deps.RepoLocator.GetServicePlanVisibilityRepository(),
		deps.RepoLocator.GetOrganizationRepository(),
		deps.PlanBuilder,
		deps.ServiceBuilder,
	)

	deps.WordGenerator = generator.NewWordGenerator()

	deps.AppZipper = app_files.ApplicationZipper{}
	deps.AppFiles = app_files.ApplicationFiles{}

	deps.PushActor = actors.NewPushActor(deps.RepoLocator.GetApplicationBitsRepository(), deps.AppZipper, deps.AppFiles)

	deps.ChecksumUtil = utils.NewSha1Checksum("")

	deps.Logger = logger

	return deps
}
コード例 #10
0
		Context("with an invalid access token", func() {
			BeforeEach(func() {
				config.SetAccessToken("bearer eyJhbGciOiJSUzI1NiJ9")
			})

			It("returns an empty string", func() {
				Expect(config.UserEmail()).To(BeEmpty())
			})
		})
	})

	Describe("NewRepositoryFromFilepath", func() {
		var configPath string

		It("returns nil repository if no error handler provided", func() {
			config = core_config.NewRepositoryFromFilepath(configPath, nil)
			Expect(config).To(BeNil())
		})

		Context("when the configuration file doesn't exist", func() {
			var tmpDir string

			BeforeEach(func() {
				tmpDir, err := ioutil.TempDir("", "test-config")
				if err != nil {
					Fail("Couldn't create tmp file")
				}

				configPath = filepath.Join(tmpDir, ".cf", "config.json")
			})
コード例 #11
0
func (fi *FirehoseInspector) Run(cliConnection plugin.CliConnection, args []string) {

	if args[0] == "firehose-inspector" {

		confRepo := core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), fatalIf)

		dopplerEndpoint := confRepo.DopplerEndpoint()
		accessToken := confRepo.AccessToken()

		connection := noaa.NewConsumer(dopplerEndpoint, &tls.Config{InsecureSkipVerify: true}, nil)

		msgChan := make(chan *events.Envelope)

		fi.pages = []p.Page{
			p.Page{
				Title: "Logs",
				Outputs: []p.Output{
					&so.LogsDisplay{
						MarginPos: 32,
					},
				},
				Foreground: termbox.ColorWhite,
				Background: termbox.ColorDefault,
			},
			p.Page{
				Title: "Page 1",
				Outputs: []p.Output{
					&so.NullDisplay{},
				},
				Foreground: termbox.ColorWhite,
				Background: termbox.ColorDefault,
			},
			p.Page{
				Title: "Page 2",
				Outputs: []p.Output{
					&so.NullDisplay{},
				},
				Foreground: termbox.ColorWhite,
				Background: termbox.ColorDefault,
			},
		}

		// call init on all Outputs
		for _, page := range fi.pages {
			for _, output := range page.Outputs {
				output.Init()
			}
		}

		fi.currentPage = fi.pages[0]

		err := termbox.Init()
		if err != nil {
			panic(err)
		}
		defer termbox.Close()
		termbox.SetOutputMode(termbox.Output256)
		fi.currentPage.Draw(fi.pages)

		go func() {

			defer close(msgChan)
			errorChan := make(chan error)
			go connection.Firehose(firehoseSubscriptionId, accessToken, msgChan, errorChan)

			for err := range errorChan {
				fmt.Fprintf(os.Stderr, "%v\n", err.Error())
			}

		}()

		go func() {
			for msg := range msgChan {
				for _, output := range fi.currentPage.Outputs {
					output.Update(msg)
				}
			}
		}()

	loop:

		for {
			switch ev := termbox.PollEvent(); ev.Type {
			case termbox.EventKey:
				for _, output := range fi.currentPage.Outputs {
					output.KeyEvent(ev.Key)
				}
				switch ev.Key {
				case termbox.KeyCtrlC:
					break loop
				case termbox.KeyF1:
					fi.ChangePage(0)
				case termbox.KeyF2:
					fi.ChangePage(1)
				case termbox.KeyF3:
					fi.ChangePage(2)

					// 	switch_output_mode(1)
					// 	draw_all()
					// case termbox.KeyArrowDown, termbox.KeyArrowLeft:
					// 	switch_output_mode(-1)
					// 	draw_all()
				}
			case termbox.EventResize:
				fi.currentPage.Draw(fi.pages)
				// draw_all()
			}
		}
	}
}