浏览代码

Merge pull request #915 from docker/aws_creds

Don't mess with exiting .aws/credentials
Nicolas De loof 5 年之前
父节点
当前提交
564b5fb793
共有 1 个文件被更改,包括 10 次插入3 次删除
  1. 10 3
      ecs/context.go

+ 10 - 3
ecs/context.go

@@ -199,8 +199,15 @@ func (h contextCreateAWSHelper) saveCredentials(profile string, accessKeyID stri
 		return err
 	}
 
-	credIni := ini.Empty()
-	section, err := credIni.NewSection(profile)
+	credentials, err := ini.Load(file)
+	if err != nil {
+		if !os.IsNotExist(err) {
+			return err
+		}
+		credentials = ini.Empty()
+	}
+
+	section, err := credentials.NewSection(profile)
 	if err != nil {
 		return err
 	}
@@ -212,7 +219,7 @@ func (h contextCreateAWSHelper) saveCredentials(profile string, accessKeyID stri
 	if err != nil {
 		return err
 	}
-	return credIni.SaveTo(file)
+	return credentials.SaveTo(file)
 }
 
 func (h contextCreateAWSHelper) saveRegion(profile, region string) error {