Skip to content
Snippets Groups Projects
Unverified Commit bfc4a610 authored by Aaron Johnson's avatar Aaron Johnson Committed by GitHub
Browse files

Merge pull request #141 from acjohnson/tommyjcarpenter-fixes

Add error handling for nonexistent key
parents e945a2fe f56087c7
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,31 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# [1.1.9] - 2021-06-27
### Added
- c6b6f68 Create python-publish.yml
- #100 GCS support
### Changed
- #92 better error message when the user specifies a bad S3 key
- #135 Update main organization instead of creating a new one
- #133 Creating the docker container without these packages didn't work
- #139 windows env var fix
### Removed
# [1.1.8] - 2021-04-14
### Added
### Changed
- #124 fixed #123
- #121 multi arch docker support
- #127 add azure storage support
### Removed
# [1.1.7] - 2021-01-13
### Added
......@@ -28,7 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
### Changed
- #104 added python2 support to restore functions
- #104 added python2 support to restore functions
- #105 add configuration attribute to set backup file name
- #112 changed restore_functions to ordered dict
- #113 [Fixed] Dashboards with same name in different folders not restored
......@@ -52,7 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- #83 Fix tarfile options for python2
- #64 Remove empty folders when backup file (.tar.gz) created.
- #64 Remove empty folders when backup file (.tar.gz) created.
# [1.1.2] - 2020-08-14
......
import os
if os.name == 'nt':
homedir = os.environ['HOMEPATH']
if os.name == "nt":
homedir = os.environ["HOMEPATH"]
else:
homedir = os.environ['HOME']
homedir = os.environ["HOME"]
PKG_NAME = 'grafana-backup'
PKG_VERSION = '1.1.8'
JSON_CONFIG_PATH = '{0}/.grafana-backup.json'.format(homedir)
PKG_NAME = "grafana-backup"
PKG_VERSION = "1.1.9"
JSON_CONFIG_PATH = "{0}/.grafana-backup.json".format(homedir)
import boto3
from botocore.exceptions import NoCredentialsError
from botocore.exceptions import NoCredentialsError, ClientError
def main(args, settings):
arg_archive_file = args.get('<archive_file>', None)
aws_s3_bucket_name = settings.get('AWS_S3_BUCKET_NAME')
aws_s3_bucket_key = settings.get('AWS_S3_BUCKET_KEY')
aws_default_region = settings.get('AWS_DEFAULT_REGION')
aws_access_key_id = settings.get('AWS_ACCESS_KEY_ID')
aws_secret_access_key = settings.get('AWS_SECRET_ACCESS_KEY')
aws_endpoint_url = settings.get('AWS_ENDPOINT_URL')
arg_archive_file = args.get("<archive_file>", None)
aws_s3_bucket_name = settings.get("AWS_S3_BUCKET_NAME")
aws_s3_bucket_key = settings.get("AWS_S3_BUCKET_KEY")
aws_default_region = settings.get("AWS_DEFAULT_REGION")
aws_access_key_id = settings.get("AWS_ACCESS_KEY_ID")
aws_secret_access_key = settings.get("AWS_SECRET_ACCESS_KEY")
aws_endpoint_url = settings.get("AWS_ENDPOINT_URL")
session = boto3.Session(
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
region_name=aws_default_region
aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, region_name=aws_default_region
)
s3 = session.resource(
service_name='s3',
endpoint_url=aws_endpoint_url
)
s3 = session.resource(service_name="s3", endpoint_url=aws_endpoint_url)
s3_object = s3.Object(aws_s3_bucket_name, '{0}/{1}'.format(aws_s3_bucket_key, arg_archive_file))
s3_path = "{0}/{1}".format(aws_s3_bucket_key, arg_archive_file)
s3_object = s3.Object(aws_s3_bucket_name, s3_path)
try:
# .read() left off on purpose, tarfile.open() takes care of that part
s3_data = s3_object.get()['Body']
s3_data = s3_object.get()["Body"]
print("Download from S3 was successful")
except ClientError as e:
if e.response["Error"]["Code"] == "NoSuchKey":
print("Error: Key {0} does not exist in bucket {1}".format(s3_path, aws_s3_bucket_name))
return False
raise e
except NoCredentialsError:
print("Credentials not available")
return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment