-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
61 lines (51 loc) · 1.43 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package aliyunecs
import (
"crypto/rand"
"errors"
"strings"
"github.com/denverdino/aliyungo/common"
)
var (
errInvalidRegion = errors.New("invalid region specified")
errNoVpcs = errors.New("No VPCs found in region")
errMachineFailure = errors.New("Machine failed to start")
errNoIP = errors.New("No IP Address associated with the instance")
errComplete = errors.New("Complete")
)
const defaultUbuntuImageID = "ubuntu_16_0402_64_20G_alibase_20171227.vhd"
const defaultUbuntuImagePrefix = "ubuntu_16_0402_64"
func validateECSRegion(region string) (common.Region, error) {
for _, v := range common.ValidRegions {
if v == common.Region(region) {
return v, nil
}
}
return "", errInvalidRegion
}
const digitals = "0123456789"
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
const specialChars = "()`~!@#$%^&*-+=|{}[]:;'<>,.?/"
const dictionary = digitals + alphabet + specialChars
const paswordLen = 16
func randomPassword() string {
var bytes = make([]byte, paswordLen)
rand.Read(bytes)
for k, v := range bytes {
var ch byte
switch k {
case 0:
ch = alphabet[v%byte(len(alphabet))]
case 1:
ch = digitals[v%byte(len(digitals))]
case 2:
ch = specialChars[v%byte(len(specialChars))]
default:
ch = dictionary[v%byte(len(dictionary))]
}
bytes[k] = ch
}
return string(bytes)
}
func isUbuntuImage(image string) bool {
return strings.HasPrefix(image, "ubuntu")
}