Exemple #1
0
 def test_to_dict_fields(self):
     consumer = models.SecretConsumerMetadatum(self.secret_id,
                                               self.project_id,
                                               self.service,
                                               self.resource_type,
                                               self.resource_id)
     fields = consumer.to_dict_fields()
     self.assertEqual(self.service, fields["service"])
     self.assertEqual(self.resource_type, fields["resource_type"])
     self.assertEqual(self.resource_id, fields["resource_id"])
Exemple #2
0
 def test_new_secret_consumer(self):
     consumer = models.SecretConsumerMetadatum(self.secret_id,
                                               self.project_id,
                                               self.service,
                                               self.resource_type,
                                               self.resource_id)
     self.assertEqual(self.secret_id, consumer.secret_id)
     self.assertEqual(self.project_id, consumer.project_id)
     self.assertEqual(self.service, consumer.service)
     self.assertEqual(self.resource_type, consumer.resource_type)
     self.assertEqual(self.resource_id, consumer.resource_id)
     self.assertEqual(models.States.ACTIVE, consumer.status)
Exemple #3
0
def create_secret_consumer(secret=None,
                           service="service",
                           resource_id="resource_id",
                           resource_type="resource_type",
                           session=None):
    consumer = models.SecretConsumerMetadatum(
        secret_id=secret.id,
        project_id=secret.project_id,
        service=service,
        resource_type=resource_type,
        resource_id=resource_id,
    )
    repo = repositories.get_secret_consumer_repository()
    repo.create_from(consumer, session=session)
    return consumer
Exemple #4
0
    def on_post(self, external_project_id, **kwargs):

        project = res.get_or_create_project(external_project_id)
        data = api.load_body(pecan.request, validator=self.validator)
        LOG.debug('Start on_post...%s', data)

        self.quota_enforcer.enforce(project)

        new_consumer = models.SecretConsumerMetadatum(
            self.secret_id,
            project.id,
            data["service"],
            data["resource_type"],
            data["resource_id"],
        )
        self.consumer_repo.create_or_update_from(new_consumer, self.secret)

        url = hrefs.convert_consumer_to_href(new_consumer.secret_id)
        pecan.response.headers['Location'] = url

        LOG.info('Created a consumer for project: %s', external_project_id)

        return self._return_secret_data(self.secret_id)
Exemple #5
0
    def test_should_update_with_duplicate_consumer(self):
        consumer1 = self._create_consumer()
        self.assertEqual(1, len(self.secret.consumers))

        # Commit things so far, because the 'create_or_update_from' call below
        # will handle consumer metadata with same composite key items already
        # existing, and then rollback this session's transaction, which would
        # remove the items added above and result in a not-found error below.
        self.session.commit()

        consumer2 = models.SecretConsumerMetadatum(
            secret_id=consumer1.secret_id,
            project_id=consumer1.project_id,
            service=consumer1.service,
            resource_type=consumer1.resource_type,
            resource_id=consumer1.resource_id,
        )

        self.consumer_repo.create_or_update_from(consumer2, self.secret,
                                                 self.session)

        secret = self.secret_repo.get_secret_by_id(self.secret.id,
                                                   session=self.session)
        self.assertEqual(1, len(secret.consumers))