Implement OVO for Barbican [4]
This patch set is to create a Base class OVO and implement some model classes like below: - ProjectQuotas - ProjectSecretStore - ProjectSecretStore Partial Implements: blueprint rolling-upgrade Change-Id: I92cdf1026f9e980e0eb87ea45c8d56e40688cf9d
This commit is contained in:
parent
1598d1e44c
commit
66036b2258
|
@ -13,7 +13,6 @@
|
|||
# under the License.
|
||||
|
||||
from barbican.objects import base
|
||||
from barbican.objects import certificate_authority
|
||||
from barbican.objects import container
|
||||
from barbican.objects import container_acl
|
||||
from barbican.objects import container_consumer_meta
|
||||
|
@ -36,7 +35,6 @@ from barbican.objects import transport_key
|
|||
|
||||
States = base.States
|
||||
BarbicanObject = base.BarbicanObject
|
||||
CertificateAuthority = certificate_authority.CertificateAuthority
|
||||
Container = container.Container
|
||||
ContainerACL = container_acl.ContainerACL
|
||||
ContainerConsumerMetadatum = container_consumer_meta.ContainerConsumerMetadatum
|
||||
|
@ -60,7 +58,6 @@ SecretStoreMetadatum = secret_store_metadatum.SecretStoreMetadatum
|
|||
__all__ = (
|
||||
States,
|
||||
BarbicanObject,
|
||||
CertificateAuthority,
|
||||
Container,
|
||||
ContainerACL,
|
||||
ContainerConsumerMetadatum,
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
# Copyright 2018 Fujitsu.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from oslo_versionedobjects import base as object_base
|
||||
|
||||
from barbican.common import exception
|
||||
from barbican import i18n as u
|
||||
from barbican.model import models
|
||||
from barbican.model import repositories as repos
|
||||
from barbican.objects import base
|
||||
from barbican.objects import fields
|
||||
|
||||
|
||||
@object_base.VersionedObjectRegistry.register
|
||||
class ProjectQuotas(base.BarbicanObject, base.BarbicanPersistentObject,
|
||||
object_base.VersionedObjectDictCompat):
|
||||
fields = {
|
||||
'project_id': fields.StringField(nullable=True),
|
||||
'secrets': fields.IntegerField(nullable=True, default=None),
|
||||
'containers': fields.IntegerField(nullable=True, default=None),
|
||||
'consumers': fields.IntegerField(nullable=True, default=None),
|
||||
'orders': fields.IntegerField(nullable=True, default=None),
|
||||
'cas': fields.IntegerField(nullable=True, default=None),
|
||||
'project': fields.ObjectField('Project', nullable=True, default=None),
|
||||
}
|
||||
|
||||
db_model = models.ProjectQuotas
|
||||
db_repo = repos.get_project_quotas_repository()
|
||||
synthetic_fields = ['project']
|
||||
|
||||
def _validate_fields(self, change_fields):
|
||||
msg = u._("Must supply non-None {0} argument for ProjectQuotas entry.")
|
||||
|
||||
if change_fields.get('project_id') is None:
|
||||
raise exception.MissingArgumentError(msg.format("project_id"))
|
||||
|
||||
def _get_db_entity(self, parsed_project_quotas=None):
|
||||
return self.db_model(parsed_project_quotas=parsed_project_quotas)
|
||||
|
||||
def create(self, session=None, parsed_project_quotas=None):
|
||||
change_fields = self._get_changed_persistent_fields()
|
||||
self._validate_fields(change_fields)
|
||||
db_entity = self._get_db_entity(
|
||||
parsed_project_quotas=parsed_project_quotas)
|
||||
db_entity.update(change_fields)
|
||||
db_entity = self.db_repo.create_from(db_entity, session=session)
|
||||
self._from_db_object(db_entity)
|
||||
|
||||
@classmethod
|
||||
def get_by_create_date(cls, offset_arg=None, limit_arg=None,
|
||||
suppress_exception=False, session=None):
|
||||
entities_db, offset, limit, total = \
|
||||
cls.db_repo.get_by_create_date(offset_arg, limit_arg,
|
||||
suppress_exception, session)
|
||||
entities = [cls()._from_db_object(entity_db)
|
||||
for entity_db in entities_db]
|
||||
return entities, offset, limit, total
|
||||
|
||||
@classmethod
|
||||
def create_or_update_by_project_id(cls, project_id,
|
||||
parsed_project_quotas,
|
||||
session=None):
|
||||
cls.db_repo.create_or_update_by_project_id(project_id,
|
||||
parsed_project_quotas,
|
||||
session)
|
||||
|
||||
@classmethod
|
||||
def get_by_external_project_id(cls, external_project_id,
|
||||
suppress_exception=False, session=None):
|
||||
entity_db = cls.db_repo. \
|
||||
get_by_external_project_id(external_project_id,
|
||||
suppress_exception, session)
|
||||
return cls()._from_db_object(entity_db)
|
||||
|
||||
@classmethod
|
||||
def delete_by_external_project_id(cls, external_project_id,
|
||||
suppress_exception=False, session=None):
|
||||
cls.db_repo.delete_by_external_project_id(external_project_id,
|
||||
suppress_exception,
|
||||
session)
|
|
@ -0,0 +1,61 @@
|
|||
# Copyright 2018 Fujitsu.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from oslo_versionedobjects import base as object_base
|
||||
|
||||
from barbican.model import models
|
||||
from barbican.model import repositories as repos
|
||||
from barbican.objects import base
|
||||
from barbican.objects import fields
|
||||
|
||||
|
||||
@object_base.VersionedObjectRegistry.register
|
||||
class ProjectSecretStore(base.BarbicanObject, base.BarbicanPersistentObject,
|
||||
object_base.VersionedObjectDictCompat):
|
||||
fields = {
|
||||
'secret_store_id': fields.StringField(),
|
||||
'project_id': fields.StringField(),
|
||||
'secret_store': fields.ObjectField('SecretStores',
|
||||
nullable=True, default=None),
|
||||
'project': fields.ObjectField('Project', nullable=True, default=None),
|
||||
'status': fields.StringField(nullable=True, default=base.States.ACTIVE)
|
||||
}
|
||||
|
||||
db_model = models.ProjectSecretStore
|
||||
db_repo = repos.get_project_secret_store_repository()
|
||||
synthetic_fields = ['secret_store', 'project']
|
||||
|
||||
@classmethod
|
||||
def get_secret_store_for_project(cls, project_id, external_project_id,
|
||||
suppress_exception=False, session=None):
|
||||
pss_db = cls.db_repo.get_secret_store_for_project(
|
||||
project_id,
|
||||
external_project_id,
|
||||
suppress_exception,
|
||||
session)
|
||||
return cls()._from_db_object(pss_db)
|
||||
|
||||
@classmethod
|
||||
def create_or_update_for_project(cls, project_id, secret_store_id,
|
||||
session=None):
|
||||
pss_db = cls.db_repo.create_or_update_for_project(project_id,
|
||||
secret_store_id,
|
||||
session)
|
||||
|
||||
return cls()._from_db_object(pss_db)
|
||||
|
||||
@classmethod
|
||||
def get_count_by_secret_store(cls, secret_store_id, session=None):
|
||||
number_pss = cls.db_repo.get_count_by_secret_store(secret_store_id,
|
||||
session)
|
||||
return number_pss
|
Loading…
Reference in New Issue