func runInfo(cmd *types.Command, args []string) { if infoHelp { cmd.PrintUsage() } if len(args) != 0 { cmd.PrintShortUsage() } // FIXME: fmt.Printf("Servers: %s\n", "quantity") // FIXME: fmt.Printf("Images: %s\n", "quantity") fmt.Printf("Debug mode (client): %v\n", os.Getenv("DEBUG") != "") fmt.Printf("Organization: %s\n", cmd.API.Organization) // FIXME: add partially-masked token fmt.Printf("API Endpoint: %s\n", os.Getenv("scaleway_api_endpoint")) configPath, _ := utils.GetConfigFilePath() fmt.Printf("RC file: %s\n", configPath) fmt.Printf("User: %s\n", os.Getenv("USER")) fmt.Printf("CPUs: %d\n", runtime.NumCPU()) hostname, _ := os.Hostname() fmt.Printf("Hostname: %s\n", hostname) cliPath, _ := osext.Executable() fmt.Printf("CLI Path: %s\n", cliPath) fmt.Printf("Cache: %s\n", cmd.API.Cache.Path) fmt.Printf(" Servers: %d\n", cmd.API.Cache.GetNbServers()) fmt.Printf(" Images: %d\n", cmd.API.Cache.GetNbImages()) fmt.Printf(" Snapshots: %d\n", cmd.API.Cache.GetNbSnapshots()) fmt.Printf(" Volumes: %d\n", cmd.API.Cache.GetNbVolumes()) fmt.Printf(" Bootscripts: %d\n", cmd.API.Cache.GetNbBootscripts()) }
// getConfig returns the Scaleway CLI config file for the current user func getConfig() (*api.Config, error) { scwrcPath, err := utils.GetConfigFilePath() if err != nil { return nil, err } stat, err := os.Stat(scwrcPath) // we don't care if it fails, the user just won't see the warning if err == nil { mode := stat.Mode() if mode&0066 != 0 { log.Fatalf("Permissions %#o for .scwrc are too open.", mode) } } file, err := ioutil.ReadFile(scwrcPath) if err != nil { return nil, err } var config api.Config err = json.Unmarshal(file, &config) if err != nil { return nil, err } if os.Getenv("scaleway_api_endpoint") == "" { os.Setenv("scaleway_api_endpoint", config.APIEndPoint) } return &config, nil }
func runLogin(cmd *types.Command, args []string) { if loginHelp { cmd.PrintUsage() } if len(args) != 0 { cmd.PrintShortUsage() } if len(organization) == 0 { fmt.Println("You can get your credentials on https://cloud.scaleway.com/#/credentials") promptUser("Organization (access key): ", &organization, true) } if len(token) == 0 { promptUser("Token: ", &token, false) } cfg := &api.Config{ APIEndPoint: "https://account.scaleway.com/", Organization: strings.Trim(organization, "\n"), Token: strings.Trim(token, "\n"), } api, err := api.NewScalewayAPI(cfg.APIEndPoint, cfg.Organization, cfg.Token) if err != nil { log.Fatalf("Unable to create ScalewayAPI: %s", err) } err = api.CheckCredentials() if err != nil { log.Fatalf("Unable to contact ScalewayAPI: %s", err) } scwrcPath, err := utils.GetConfigFilePath() if err != nil { log.Fatalf("Unable to get scwrc config file path: %s", err) } scwrc, err := os.OpenFile(scwrcPath, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0600) if err != nil { log.Fatalf("Unable to create scwrc config file: %s", err) } defer scwrc.Close() encoder := json.NewEncoder(scwrc) cfg.APIEndPoint = "https://api.scaleway.com/" err = encoder.Encode(cfg) if err != nil { log.Fatalf("Unable to encode scw config file: %s", err) } }