-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
75 lines (58 loc) · 2.05 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
// go get github.com/kirinlabs/HttpRequest
// go get github.com/pkg/sftp
// go get golang.org/x/crypto/ssh
// go get golang.org/x/oauth2/google
import (
"fmt"
"os"
)
// This is the file where User Credentails are saved after authorization
// This credentials are loaded on program start and refreshed if previously saved
var SavedUserCredentials = "user_credentials.json"
var SavedAdcCredentials = "adc_credentials.json"
// If you change the scopes, delete the saved user_credentials.json
var SCOPE = "https://www.googleapis.com/auth/cloud-platform openid https://www.googleapis.com/auth/userinfo.email"
func main() {
//************************************************************
//
//************************************************************
err := init_config()
if err != nil {
os.Exit(1)
}
//************************************************************
//
//************************************************************
err = check_os()
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
//************************************************************
// Using Cloud SDK User Credentials does not work with Cloud Shell
//
// Your application has authenticated using end user credentials from the
// Google Cloud SDK or Google Cloud Shell which are not supported by the
// cloudshell.googleapis.com. We recommend that most server applications
// use service accounts instead. For more information about service accounts
// and how to use them in your application, see
// https://cloud.google.com/docs/authentication/.
//
// Service Account credentials do not work with Cloud Shell, so we
// must use OAuth 2.0 User Credentials
//************************************************************
var accessToken = ""
// accessToken, idToken, err := get_tokens()
accessToken, _, err = get_tokens()
if err != nil {
os.Exit(1)
}
if accessToken == "" {
fmt.Println("Error: Empty Access Token")
os.Exit(1)
}
// FIX - return error numbers so that scripts/tools can detect errors
call_cloud_shell(accessToken)
os.Exit(0)
}