Skip to content

Commit

Permalink
fix sls interrupt and change travis ci configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ringtail committed Apr 19, 2020
1 parent abfb187 commit 1606f46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
# You don't need to test on very old versions of the Go compiler. It's the user's
# responsibility to keep their compiler up to date.
go:
- 1.14.x
- 1.13.x
- 1.12.x
- 1.11.x

Expand All @@ -25,7 +27,8 @@ git:

# Don't email me the results of the test runs.
notifications:
email: false
email:
- [email protected]

# Anything in before_script that returns a nonzero exit code will flunk the
# build and immediately stop. It's sorta like having set -e enabled in bash.
Expand All @@ -38,6 +41,7 @@ before_script:
# .golangci.yml file at the top level of your repo.
script:
# - golangci-lint run # run a bunch of code checkers/linters in parallel
- ./hack/check_gofmt.sh
- go test ./... -race -coverprofile=coverage.txt -covermode=atomic

after_success:
Expand Down
22 changes: 14 additions & 8 deletions sinks/sls/sls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/url"
Expand Down Expand Up @@ -247,41 +246,48 @@ func newClient(c *Config) (*sls.Client, error) {
//获取token config json
encodeTokenCfg, err := ioutil.ReadFile(ConfigPath)
if err != nil {
klog.Fatalf("failed to read token config, err: %v", err)
klog.Errorf("failed to read token config, err: %v", err)
return nil, err
}
err = json.Unmarshal(encodeTokenCfg, &akInfo)
if err != nil {
klog.Fatalf("error unmarshal token config: %v", err)
klog.Errorf("error unmarshal token config: %v", err)
return nil, err
}
keyring := akInfo.Keyring
ak, err := Decrypt(akInfo.AccessKeyId, []byte(keyring))
if err != nil {
klog.Fatalf("failed to decode ak, err: %v", err)
klog.Errorf("failed to decode ak, err: %v", err)
return nil, err
}

sk, err := Decrypt(akInfo.AccessKeySecret, []byte(keyring))
if err != nil {
klog.Fatalf("failed to decode sk, err: %v", err)
klog.Errorf("failed to decode sk, err: %v", err)
return nil, err
}

token, err := Decrypt(akInfo.SecurityToken, []byte(keyring))
if err != nil {
klog.Fatalf("failed to decode token, err: %v", err)
klog.Errorf("failed to decode token, err: %v", err)
return nil, err
}
layout := "2006-01-02T15:04:05Z"
t, err := time.Parse(layout, akInfo.Expiration)
if err != nil {
fmt.Errorf(err.Error())
klog.Errorf("failed to parse sts expiration,err: %v", err)
return nil, err
}
if t.Before(time.Now()) {
klog.Errorf("invalid token which is expired")
return nil, err
}
klog.Info("get token by ram role.")
akInfo.AccessKeyId = string(ak)
akInfo.AccessKeySecret = string(sk)
akInfo.SecurityToken = string(token)
} else {
klog.Info("use metadata instead outside params.")
klog.Info("use metadata instead of add token.")
roleName, err := m.RoleName()
if err != nil {
klog.Errorf("failed to get RoleName,because of %s", err.Error())
Expand Down

0 comments on commit 1606f46

Please sign in to comment.