-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
55 lines (45 loc) · 1.37 KB
/
client.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
package cloudbuild
import (
"context"
"io/ioutil"
"log"
"path/filepath"
"github.com/urvil38/kubepaas/util"
"cloud.google.com/go/storage"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/cloudbuild/v1"
"google.golang.org/api/option"
)
func getCloudBuildClient() (*cloudbuild.Service, error) {
data, err := ioutil.ReadFile(filepath.Join(util.GetConfigFolderPath(), "kubepaas-cloudbuild.json"))
if err != nil {
log.Fatal(err)
}
config, err := google.JWTConfigFromJSON(data, "https://www.googleapis.com/auth/cloud-platform")
if err != nil {
log.Fatal(err)
}
httpClient := config.Client(oauth2.NoContext)
cloudbuildClinet, err := cloudbuild.NewService(context.Background(), option.WithHTTPClient(httpClient))
if err != nil {
return nil, err
}
return cloudbuildClinet, nil
}
func getCloudBuildLogStorageClient() (storageClient *storage.Client, err error) {
data, err := ioutil.ReadFile(filepath.Join(util.GetConfigFolderPath(), "kubepaas-storage.json"))
if err != nil {
log.Fatal(err)
}
config, err := google.JWTConfigFromJSON(data, "https://www.googleapis.com/auth/devstorage.read_only")
if err != nil {
log.Fatal(err)
}
httpClient := config.Client(oauth2.NoContext)
storageClient, err = storage.NewClient(context.Background(), option.WithHTTPClient(httpClient))
if err != nil {
return nil, err
}
return storageClient, nil
}