<commit_before>/*
	A cloud account allows the platform to commission and control servers on behalf of the user.
  	A cloud account stores the credentials needed to access a cloud provider.

	The available commands are:
		list
		create
		update
		delete

	Use "settings cloud_accounts --help" on the commandline interface for more information about the available subcommands.

	Cloud accounts list

	Lists the cloud accounts of the account group.

	Usage:

		cloud_accounts list

	Cloud account create

	Creates a new cloud account.

	Usage:

		cloud_accounts create (options)

	Options:
		--cloud_provider_id <cloud_provider_id> 	Identifier of the cloud provider
		--credentials <credentials> 	A mapping assigning a value to each of the required yes credentials of the cloud provider

	Cloud account update

	Updates an existing cloud account.

	Usage:

		cloud_accounts update (options)

	Options:
		--id <cloud_account_id> 		Identifier of the cloud account
		--credentials <credentials> 	A mapping assigning a value to each of the required yes credentials of the cloud provider

	Cloud account delete

	This action deletes a cloud account.

	Usage:

		cloud_accounts delete (options)

	Options:
		--id <cloud_account_id> 		Identifier of the cloud account
*/
package cloud_accounts

import (
	"encoding/json"
	"fmt"
	log "github.com/Sirupsen/logrus"
	"github.com/codegangsta/cli"
	"github.com/flexiant/concerto/utils"
	"github.com/flexiant/concerto/webservice"
	"os"
	"text/tabwriter"
)

type Account struct {
	Id          string `json:"id"`
	CloudProvId string `json:"cloud_provider_id"`
}

type RequiredCredentials struct {
	AccessKeyId       string `json:"access_key_id,omitempty"`
	SecretAccessKey   string `json:"secret_access_key,omitempty"`
	Username          string `json:"username,omitempty"`
	APIKey            string `json:"api_key,omitempty"`
	Password          string `json:"password"`
	User              string `json:"user"`
	ClientId          string `json:"client_id,omitempty"`
	GoogleProj        string `json:"google_project,omitempty"`
	GoogleClientEmail string `json:"google_client_email,omitempty"`
	CertGoogleKey     string `json:"cert_google_key,omitempty"`
	SubscriptionID    string `json:"subscription_id,omitempty"`
	CertManagement    string `json:"cert_management_certificate,omitempty"`
}

func cmdList(c *cli.Context) {
	var accounts []Account

	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	data, err := webservice.Get("/v1/settings/cloud_accounts")
	utils.CheckError(err)

	err = json.Unmarshal(data, &accounts)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tCLOUD PROVIDER ID\r")

	for _, ac := range accounts {
		fmt.Fprintf(w, "%s\t%s\n", ac.Id, ac.CloudProvId)
	}

	w.Flush()
}

func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"cloud_provider_id", "credentials"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)
	v["cloud_provider_id"] = c.String("cloud_provider_id")
	v["credentials"] = c.String("credentials")

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, _ := webservice.Post("/v1/settings/cloud_accounts", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)

}

func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	if c.IsSet("credentials") {
		v["credentials"] = c.String("credentials")
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, _ := webservice.Put(fmt.Sprintf("/v1/settings/cloud_accounts/%s", c.String("id")), jsonBytes)

	utils.CheckError(err)
	fmt.Println(res)
}

func cmdDelete(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})

	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	err, _, res := webservice.Delete(fmt.Sprintf("/v1/settings/cloud_accounts/%s", c.String("id")))
	utils.CheckError(err)
	utils.CheckReturnCode(res)

	fmt.Println(res)
}
<commit_msg>Fixed cloud accounts create, update<commit_after>/*
	A cloud account allows the platform to commission and control servers on behalf of the user.
  	A cloud account stores the credentials needed to access a cloud provider.

	The available commands are:
		list
		create
		update
		delete

	Use "settings cloud_accounts --help" on the commandline interface for more information about the available subcommands.

	Cloud accounts list

	Lists the cloud accounts of the account group.

	Usage:

		cloud_accounts list

	Cloud account create

	Creates a new cloud account.

	Usage:

		cloud_accounts create (options)

	Options:
		--cloud_provider_id <cloud_provider_id> 	Identifier of the cloud provider
		--credentials <credentials> 	A mapping assigning a value to each of the required yes credentials of the cloud provider

	Cloud account update

	Updates an existing cloud account.

	Usage:

		cloud_accounts update (options)

	Options:
		--id <cloud_account_id> 		Identifier of the cloud account
		--credentials <credentials> 	A mapping assigning a value to each of the required yes credentials of the cloud provider

	Cloud account delete

	This action deletes a cloud account.

	Usage:

		cloud_accounts delete (options)

	Options:
		--id <cloud_account_id> 		Identifier of the cloud account
*/
package cloud_accounts

import (
	"encoding/json"
	"fmt"
	log "github.com/Sirupsen/logrus"
	"github.com/codegangsta/cli"
	"github.com/flexiant/concerto/utils"
	"github.com/flexiant/concerto/webservice"
	"os"
	"text/tabwriter"
)

type Account struct {
	Id          string `json:"id"`
	CloudProvId string `json:"cloud_provider_id"`
}

type RequiredCredentials struct {
	AccessKeyId       string `json:"access_key_id,omitempty"`
	SecretAccessKey   string `json:"secret_access_key,omitempty"`
	Username          string `json:"username,omitempty"`
	APIKey            string `json:"api_key,omitempty"`
	Password          string `json:"password,omitempty"`
	User              string `json:"user,omitempty§"`
	ClientId          string `json:"client_id,omitempty"`
	GoogleProj        string `json:"google_project,omitempty"`
	GoogleClientEmail string `json:"google_client_email,omitempty"`
	CertGoogleKey     string `json:"cert_google_key,omitempty"`
	SubscriptionID    string `json:"subscription_id,omitempty"`
	CertManagement    string `json:"cert_management_certificate,omitempty"`
}

func cmdList(c *cli.Context) {
	var accounts []Account

	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	data, err := webservice.Get("/v1/settings/cloud_accounts")
	utils.CheckError(err)

	err = json.Unmarshal(data, &accounts)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tCLOUD PROVIDER ID\r")

	for _, ac := range accounts {
		fmt.Fprintf(w, "%s\t%s\n", ac.Id, ac.CloudProvId)
	}

	w.Flush()
}

func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"cloud_provider_id", "credentials"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	credentialsString := []byte(c.String("credentials"))
	print(credentialsString)
	var jsonCredentials RequiredCredentials
	err = json.Unmarshal(credentialsString, &jsonCredentials)

	v := make(map[string]interface{})
	v["cloud_provider_id"] = c.String("cloud_provider_id")
	v["credentials"] = jsonCredentials

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, _ := webservice.Post("/v1/settings/cloud_accounts", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)

}

func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]interface{})

	if c.IsSet("credentials") {
		credentialsString := []byte(c.String("credentials"))
		var jsonCredentials RequiredCredentials
		err = json.Unmarshal(credentialsString, &jsonCredentials)
		v["credentials"] = jsonCredentials
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, _ := webservice.Put(fmt.Sprintf("/v1/settings/cloud_accounts/%s", c.String("id")), jsonBytes)

	utils.CheckError(err)
	fmt.Println(res)
}

func cmdDelete(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})

	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	err, _, res := webservice.Delete(fmt.Sprintf("/v1/settings/cloud_accounts/%s", c.String("id")))
	utils.CheckError(err)
	utils.CheckReturnCode(res)

	fmt.Println(res)
}

{'fraction_non_alphanumeric': 0.11713716762328687, 'fraction_numerical': 0.0021084690172191636, 'mean_word_length': 4.673089700996678, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7138094', 'n_tokens_mistral': 2851, 'n_tokens_neox': 2726, 'n_words': 683}