示例#1
0
func TestFileConfig(t *testing.T) {
	assert := assert.New(t)

	file, err := ioutil.TempFile("", "tmp")
	assert.Nil(err)

	clearEnvVars()
	os.Setenv("CLC_ALIAS", "alias")
	os.Setenv("CLC_USER_AGENT", "some-sdk-client")
	conf, err := api.NewConfig("user", "pass")

	assert.Nil(err)
	b, _ := json.Marshal(conf)

	assert.Nil(ioutil.WriteFile(file.Name(), b, 755))

	c, err := api.FileConfig(file.Name())

	assert.Nil(err)
	assert.Equal("user", c.User.Username)
	assert.Equal("pass", c.User.Password)
	assert.Equal("alias", c.Alias)
	assert.Equal("some-sdk-client", c.UserAgent)

	file.Close()
	os.Remove(file.Name())
}
示例#2
0
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
	un := d.Get("username").(string)
	pw := d.Get("password").(string)

	config, err := api.NewConfig(un, pw)
	if err != nil {
		return nil, fmt.Errorf("Failed to create CLC config with provided details: %v", err)
	}
	config.UserAgent = fmt.Sprintf("terraform-clc terraform/%s", terraform.Version)
	// user requested alias override or sub-account
	if al := d.Get("account").(string); al != "" {
		config.Alias = al
	}

	client := clc.New(config)
	if err := client.Authenticate(); err != nil {
		return nil, fmt.Errorf("Failed authenticated with provided credentials: %v", err)
	}

	alerts, err := client.Alert.GetAll()
	if err != nil {
		return nil, fmt.Errorf("Failed to connect to the CLC api because %s", err)
	}
	for _, a := range alerts.Items {
		log.Printf("[WARN] Received alert: %v", a)
	}
	return client, nil
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
	un := d.Get("username").(string)
	pw := d.Get("password").(string)
	ac := d.Get("account").(string)
	url := d.Get("url").(string)

	config, config_err := api.NewConfig(un, pw, ac, url)
	if config_err != nil {
		return nil, fmt.Errorf("Failed to create CLC config with provided details: %v", config_err)
	}

	client := clc.New(config)
	err := client.Authenticate()
	if err != nil {
		return nil, fmt.Errorf("Failed authenticated with provided credentials: %v", err)
	}

	alerts, err := client.Alert.GetAll()
	if err != nil {
		return nil, fmt.Errorf("Failed to connect to the CLC api because %s", err)
	}
	for _, a := range alerts.Items {
		log.Printf("[WARN] Received alert: %v", a)
	}
	return client, nil
}
示例#4
0
文件: api_test.go 项目: ack/clc-sdk
func TestNewConfigWithUrl(t *testing.T) {
	assert := assert.New(t)

	c, err := api.NewConfig("user", "pass", "alias", "https://api.other.io/v2")

	u, _ := url.Parse("https://api.other.io/v2")

	assert.Nil(err)
	assert.Equal("user", c.User.Username)
	assert.Equal("pass", c.User.Password)
	assert.Equal("alias", c.Alias)
	assert.Equal(u, c.BaseURL)
}
示例#5
0
文件: cli.go 项目: mikebeyer/clc-cli
func genConfig() error {
	config, err := api.NewConfig("USERNAME", "PASSWORD", "DEFAULT-ALIAS", "")
	if err != nil {
		return err
	}
	b, err := json.MarshalIndent(config, "", "  ")
	if err != nil {
		return err
	}

	err = ioutil.WriteFile("./config.json", b, 0666)
	if err != nil {
		return err
	}
	fmt.Printf("config template written to config.json\n")
	return nil
}
示例#6
0
func TestNewConfigWithUrl(t *testing.T) {
	assert := assert.New(t)

	clearEnvVars()

	alt := "https://api.other.io/v2"
	os.Setenv("CLC_BASE_URL", alt)

	c, err := api.NewConfig("user", "pass")

	u, _ := url.Parse(alt)

	assert.Nil(err)
	assert.Equal("user", c.User.Username)
	assert.Equal("pass", c.User.Password)
	assert.Equal("", c.Alias) // not set until Auth()
	assert.Equal(u, c.BaseURL)
}
示例#7
0
文件: api_test.go 项目: ack/clc-sdk
func TestFileConfig(t *testing.T) {
	assert := assert.New(t)

	file, err := ioutil.TempFile("", "tmp")
	assert.Nil(err)

	conf, err := api.NewConfig("user", "pass", "alias", "https://api.ctl.io/v2")
	assert.Nil(err)
	b, _ := json.Marshal(conf)

	assert.Nil(ioutil.WriteFile(file.Name(), b, 755))

	c, err := api.FileConfig(file.Name())

	assert.Nil(err)
	assert.Equal("user", c.User.Username)
	assert.Equal("pass", c.User.Password)
	assert.Equal("alias", c.Alias)

	file.Close()
	os.Remove(file.Name())
}