mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-14 06:52:39 +03:00
server: allow user to specify custom s3cfg file (closes #413)
This lets people do advanced S3 setups like CloudFront caching, and anything else s3cmd lets you do.
This commit is contained in:
parent
528d5a0d1a
commit
7eef6eac93
2 changed files with 24 additions and 11 deletions
|
@ -216,11 +216,12 @@ The repository of older versions of applications from the main demo repository.
|
||||||
# sync_from_local_copy_dir = True
|
# sync_from_local_copy_dir = True
|
||||||
|
|
||||||
|
|
||||||
# To upload the repo to an Amazon S3 bucket using `fdroid server update`.
|
# To upload the repo to an Amazon S3 bucket using `fdroid server
|
||||||
# Warning, this deletes and recreates the whole fdroid/ directory each
|
# update`. Warning, this deletes and recreates the whole fdroid/
|
||||||
# time. This is based on apache-libcloud, which supports basically all cloud
|
# directory each time. This prefers s3cmd, but can also use
|
||||||
# storage services, so it should be easy to port the fdroid server tools to
|
# apache-libcloud. To customize how s3cmd interacts with the cloud
|
||||||
# any of them.
|
# provider, create a 's3cfg' file next to this file (config.py), and
|
||||||
|
# those settings will be used instead of any 'aws' variable below.
|
||||||
#
|
#
|
||||||
# awsbucket = 'myawsfdroid'
|
# awsbucket = 'myawsfdroid'
|
||||||
# awsaccesskeyid = 'SEE0CHAITHEIMAUR2USA'
|
# awsaccesskeyid = 'SEE0CHAITHEIMAUR2USA'
|
||||||
|
|
|
@ -38,6 +38,9 @@ options = None
|
||||||
|
|
||||||
BINARY_TRANSPARENCY_DIR = 'binary_transparency'
|
BINARY_TRANSPARENCY_DIR = 'binary_transparency'
|
||||||
|
|
||||||
|
AUTO_S3CFG = '.fdroid-server-update-s3cfg'
|
||||||
|
USER_S3CFG = 's3cfg'
|
||||||
|
|
||||||
|
|
||||||
def update_awsbucket(repo_section):
|
def update_awsbucket(repo_section):
|
||||||
'''
|
'''
|
||||||
|
@ -72,12 +75,17 @@ def update_awsbucket_s3cmd(repo_section):
|
||||||
logging.debug(_('Using s3cmd to sync with: {url}')
|
logging.debug(_('Using s3cmd to sync with: {url}')
|
||||||
.format(url=config['awsbucket']))
|
.format(url=config['awsbucket']))
|
||||||
|
|
||||||
configfilename = '.s3cfg'
|
if os.path.exists(USER_S3CFG):
|
||||||
fd = os.open(configfilename, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o600)
|
logging.info(_('Using "{path}" for configuring s3cmd.').format(path=USER_S3CFG))
|
||||||
os.write(fd, '[default]\n'.encode('utf-8'))
|
configfilename = USER_S3CFG
|
||||||
os.write(fd, ('access_key = ' + config['awsaccesskeyid'] + '\n').encode('utf-8'))
|
else:
|
||||||
os.write(fd, ('secret_key = ' + config['awssecretkey'] + '\n').encode('utf-8'))
|
fd = os.open(AUTO_S3CFG, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o600)
|
||||||
os.close(fd)
|
logging.debug(_('Creating "{path}" for configuring s3cmd.').format(path=AUTO_S3CFG))
|
||||||
|
os.write(fd, '[default]\n'.encode('utf-8'))
|
||||||
|
os.write(fd, ('access_key = ' + config['awsaccesskeyid'] + '\n').encode('utf-8'))
|
||||||
|
os.write(fd, ('secret_key = ' + config['awssecretkey'] + '\n').encode('utf-8'))
|
||||||
|
os.close(fd)
|
||||||
|
configfilename = AUTO_S3CFG
|
||||||
|
|
||||||
s3bucketurl = 's3://' + config['awsbucket']
|
s3bucketurl = 's3://' + config['awsbucket']
|
||||||
s3cmd = [config['s3cmd'], '--config=' + configfilename]
|
s3cmd = [config['s3cmd'], '--config=' + configfilename]
|
||||||
|
@ -151,6 +159,10 @@ def update_awsbucket_libcloud(repo_section):
|
||||||
_('To use awsbucket, awssecretkey and awsaccesskeyid must also be set in config.py!'))
|
_('To use awsbucket, awssecretkey and awsaccesskeyid must also be set in config.py!'))
|
||||||
awsbucket = config['awsbucket']
|
awsbucket = config['awsbucket']
|
||||||
|
|
||||||
|
if os.path.exists(USER_S3CFG):
|
||||||
|
raise FDroidException(_('"{path}" exists but s3cmd is not installed!')
|
||||||
|
.format(path=USER_S3CFG))
|
||||||
|
|
||||||
cls = get_driver(Provider.S3)
|
cls = get_driver(Provider.S3)
|
||||||
driver = cls(config['awsaccesskeyid'], config['awssecretkey'])
|
driver = cls(config['awsaccesskeyid'], config['awssecretkey'])
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue