disable aws params for dolt_sync command run via sql and minor credentialing change

This commit is contained in:
Brian Hendriks
2022-07-12 17:16:34 -07:00
parent 48480f302a
commit 1b4420b1f0
2 changed files with 29 additions and 0 deletions
+10
View File
@@ -142,6 +142,11 @@ func (fact AWSFactory) newChunkStore(ctx context.Context, nbf *types.NomsBinForm
}
sess := session.Must(session.NewSessionWithOptions(opts))
_, err = sess.Config.Credentials.Get()
if err != nil {
return nil, err
}
q := nbs.NewUnlimitedMemQuotaProvider()
return nbs.NewAWSStore(ctx, nbf.VersionString(), parts[0], dbName, parts[1], s3.New(sess), dynamodb.New(sess), defaultMemTableSize, q)
}
@@ -188,6 +193,11 @@ func awsConfigFromParams(params map[string]interface{}) (session.Options, error)
opts.Profile = val.(string)
}
filePath, ok := params[AWSCredsFileParam]
if ok && len(filePath.(string)) != 0 && awsCredsSource == RoleCS {
awsCredsSource = FileCS
}
switch awsCredsSource {
case EnvCS:
awsConfig = awsConfig.WithCredentials(credentials.NewEnvCredentials())
@@ -84,6 +84,13 @@ func DoDoltBackup(ctx *sql.Context, args []string) (int, error) {
return statusErr, err
}
invalidParams := []string{dbfactory.AWSCredsFileParam, dbfactory.AWSCredsProfile, dbfactory.AWSCredsTypeParam, dbfactory.AWSRegionParam}
for _, param := range invalidParams {
if apr.Contains(param) {
return statusErr, fmt.Errorf("parameter '%s' is not supported when running this command via SQL", param)
}
}
sess := dsess.DSessFromSess(ctx.Session)
dbData, ok := sess.GetDbData(ctx, dbName)
if !ok {
@@ -122,6 +129,18 @@ func DoDoltBackup(ctx *sql.Context, args []string) (int, error) {
return statusErr, err
}
credsFile, _ := sess.GetSessionVariable(ctx, dsess.AwsCredsFileKey)
credsFileStr, isStr := credsFile.(string)
if isStr && len(credsFileStr) > 0 {
params[dbfactory.AWSCredsFileParam] = credsFileStr
}
credsProfile, err := sess.GetSessionVariable(ctx, dsess.AwsCredsProfileKey)
profStr, isStr := credsProfile.(string)
if isStr && len(profStr) > 0 {
params[dbfactory.AWSCredsProfile] = profStr
}
b = env.NewRemote("__temp__", backupUrl, params, nil)
case apr.Arg(0) == cli.SyncBackupId: