Exemplo n.º 1
0
 def _select_area_by_alias(self, alias):
     try:
         config = UploadConfig()
         uuid = config.area_uuid_from_partial_uuid(partial_uuid=alias)
         config.select_area(uuid)
         print("Upload area %s selected." % uuid)
     except UploadException as e:
         print(str(e))
Exemplo n.º 2
0
 def _store_credentials(self):
     stored_creds = {
         'aws_access_key_id': 'skey',
         'aws_secret_access_key': 'ssecret',
         'aws_session_token': 'stoken'
     }
     config = UploadConfig()
     config.areas[self.area.uuid]['credentials'] = stored_creds
     config.save()
     return stored_creds
Exemplo n.º 3
0
    def test_when_given_an_alias_that_matches_one_area_it_forgets_that_area(
            self):
        area = self.mock_current_upload_area()
        self.assertIn(area.uuid, UploadConfig().areas)
        self.assertEqual(area.uuid, UploadConfig().current_area)

        forget_area(area.uuid)

        self.assertNotIn(area.uuid, UploadConfig().areas)
        self.assertEqual(None, UploadConfig().current_area)
Exemplo n.º 4
0
    def setUp(self):
        super(self.__class__, self).setUp()
        config = UploadConfig()
        config._config.upload.preprod_api_url_template = "https://prefix.{deployment_stage}.suffix/v1"
        config._config.upload.production_api_url = "https://prefix.suffix/v1"
        config.save()

        self.api_key = "api-key-{}".format(random.randint(0, 999999999))
        self.api_client = ApiClient(deployment_stage="test",
                                    authentication_token=self.api_key)
Exemplo n.º 5
0
    def test_when_given_an_alias_that_matches_one_area_it_forgets_that_area(
            self):
        area = self.mock_current_upload_area()
        self.assertIn(area.uuid, UploadConfig().areas)
        self.assertEqual(area.uuid, UploadConfig().current_area)

        with CapturingIO('stdout'):
            args = Namespace(uuid_or_alias=area.uuid)
            ForgetCommand(args)

        self.assertNotIn(area.uuid, UploadConfig().areas)
        self.assertEqual(None, UploadConfig().current_area)
Exemplo n.º 6
0
 def mock_upload_area(self, area_uuid=None, bucket_name=None):
     """
     Create a UUID and URI for a fake upload area, store it in Tweak config.
     """
     if not area_uuid:
         area_uuid = str(uuid.uuid4())
     if not bucket_name:
         bucket_name = self.UPLOAD_BUCKET_NAME_TEMPLATE.format(deployment_stage=self.deployment_stage)
     area_uri_str = "s3://{bucket}/{uuid}/".format(bucket=bucket_name, uuid=area_uuid)
     area_uri = UploadAreaURI(area_uri_str)
     config = UploadConfig()
     config.add_area(area_uri)
     area = self.upload_service.upload_area(area_uri=area_uri)
     return area
 def __init__(self, args):
     area_uuid = args.uuid
     env = args.env
     out_put = args.output_file_name
     config = UploadConfig()
     if not area_uuid:
         area_uuid = config.current_area
     if not env:
         area_uri = config.area_uri(area_uuid)
         env = area_uri.deployment_stage
     if not out_put:
         out_put = area_uuid
     UploadAreaFilesStatusCheck(env).check_file_statuses(area_uuid, out_put)
     print('File status report for {}/{} generated, located {}.txt'.format(
         env, area_uuid, out_put))
Exemplo n.º 8
0
 def __init__(self, args):
     area_uuid = args.uuid
     env = args.env
     config = UploadConfig()
     if not area_uuid:
         area_uuid = config.current_area
     if not env:
         area_uri = config.area_uri(area_uuid)
         env = area_uri.deployment_stage
     filename = args.filename
     status = FileStatusCheck(env).check_file_status(area_uuid, filename)
     if re.search('STATUS_RETRIEVAL_ERROR', status):
         print(status)
     else:
         print("File: {} in UploadArea: {}/{} is currently {}".format(filename, env, area_uuid, status))
Exemplo n.º 9
0
 def _save_and_select_area_by_uri(self, uri_string):
     if not uri_string.endswith('/'):
         uri_string += '/'
     uri = UploadAreaURI(uri_string)
     config = UploadConfig()
     if uri.area_uuid in config.areas:
         config.select_area(uri.area_uuid)
     else:
         config.add_area(uri)
         config.select_area(uri.area_uuid)
     print("Upload area %s selected." % uri.area_uuid)
     print(
         "In future you may refer to this upload area using the alias \"%s\""
         % config.unique_prefix(uri.area_uuid))
Exemplo n.º 10
0
    def __init__(self, args):
        config = UploadConfig()
        area_uuid = config.current_area
        area_uri = config.area_uri(area_uuid)
        upload_service = UploadService(
            deployment_stage=area_uri.deployment_stage)
        upload_area = upload_service.upload_area(area_uri=area_uri)

        for f in upload_area.list(detail=args.long):
            print(f['name'])
            if args.long:
                print("\t%-12s %d bytes\n\t%-12s %s\n\t%-12s %s" %
                      ('size', f['size'], 'URL', f['url'], 'Content-Type',
                       f['content_type']))
                if 'checksums' in f:
                    for checksum in ('S3_Etag', 'CRC32C', 'SHA1', 'SHA256'):
                        if checksum.lower() in f['checksums']:
                            print("\t%-12s %s" %
                                  (checksum, f['checksums'][checksum.lower()]))
Exemplo n.º 11
0
 def __init__(self, args):
     upload_area = args.uuid
     env = args.env
     config = UploadConfig()
     if not upload_area:
         upload_area = config.current_area
     if not env:
         env = UploadArea(uuid=upload_area).deployment_stage
     filename = args.filename
     status = FileStatusCheck(env).check_file_status(upload_area, filename)
     if re.search('STATUS_RETRIEVAL_ERROR', status):
         print(status)
     else:
         print("File: {} in UploadArea: {}/{} is currently {}".format(
             filename, env, upload_area, status))
Exemplo n.º 12
0
 def __init__(self, args):
     upload_area = args.uuid
     env = args.env
     out_put = args.output_file_name
     config = UploadConfig()
     if not upload_area:
         upload_area = config.current_area
     if not env:
         env = UploadArea(uuid=upload_area).deployment_stage
     if not out_put:
         out_put = upload_area
     UploadAreaFilesStatusCheck(env).check_file_statuses(
         upload_area, out_put)
     print('File status report for {}/{} generated, located {}.txt'.format(
         env, upload_area, out_put))
Exemplo n.º 13
0
 def setUp(self):
     super(self.__class__, self).setUp()
     config = UploadConfig()
     config._config.upload.preprod_api_url_template = "https://prefix.{deployment_stage}.suffix"
     config._config.upload.production_api_url = "https://prefix.suffix"
     config.save()
Exemplo n.º 14
0
 def mock_current_upload_area(self, area_uuid=None, bucket_name=None):
     area = self.mock_upload_area(area_uuid=area_uuid, bucket_name=bucket_name)
     UploadConfig().select_area(area.uuid)
     return area