blob: 18025919ce13408c6425acc4ac8c1715f86b0b27 [file] [log] [blame]
Samuel A. Falvo II704a7502013-07-10 15:23:43 -07001package main
2
3import (
4 "fmt"
5 "os"
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -07006 "crypto/rand"
Samuel A. Falvo II704a7502013-07-10 15:23:43 -07007)
8
9// getCredentials will verify existence of needed credential information
10// provided through environment variables. This function will not return
11// if at least one piece of required information is missing.
12func getCredentials() (provider, username, password string) {
13 provider = os.Getenv("SDK_PROVIDER")
14 username = os.Getenv("SDK_USERNAME")
15 password = os.Getenv("SDK_PASSWORD")
16
17 if (provider == "") || (username == "") || (password == "") {
18 fmt.Fprintf(os.Stderr, "One or more of the following environment variables aren't set:\n")
19 fmt.Fprintf(os.Stderr, " SDK_PROVIDER=\"%s\"\n", provider)
20 fmt.Fprintf(os.Stderr, " SDK_USERNAME=\"%s\"\n", username)
21 fmt.Fprintf(os.Stderr, " SDK_PASSWORD=\"%s\"\n", password)
22 os.Exit(1)
23 }
24
25 return
26}
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -070027
28// randomString generates a string of given length, but random content.
29// All content will be within the ASCII graphic character set.
30// (Implementation from Even Shaw's contribution on
31// http://stackoverflow.com/questions/12771930/what-is-the-fastest-way-to-generate-a-long-random-string-in-go).
Samuel A. Falvo IIe3b2d7a2013-07-12 11:08:02 -070032func randomString(prefix string, n int) string {
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -070033 const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
34 var bytes = make([]byte, n)
35 rand.Read(bytes)
36 for i, b := range bytes {
37 bytes[i] = alphanum[b % byte(len(alphanum))]
38 }
Samuel A. Falvo IIe3b2d7a2013-07-12 11:08:02 -070039 return prefix + string(bytes)
Samuel A. Falvo IIe91ff6d2013-07-11 15:46:10 -070040}