Esempio n. 1
0
// GetApi returns a Api object
func (c *Command) GetApi(baseUrl, accessToken, appId string, rawOutput bool) *api.Api {
	if accessToken == "" || appId == "" {
		configPath, err := GetConfigPath()
		if err != nil {
			os.Exit(EXIT_FLAG_ERROR)
		}
		config, err := api.ReadApiConfiguration(configPath)
		if err != nil {
			c.PrintUsage()
		}
		baseUrl = config.BaseUrl
		accessToken = config.AccessToken
		appId = config.AppId
	}
	return api.NewApi(baseUrl, accessToken, appId, rawOutput)
}
Esempio n. 2
0
// GetApi returns a Api object
func (c *Command) GetApi(baseUrl, accessToken, appId string, rawOutput bool) *api.Api {
	if accessToken == "" || appId == "" {
		configPath, err := GetConfigPath()
		if err != nil {
			return api.NewFakeApi()
		}
		config, err := api.ReadApiConfiguration(configPath)
		if err != nil {
			return api.NewFakeApi()
		}
		baseUrl = config.BaseUrl
		accessToken = config.AccessToken
		appId = config.AppId
	}
	return api.NewApi(baseUrl, accessToken, appId, rawOutput)
}
Esempio n. 3
0
var ConfigActions = []*Command{
	{
		Name:      "check",
		UsageLine: "config check",
		Long: `
Check the CLI configuration.
`,
		Run: func(cmd *Command, args []string) {
			// check for getting the config file path
			file, err := GetConfigPath()
			if err != nil {
				fmt.Fprintln(os.Stderr, "No such file: "+file)
				os.Exit(EXIT_SUCCESS_ERROR)
			}
			// check if the configuration file can be parsed
			config, err := api.ReadApiConfiguration(file)
			if err != nil {
				fmt.Fprintln(os.Stderr, "Could not parse configuration from "+file)
				os.Exit(EXIT_SUCCESS_ERROR)
			}
			// check if we can loggin with this configuration
			api := api.NewApi(config.BaseUrl, config.AccessToken, config.AppId, false)
			err = api.Login()
			if err != nil {
				fmt.Fprintln(os.Stderr, "Api authentication failed")
				os.Exit(EXIT_SUCCESS_ERROR)
			}
			fmt.Fprintln(os.Stderr, "Configuration successfuly checked")
			os.Exit(EXIT_SUCCESS)
		},
	},