From 9326152be5712cfce22f00ebe738aec8e9b892db Mon Sep 17 00:00:00 2001 From: "adrianwit@gmail.com" Date: Mon, 16 Sep 2019 12:46:51 -0700 Subject: [PATCH] updated cred config JSON annotation --- cred/config.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cred/config.go b/cred/config.go index 6fc3c5f..616715d 100644 --- a/cred/config.go +++ b/cred/config.go @@ -35,8 +35,8 @@ type Config struct { Key string `json:",omitempty"` Secret string `json:",omitempty"` Region string `json:",omitempty"` - AccountID string `json:"-"` - Token string `json:"-"` + AccountID string `json:",omitempty"` + Token string `json:",omitempty"` //google cloud credential ClientEmail string `json:"client_email,omitempty"` @@ -48,7 +48,7 @@ type Config struct { Type string `json:"type"` ClientX509CertURL string `json:"client_x509_cert_url"` AuthProviderX509CertURL string `json:"auth_provider_x509_cert_url"` - + //JSON string for this secret Data string `json:",omitempty"` @@ -95,6 +95,7 @@ func (c *Config) LoadFromReader(reader io.Reader, ext string) error { return nil } + func (c *Config) Save(filename string) error { _ = os.Remove(filename) file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0644) @@ -186,6 +187,15 @@ func (c *Config) NewJWTConfig(scopes ...string) (*jwt.Config, error) { return result, nil } + +//JWTConfig returns jwt config and projectID +func (c *Config) JWTConfig(scopes ...string) (config *jwt.Config, projectID string, err error) { + config, err = c.NewJWTConfig(scopes...) + return config, c.ProjectID, err +} + + + func loadPEM(location string, password string) ([]byte, error) { var pemBytes []byte if IsKeyEncrypted(location) { @@ -233,6 +243,10 @@ func (c *Config) ClientConfig() (*ssh.ClientConfig, error) { return result, nil } + + + + //NewConfig create a new config for supplied file name func NewConfig(filename string) (*Config, error) { var config = &Config{}