/
gcs_conf.go
45 lines (34 loc) · 939 Bytes
/
gcs_conf.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
// Copyright (c) Red Hat, Inc.
// Copyright Contributors to the Open Cluster Management project
// Licensed under the Apache License 2.0
package config
import (
"errors"
"strings"
"gopkg.in/yaml.v2"
)
func validateGCS(conf Config) error {
if conf.Bucket == "" {
return errors.New("no bucket as gcs bucket name in config file")
}
if conf.ServiceAccount == "" {
return errors.New("no service_account as google application credentials in config file")
}
return nil
}
// IsValidGCSConf is used to validate GCS configuration.
func IsValidGCSConf(data []byte) (bool, error) {
var objectConfg ObjectStorgeConf
err := yaml.Unmarshal(data, &objectConfg)
if err != nil {
return false, err
}
if strings.ToLower(objectConfg.Type) != "gcs" {
return false, errors.New("invalid type config, only GCS type is supported")
}
err = validateGCS(objectConfg.Config)
if err != nil {
return false, err
}
return true, nil
}