Skip to content

Commit

Permalink
update me
Browse files Browse the repository at this point in the history
  • Loading branch information
dciangot committed Feb 9, 2020
1 parent c4cf806 commit e55897e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func initConfig() {
if err := viper.ReadInConfig(); err == nil {
//fmt.Println("Using config file:", viper.ConfigFileUsed())
clientConf = clientConf.GetConf(viper.ConfigFileUsed())

//fmt.Printf("TOKEN: %s", clientConf.Im.Token)
//if clientConf.im.Password == "" {
// fmt.Println("No password")
//}
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/blang/semver v3.5.1+incompatible
github.com/dciangot/toscalib v0.0.0-20190329085732-12f4d4a283e4
github.com/huandu/xstrings v1.3.0 // indirect
github.com/kenjones-cisco/mergo v0.0.0-20161024152414-0149f50ea824 // indirect
github.com/kenjones-cisco/mergo v0.0.0-20161024152414-0149f50ea824
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.6.2
golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456 // indirect
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.17.2 // indirect
Expand Down
10 changes: 10 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ extra:

markdown_extensions:
- codehilite
- pymdownx.arithmatex
- pymdownx.betterem:
smart_enable: all
- pymdownx.caret
- pymdownx.critic
- pymdownx.details
- pymdownx.inlinehilite
- pymdownx.superfences
- pymdownx.tasklist:
custom_checkbox: true
19 changes: 6 additions & 13 deletions pkg/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"fmt"
"io/ioutil"
"log"
"os"
"regexp"

Expand Down Expand Up @@ -53,18 +52,12 @@ type Conf struct {
// GetConf ..
func (clientConf Conf) GetConf(path string) Conf {

c := Conf{
Im: ConfIM{},
Cloud: ConfCloud{},
AllowRefresh: TokenRefreshConf{},
}

f, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}

err = yaml.UnmarshalStrict(f, &c)
err = yaml.UnmarshalStrict(f, &clientConf)
if err != nil {
panic(err)
}
Expand All @@ -77,14 +70,14 @@ func (clientConf Conf) GetConf(path string) Conf {
tokenBytes, err := ioutil.ReadFile(clientConf.AllowRefresh.AccessTokenFile)
if err != nil {
fmt.Printf("Failed to read access token file %s, not going to use cache tokens: %s", clientConf.AllowRefresh.AccessTokenFile, err.Error())
return c
return clientConf
}

if clientConf.Cloud.AuthVersion == "3.x_oidc_access_token" {
c.Cloud.Password = string(tokenBytes)
clientConf.Cloud.Password = string(tokenBytes)
}
if clientConf.Im.Token != "" {
c.Im.Token = string(tokenBytes)
clientConf.Im.Token = string(tokenBytes)
}

_, err = clientConf.ListInfIDs()
Expand All @@ -103,12 +96,12 @@ func (clientConf Conf) GetConf(path string) Conf {
// Dump the new token
fmt.Printf("Saving new access token in %s \n", clientConf.AllowRefresh.AccessTokenFile)
if err := ioutil.WriteFile(clientConf.AllowRefresh.AccessTokenFile, []byte(clientConf.Im.Token), os.FileMode(int(0600))); err != nil {
log.Fatal(err)
panic(err)
}
}
}
}
//fmt.Printf("--- c.im:\n%v\n\n", string(c.Im.Host))

return c
return clientConf
}

0 comments on commit e55897e

Please sign in to comment.