Skip to content

Commit

Permalink
DEVOPS-499: Auto-correct S3 key and secret based on environment varia…
Browse files Browse the repository at this point in the history
…bles in master of Jenkins (#20)
  • Loading branch information
peterngockhoa authored Mar 18, 2022
1 parent 7b6a9b3 commit 3de5f58
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions git-fat
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,25 @@ class GitFat(object):
return RsyncBackend(remote,ssh_port,ssh_user,options,self.objdir)
elif gitconfig_get('s3.bucket', file=cfgpath):
bucket = gitconfig_get('s3.bucket', file=cfgpath)

# For S3 key
key = gitconfig_get('s3.key', file=cfgpath)
key_env = os.getenv('GITFAT_S3_ACCESS_KEY_ID')
if key_env is not None and key != key_env:
gitconfig_set('s3.key', key_env, file=cfgpath)
key = key_env
if key is None:
key = os.getenv('GITFAT_S3_ACCESS_KEY_ID', os.getenv('AWS_ACCESS_KEY_ID'))
if key is None:
raise RuntimeError('No s3.key in both environment variables and %s' % cfgpath)
secret = gitconfig_get('s3.secret', file=cfgpath)
raise RuntimeError('No s3.key in both environment variables and %s' % cfgpath)

# For S3 secret
secret = gitconfig_get('s3.secret', file=cfgpath)
secret_env = os.getenv('GITFAT_S3_SECRET_ACCESS_KEY')
if secret_env is not None and secret != secret_env:
gitconfig_set('s3.secret', secret_env, file=cfgpath)
secret = secret_env
if secret is None:
secret = os.getenv('GITFAT_S3_SECRET_ACCESS_KEY', os.getenv('AWS_SECRET_ACCESS_KEY'))
if secret is None:
raise RuntimeError('No s3.secret in both environment variables and %s' % cfgpath)
raise RuntimeError('No s3.secret in both environment variables and %s' % cfgpath)

return S3Backend(bucket,key,secret,self.objdir)
else:
raise RuntimeError('No supported backends specified in %s' % cfgpath)
Expand Down

0 comments on commit 3de5f58

Please sign in to comment.