Exemple #1
0
def test_creds():
    os.environ['AWS_ACCESS_KEY_ID'] = boto.config.get(
        'Credentials', 'aws_access_key_id')
    os.environ['AWS_SECRET_ACCESS_KEY'] = boto.config.get(
        'Credentials', 'aws_secret_access_key')
    os.environ['AWS_SECURITY_TOKEN'] = boto.config.get(
        'Credentials', 'aws_security_token')

    try:
        sys.stdout.write('Validating temporary credentials..\n')
        s3 = boto.connect_s3()
        s3.get_all_buckets()
        expiration_string = boto.config.get('Credentials', 'expiration')
        exp_dt = datetime.datetime.strptime(
            expiration_string, '%Y-%m-%dT%H:%M:%SZ'
        )
        t_diff = exp_dt - datetime.datetime.utcnow()
        sys.stdout.write(
            'Temporary credentials validation successful! '
            'Token expires in %s seconds at %s\n' %
            (t_diff.seconds, expiration_string)
        )
        return True
    except:
        sys.stdout.write('Temporary credentials failed.\n')
        return False
Exemple #2
0
def test_creds(profile_name):
    try:
        logger.info('Validating temporary credentials..')
        if boto.config.getbool(profile_name, 'assumed_role'):
            logger.info('You are currently using the credentials of an '
                        'AssumedRole. Use the --clear flag to clear these '
                        'credentials')
        expiration_string = boto.config.get(profile_name, 'expiration')
        if expiration_string is None:
            logger.error('Expiration timestamp missing from temporary '
                         'credentials.')
            return False
        exp_dt = datetime.datetime.strptime(expiration_string,
                                            '%Y-%m-%dT%H:%M:%SZ')
        t_diff = exp_dt - datetime.datetime.utcnow()
        if t_diff.total_seconds() <= 0:
            logger.warn('Your temporary credentials have expired. '
                        'Attempting to renew...')
            return False

        # Validate against a real service. This may not be the best solution
        # for everyone, as the person attempting to fetch an STS token may
        # now have access to S3. This might need to be more flexible or we
        # could potentially ditch this altogether?
        s3 = boto.connect_s3()
        s3.get_all_buckets()

        logger.info('Temporary credentials validation successful! '
                    'Token expires in %s seconds at %s' %
                    (t_diff.seconds, expiration_string))
        return True
    except:
        logger.warn('Temporary credentials are invalid.')
        return False
    def test_s3_client(self):
        s3 = boto.s3.connect_to_region("us-east-1")

        s3.get_all_buckets()
        spans = self.memory_exporter.get_finished_spans()
        assert spans
        self.assertEqual(len(spans), 1)
        span = spans[0]
        assert_span_http_status_code(span, 200)
        self.assertEqual(span.attributes["http.method"], "GET")
        self.assertEqual(span.attributes["aws.operation"], "get_all_buckets")

        # Create a bucket command
        s3.create_bucket("cheese")
        spans = self.memory_exporter.get_finished_spans()
        assert spans
        self.assertEqual(len(spans), 2)
        span = spans[1]
        assert_span_http_status_code(span, 200)
        self.assertEqual(span.attributes["http.method"], "PUT")
        self.assertEqual(span.attributes["path"], "/")
        self.assertEqual(span.attributes["aws.operation"], "create_bucket")

        # Get the created bucket
        s3.get_bucket("cheese")
        spans = self.memory_exporter.get_finished_spans()
        assert spans
        self.assertEqual(len(spans), 3)
        span = spans[2]
        assert_span_http_status_code(span, 200)
        self.assertEqual(
            span.resource,
            Resource(attributes={
                "endpoint": "s3",
                "http_method": "head"
            }),
        )
        self.assertEqual(span.attributes["http.method"], "HEAD")
        self.assertEqual(span.attributes["aws.operation"], "head_bucket")
        self.assertEqual(span.name, "s3.command")

        # Checking for resource incase of error
        try:
            s3.get_bucket("big_bucket")
        except Exception:  # pylint: disable=broad-except
            spans = self.memory_exporter.get_finished_spans()
            assert spans
            span = spans[2]
            self.assertEqual(
                span.resource,
                Resource(attributes={
                    "endpoint": "s3",
                    "http_method": "head"
                }),
            )
Exemple #4
0
    def test_s3_client(self):
        s3 = boto.s3.connect_to_region('us-east-1')

        writer = self.tracer.writer
        Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(s3)

        s3.get_all_buckets()
        spans = writer.pop()
        assert spans
        self.assertEqual(len(spans), 1)
        span = spans[0]
        assert_is_measured(span)
        assert_span_http_status_code(span, 200)
        self.assertEqual(span.get_tag(http.METHOD), 'GET')
        self.assertEqual(span.get_tag('aws.operation'), 'get_all_buckets')

        # Create a bucket command
        s3.create_bucket('cheese')
        spans = writer.pop()
        assert spans
        self.assertEqual(len(spans), 1)
        span = spans[0]
        assert_is_measured(span)
        assert_span_http_status_code(span, 200)
        self.assertEqual(span.get_tag(http.METHOD), 'PUT')
        self.assertEqual(span.get_tag('path'), '/')
        self.assertEqual(span.get_tag('aws.operation'), 'create_bucket')

        # Get the created bucket
        s3.get_bucket('cheese')
        spans = writer.pop()
        assert spans
        self.assertEqual(len(spans), 1)
        span = spans[0]
        assert_is_measured(span)
        assert_span_http_status_code(span, 200)
        self.assertEqual(span.get_tag(http.METHOD), 'HEAD')
        self.assertEqual(span.get_tag('aws.operation'), 'head_bucket')
        self.assertEqual(span.service, 'test-boto-tracing.s3')
        self.assertEqual(span.resource, 's3.head')
        self.assertEqual(span.name, 's3.command')

        # Checking for resource incase of error
        try:
            s3.get_bucket('big_bucket')
        except Exception:
            spans = writer.pop()
            assert spans
            span = spans[0]
            self.assertEqual(span.resource, 's3.head')
Exemple #5
0
    def test_s3_client(self):
        s3 = boto.s3.connect_to_region("us-east-1")
        Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(s3)

        s3.get_all_buckets()
        spans = self.pop_spans()
        assert spans
        self.assertEqual(len(spans), 1)
        span = spans[0]
        assert_is_measured(span)
        assert_span_http_status_code(span, 200)
        self.assertEqual(span.get_tag(http.METHOD), "GET")
        self.assertEqual(span.get_tag("aws.operation"), "get_all_buckets")

        # Create a bucket command
        s3.create_bucket("cheese")
        spans = self.pop_spans()
        assert spans
        self.assertEqual(len(spans), 1)
        span = spans[0]
        assert_is_measured(span)
        assert_span_http_status_code(span, 200)
        self.assertEqual(span.get_tag(http.METHOD), "PUT")
        self.assertEqual(span.get_tag("path"), "/")
        self.assertEqual(span.get_tag("aws.operation"), "create_bucket")

        # Get the created bucket
        s3.get_bucket("cheese")
        spans = self.pop_spans()
        assert spans
        self.assertEqual(len(spans), 1)
        span = spans[0]
        assert_is_measured(span)
        assert_span_http_status_code(span, 200)
        self.assertEqual(span.get_tag(http.METHOD), "HEAD")
        self.assertEqual(span.get_tag("aws.operation"), "head_bucket")
        self.assertEqual(span.service, "test-boto-tracing.s3")
        self.assertEqual(span.resource, "s3.head")
        self.assertEqual(span.name, "s3.command")

        # Checking for resource incase of error
        try:
            s3.get_bucket("big_bucket")
        except Exception:
            spans = self.pop_spans()
            assert spans
            span = spans[0]
            self.assertEqual(span.resource, "s3.head")
Exemple #6
0
    def test_s3_client(self):
        s3 = boto.s3.connect_to_region("us-east-1")
        tracer = get_dummy_tracer()
        writer = tracer.writer
        Pin(service=self.TEST_SERVICE, tracer=tracer).onto(s3)

        s3.get_all_buckets()
        spans = writer.pop()
        assert spans
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.get_tag(http.STATUS_CODE), "200")
        eq_(span.get_tag(http.METHOD), "GET")
        eq_(span.get_tag('aws.operation'), "get_all_buckets")

        # Create a bucket command
        s3.create_bucket("cheese")
        spans = writer.pop()
        assert spans
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.get_tag(http.STATUS_CODE), "200")
        eq_(span.get_tag(http.METHOD), "PUT")
        eq_(span.get_tag('path'), '/')
        eq_(span.get_tag('aws.operation'), "create_bucket")

        # Get the created bucket
        s3.get_bucket("cheese")
        spans = writer.pop()
        assert spans
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.get_tag(http.STATUS_CODE), "200")
        eq_(span.get_tag(http.METHOD), "HEAD")
        eq_(span.get_tag('aws.operation'), "head_bucket")
        eq_(span.service, "test-boto-tracing.s3")
        eq_(span.resource, "s3.head")
        eq_(span.name, "s3.command")

        # Checking for resource incase of error
        try:
            s3.get_bucket("big_bucket")
        except Exception:
            spans = writer.pop()
            assert spans
            span = spans[0]
            eq_(span.resource, "s3.head")
Exemple #7
0
    def test_s3_client(self):
        s3 = boto.s3.connect_to_region("us-east-1")
        tracer = get_dummy_tracer()
        writer = tracer.writer
        Pin(service=self.TEST_SERVICE, tracer=tracer).onto(s3)

        s3.get_all_buckets()
        spans = writer.pop()
        assert spans
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.get_tag(http.STATUS_CODE), "200")
        eq_(span.get_tag(http.METHOD), "GET")
        eq_(span.get_tag('aws.operation'), "get_all_buckets")

        # Create a bucket command
        s3.create_bucket("cheese")
        spans = writer.pop()
        assert spans
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.get_tag(http.STATUS_CODE), "200")
        eq_(span.get_tag(http.METHOD), "PUT")
        eq_(span.get_tag('path'), '/')
        eq_(span.get_tag('aws.operation'), "create_bucket")

        # Get the created bucket
        s3.get_bucket("cheese")
        spans = writer.pop()
        assert spans
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.get_tag(http.STATUS_CODE), "200")
        eq_(span.get_tag(http.METHOD), "HEAD")
        eq_(span.get_tag('aws.operation'), "head_bucket")
        eq_(span.service, "test-boto-tracing.s3")
        eq_(span.resource, "s3.head")
        eq_(span.name, "s3.command")

        # Checking for resource incase of error
        try:
            s3.get_bucket("big_bucket")
        except Exception:
            spans = writer.pop()
            assert spans
            span = spans[0]
            eq_(span.resource, "s3.head")
Exemple #8
0
def test_creds():
    os.environ['AWS_ACCESS_KEY_ID'] = boto.config.get('Credentials',
                                                      'aws_access_key_id')
    os.environ['AWS_SECRET_ACCESS_KEY'] = boto.config.get(
        'Credentials', 'aws_secret_access_key')
    os.environ['AWS_SECURITY_TOKEN'] = boto.config.get('Credentials',
                                                       'aws_security_token')

    try:
        sys.stdout.write('Validating temporary credentials..\n')
        s3 = boto.connect_s3()
        s3.get_all_buckets()
        expiration_string = boto.config.get('Credentials', 'expiration')
        exp_dt = datetime.datetime.strptime(expiration_string,
                                            '%Y-%m-%dT%H:%M:%SZ')
        t_diff = exp_dt - datetime.datetime.utcnow()
        sys.stdout.write('Temporary credentials validation successful! '
                         'Token expires in %s seconds at %s\n' %
                         (t_diff.seconds, expiration_string))
        return True
    except:
        sys.stdout.write('Temporary credentials failed.\n')
        return False
Exemple #9
0
def test_creds(profile_name):
    try:
        logger.info('Validating temporary credentials..')
        if boto.config.getbool(profile_name, 'assumed_role'):
            logger.info('You are currently using the credentials of an '
                        'AssumedRole. Use the --clear flag to clear these '
                        'credentials')
        expiration_string = boto.config.get(profile_name, 'expiration')
        if expiration_string is None:
            logger.error('Expiration timestamp missing from temporary '
                         'credentials.')
            return False
        exp_dt = datetime.datetime.strptime(
            expiration_string, '%Y-%m-%dT%H:%M:%SZ'
        )
        t_diff = exp_dt - datetime.datetime.utcnow()
        if t_diff.total_seconds() <= 0:
            logger.warn('Your temporary credentials have expired. '
                        'Attempting to renew...')
            return False

        # Validate against a real service. This may not be the best solution
        # for everyone, as the person attempting to fetch an STS token may
        # now have access to S3. This might need to be more flexible or we
        # could potentially ditch this altogether?
        s3 = boto.connect_s3()
        s3.get_all_buckets()

        logger.info(
            'Temporary credentials validation successful! '
            'Token expires in %s seconds at %s' %
            (t_diff.seconds, expiration_string)
        )
        return True
    except:
        logger.warn('Temporary credentials are invalid.')
        return False