Commit b387a875 by Mitsuhiro Tanda Committed by Torkel Ödegaard

use session.NewSession() (#7745)

parent 6ab90425
...@@ -114,7 +114,10 @@ func getCredentials(dsInfo *datasourceInfo) (*credentials.Credentials, error) { ...@@ -114,7 +114,10 @@ func getCredentials(dsInfo *datasourceInfo) (*credentials.Credentials, error) {
DurationSeconds: aws.Int64(900), DurationSeconds: aws.Int64(900),
} }
stsSess := session.New() stsSess, err := session.NewSession()
if err != nil {
return nil, err
}
stsCreds := credentials.NewChainCredentials( stsCreds := credentials.NewChainCredentials(
[]credentials.Provider{ []credentials.Provider{
&credentials.EnvProvider{}, &credentials.EnvProvider{},
...@@ -126,7 +129,11 @@ func getCredentials(dsInfo *datasourceInfo) (*credentials.Credentials, error) { ...@@ -126,7 +129,11 @@ func getCredentials(dsInfo *datasourceInfo) (*credentials.Credentials, error) {
Credentials: stsCreds, Credentials: stsCreds,
} }
svc := sts.New(session.New(stsConfig), stsConfig) sess, err := session.NewSession(stsConfig)
if err != nil {
return nil, err
}
svc := sts.New(sess, stsConfig)
resp, err := svc.AssumeRole(params) resp, err := svc.AssumeRole(params)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -139,7 +146,10 @@ func getCredentials(dsInfo *datasourceInfo) (*credentials.Credentials, error) { ...@@ -139,7 +146,10 @@ func getCredentials(dsInfo *datasourceInfo) (*credentials.Credentials, error) {
} }
} }
sess := session.New() sess, err := session.NewSession()
if err != nil {
return nil, err
}
creds := credentials.NewChainCredentials( creds := credentials.NewChainCredentials(
[]credentials.Provider{ []credentials.Provider{
&credentials.StaticProvider{Value: credentials.Value{ &credentials.StaticProvider{Value: credentials.Value{
...@@ -185,7 +195,12 @@ func handleGetMetricStatistics(req *cwRequest, c *middleware.Context) { ...@@ -185,7 +195,12 @@ func handleGetMetricStatistics(req *cwRequest, c *middleware.Context) {
c.JsonApiErr(500, "Unable to call AWS API", err) c.JsonApiErr(500, "Unable to call AWS API", err)
return return
} }
svc := cloudwatch.New(session.New(cfg), cfg) sess, err := session.NewSession(cfg)
if err != nil {
c.JsonApiErr(500, "Unable to call AWS API", err)
return
}
svc := cloudwatch.New(sess, cfg)
reqParam := &struct { reqParam := &struct {
Parameters struct { Parameters struct {
...@@ -232,7 +247,12 @@ func handleListMetrics(req *cwRequest, c *middleware.Context) { ...@@ -232,7 +247,12 @@ func handleListMetrics(req *cwRequest, c *middleware.Context) {
c.JsonApiErr(500, "Unable to call AWS API", err) c.JsonApiErr(500, "Unable to call AWS API", err)
return return
} }
svc := cloudwatch.New(session.New(cfg), cfg) sess, err := session.NewSession(cfg)
if err != nil {
c.JsonApiErr(500, "Unable to call AWS API", err)
return
}
svc := cloudwatch.New(sess, cfg)
reqParam := &struct { reqParam := &struct {
Parameters struct { Parameters struct {
...@@ -273,7 +293,12 @@ func handleDescribeAlarms(req *cwRequest, c *middleware.Context) { ...@@ -273,7 +293,12 @@ func handleDescribeAlarms(req *cwRequest, c *middleware.Context) {
c.JsonApiErr(500, "Unable to call AWS API", err) c.JsonApiErr(500, "Unable to call AWS API", err)
return return
} }
svc := cloudwatch.New(session.New(cfg), cfg) sess, err := session.NewSession(cfg)
if err != nil {
c.JsonApiErr(500, "Unable to call AWS API", err)
return
}
svc := cloudwatch.New(sess, cfg)
reqParam := &struct { reqParam := &struct {
Parameters struct { Parameters struct {
...@@ -316,7 +341,12 @@ func handleDescribeAlarmsForMetric(req *cwRequest, c *middleware.Context) { ...@@ -316,7 +341,12 @@ func handleDescribeAlarmsForMetric(req *cwRequest, c *middleware.Context) {
c.JsonApiErr(500, "Unable to call AWS API", err) c.JsonApiErr(500, "Unable to call AWS API", err)
return return
} }
svc := cloudwatch.New(session.New(cfg), cfg) sess, err := session.NewSession(cfg)
if err != nil {
c.JsonApiErr(500, "Unable to call AWS API", err)
return
}
svc := cloudwatch.New(sess, cfg)
reqParam := &struct { reqParam := &struct {
Parameters struct { Parameters struct {
...@@ -360,7 +390,12 @@ func handleDescribeAlarmHistory(req *cwRequest, c *middleware.Context) { ...@@ -360,7 +390,12 @@ func handleDescribeAlarmHistory(req *cwRequest, c *middleware.Context) {
c.JsonApiErr(500, "Unable to call AWS API", err) c.JsonApiErr(500, "Unable to call AWS API", err)
return return
} }
svc := cloudwatch.New(session.New(cfg), cfg) sess, err := session.NewSession(cfg)
if err != nil {
c.JsonApiErr(500, "Unable to call AWS API", err)
return
}
svc := cloudwatch.New(sess, cfg)
reqParam := &struct { reqParam := &struct {
Parameters struct { Parameters struct {
...@@ -396,7 +431,12 @@ func handleDescribeInstances(req *cwRequest, c *middleware.Context) { ...@@ -396,7 +431,12 @@ func handleDescribeInstances(req *cwRequest, c *middleware.Context) {
c.JsonApiErr(500, "Unable to call AWS API", err) c.JsonApiErr(500, "Unable to call AWS API", err)
return return
} }
svc := ec2.New(session.New(cfg), cfg) sess, err := session.NewSession(cfg)
if err != nil {
c.JsonApiErr(500, "Unable to call AWS API", err)
return
}
svc := ec2.New(sess, cfg)
reqParam := &struct { reqParam := &struct {
Parameters struct { Parameters struct {
......
...@@ -258,8 +258,11 @@ func getAllMetrics(cwData *datasourceInfo) (cloudwatch.ListMetricsOutput, error) ...@@ -258,8 +258,11 @@ func getAllMetrics(cwData *datasourceInfo) (cloudwatch.ListMetricsOutput, error)
Region: aws.String(cwData.Region), Region: aws.String(cwData.Region),
Credentials: creds, Credentials: creds,
} }
sess, err := session.NewSession(cfg)
svc := cloudwatch.New(session.New(cfg), cfg) if err != nil {
return cloudwatch.ListMetricsOutput{}, err
}
svc := cloudwatch.New(sess, cfg)
params := &cloudwatch.ListMetricsInput{ params := &cloudwatch.ListMetricsInput{
Namespace: aws.String(cwData.Namespace), Namespace: aws.String(cwData.Namespace),
......
...@@ -35,7 +35,10 @@ func NewS3Uploader(region, bucket, acl, accessKey, secretKey string) *S3Uploader ...@@ -35,7 +35,10 @@ func NewS3Uploader(region, bucket, acl, accessKey, secretKey string) *S3Uploader
} }
func (u *S3Uploader) Upload(imageDiskPath string) (string, error) { func (u *S3Uploader) Upload(imageDiskPath string) (string, error) {
sess := session.New() sess, err := session.NewSession()
if err != nil {
return "", err
}
creds := credentials.NewChainCredentials( creds := credentials.NewChainCredentials(
[]credentials.Provider{ []credentials.Provider{
&credentials.StaticProvider{Value: credentials.Value{ &credentials.StaticProvider{Value: credentials.Value{
...@@ -58,7 +61,11 @@ func (u *S3Uploader) Upload(imageDiskPath string) (string, error) { ...@@ -58,7 +61,11 @@ func (u *S3Uploader) Upload(imageDiskPath string) (string, error) {
return "", err return "", err
} }
svc := s3.New(session.New(cfg), cfg) sess, err = session.NewSession(cfg)
if err != nil {
return "", err
}
svc := s3.New(sess, cfg)
params := &s3.PutObjectInput{ params := &s3.PutObjectInput{
Bucket: aws.String(u.bucket), Bucket: aws.String(u.bucket),
Key: aws.String(key), Key: aws.String(key),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment