Add ruff
Change-Id: I49d4394460acd22de6ac5ed22d5230867236d186 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
+9
-15
@@ -1,32 +1,26 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v5.0.0
|
||||
rev: v6.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
# Replaces or checks mixed line ending
|
||||
- id: mixed-line-ending
|
||||
args: ['--fix', 'lf']
|
||||
exclude: '.*\.(svg)$'
|
||||
# Forbid files which have a UTF-8 byte-order marker
|
||||
- id: check-byte-order-marker
|
||||
# Checks that non-binary executables have a proper shebang
|
||||
- id: fix-byte-order-marker
|
||||
- id: check-executables-have-shebangs
|
||||
# Check for files that contain merge conflict strings.
|
||||
- id: check-merge-conflict
|
||||
# Check for debugger imports and py37+ breakpoint()
|
||||
# calls in python source
|
||||
- id: debug-statements
|
||||
- id: check-yaml
|
||||
files: .*\.(yaml|yml)$
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.13.0
|
||||
hooks:
|
||||
- id: ruff-check
|
||||
args: ['--fix', '--unsafe-fixes']
|
||||
- id: ruff-format
|
||||
- repo: https://opendev.org/openstack/hacking
|
||||
rev: 7.0.0
|
||||
hooks:
|
||||
- id: hacking
|
||||
additional_dependencies:
|
||||
- flake8-import-order>=0.18.0,<0.19.0
|
||||
additional_dependencies: []
|
||||
exclude: '^(doc|releasenotes)/.*$'
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v3.18.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py3-only]
|
||||
|
||||
+15
-13
@@ -18,21 +18,24 @@ ATTACHMENT_KEYNAME_TYPEURI = "typeURI"
|
||||
ATTACHMENT_KEYNAME_CONTENT = "content"
|
||||
ATTACHMENT_KEYNAME_NAME = "name"
|
||||
|
||||
ATTACHMENT_KEYNAMES = [ATTACHMENT_KEYNAME_TYPEURI,
|
||||
ATTACHMENT_KEYNAME_CONTENT,
|
||||
ATTACHMENT_KEYNAME_NAME]
|
||||
ATTACHMENT_KEYNAMES = [
|
||||
ATTACHMENT_KEYNAME_TYPEURI,
|
||||
ATTACHMENT_KEYNAME_CONTENT,
|
||||
ATTACHMENT_KEYNAME_NAME,
|
||||
]
|
||||
|
||||
|
||||
class Attachment(cadftype.CADFAbstractType):
|
||||
|
||||
# TODO(mrutkows): OpenStack / Ceilometer may want to define
|
||||
# the set of approved attachment types in order to
|
||||
# limit and validate them.
|
||||
typeURI = cadftype.ValidatorDescriptor(ATTACHMENT_KEYNAME_TYPEURI,
|
||||
lambda x: isinstance(x, str))
|
||||
typeURI = cadftype.ValidatorDescriptor(
|
||||
ATTACHMENT_KEYNAME_TYPEURI, lambda x: isinstance(x, str)
|
||||
)
|
||||
content = cadftype.ValidatorDescriptor(ATTACHMENT_KEYNAME_CONTENT)
|
||||
name = cadftype.ValidatorDescriptor(ATTACHMENT_KEYNAME_NAME,
|
||||
lambda x: isinstance(x, str))
|
||||
name = cadftype.ValidatorDescriptor(
|
||||
ATTACHMENT_KEYNAME_NAME, lambda x: isinstance(x, str)
|
||||
)
|
||||
|
||||
def __init__(self, typeURI=None, content=None, name=None):
|
||||
"""Create Attachment data type
|
||||
@@ -55,10 +58,9 @@ class Attachment(cadftype.CADFAbstractType):
|
||||
|
||||
# self validate cadf:Attachment type against schema
|
||||
def is_valid(self):
|
||||
"""Validation to ensure Attachment required attributes are set.
|
||||
"""
|
||||
"""Validation to ensure Attachment required attributes are set."""
|
||||
return (
|
||||
self._isset(ATTACHMENT_KEYNAME_TYPEURI) and
|
||||
self._isset(ATTACHMENT_KEYNAME_NAME) and
|
||||
self._isset(ATTACHMENT_KEYNAME_CONTENT)
|
||||
self._isset(ATTACHMENT_KEYNAME_TYPEURI)
|
||||
and self._isset(ATTACHMENT_KEYNAME_NAME)
|
||||
and self._isset(ATTACHMENT_KEYNAME_CONTENT)
|
||||
)
|
||||
|
||||
+128
-127
@@ -30,35 +30,37 @@ ACTION_EVALUATE = 'evaluate'
|
||||
ACTION_LIST = 'read/list'
|
||||
|
||||
# TODO(mrutkows): Make global using WSGI mechanism
|
||||
ACTION_TAXONOMY = frozenset([
|
||||
'backup',
|
||||
'capture',
|
||||
ACTION_CREATE,
|
||||
'configure',
|
||||
ACTION_READ,
|
||||
ACTION_LIST,
|
||||
ACTION_UPDATE,
|
||||
ACTION_DELETE,
|
||||
'monitor',
|
||||
'start',
|
||||
'stop',
|
||||
'deploy',
|
||||
'undeploy',
|
||||
'enable',
|
||||
'disable',
|
||||
'send',
|
||||
'receive',
|
||||
ACTION_AUTHENTICATE,
|
||||
'authenticate/login',
|
||||
'revoke',
|
||||
'renew',
|
||||
'restore',
|
||||
ACTION_EVALUATE,
|
||||
'allow',
|
||||
'deny',
|
||||
'notify',
|
||||
UNKNOWN
|
||||
])
|
||||
ACTION_TAXONOMY = frozenset(
|
||||
[
|
||||
'backup',
|
||||
'capture',
|
||||
ACTION_CREATE,
|
||||
'configure',
|
||||
ACTION_READ,
|
||||
ACTION_LIST,
|
||||
ACTION_UPDATE,
|
||||
ACTION_DELETE,
|
||||
'monitor',
|
||||
'start',
|
||||
'stop',
|
||||
'deploy',
|
||||
'undeploy',
|
||||
'enable',
|
||||
'disable',
|
||||
'send',
|
||||
'receive',
|
||||
ACTION_AUTHENTICATE,
|
||||
'authenticate/login',
|
||||
'revoke',
|
||||
'renew',
|
||||
'restore',
|
||||
ACTION_EVALUATE,
|
||||
'allow',
|
||||
'deny',
|
||||
'notify',
|
||||
UNKNOWN,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
# TODO(mrutkows): validate absolute URIs as well
|
||||
@@ -77,12 +79,9 @@ OUTCOME_FAILURE = 'failure'
|
||||
OUTCOME_PENDING = 'pending'
|
||||
|
||||
# TODO(mrutkows): Make global using WSGI mechanism
|
||||
OUTCOME_TAXONOMY = frozenset([
|
||||
OUTCOME_SUCCESS,
|
||||
OUTCOME_FAILURE,
|
||||
OUTCOME_PENDING,
|
||||
UNKNOWN
|
||||
])
|
||||
OUTCOME_TAXONOMY = frozenset(
|
||||
[OUTCOME_SUCCESS, OUTCOME_FAILURE, OUTCOME_PENDING, UNKNOWN]
|
||||
)
|
||||
|
||||
|
||||
# TODO(mrutkows): validate absolute URIs as well
|
||||
@@ -111,104 +110,106 @@ SECURITY_ROLE = 'data/security/role'
|
||||
SECURITY_SERVICE = 'data/security/service'
|
||||
SECURITY_TRUST = 'data/security/trust'
|
||||
SECURITY_ACCOUNT_USER = 'data/security/account/user'
|
||||
KEYMGR_SECRET = 'data/security/keymanager/secret'
|
||||
KEYMGR_SECRET = 'data/security/keymanager/secret' # noqa: S105
|
||||
KEYMGR_CONTAINER = 'data/security/keymanager/container'
|
||||
KEYMGR_ORDER = 'data/security/keymanager/order'
|
||||
KEYMGR_OTHERS = 'data/security/keymanager'
|
||||
|
||||
|
||||
# TODO(mrutkows): Make global using WSGI mechanism
|
||||
RESOURCE_TAXONOMY = frozenset([
|
||||
'storage',
|
||||
'storage/node',
|
||||
'storage/volume',
|
||||
'storage/memory',
|
||||
'storage/container',
|
||||
'storage/directory',
|
||||
'storage/database',
|
||||
'storage/queue',
|
||||
'compute',
|
||||
'compute/node',
|
||||
'compute/cpu',
|
||||
'compute/machine',
|
||||
'compute/process',
|
||||
'compute/thread',
|
||||
'network',
|
||||
'network/node',
|
||||
'network/node/host',
|
||||
'network/connection',
|
||||
'network/domain',
|
||||
'network/cluster',
|
||||
'service',
|
||||
'service/oss',
|
||||
'service/bss',
|
||||
'service/bss/metering',
|
||||
'service/composition',
|
||||
'service/compute',
|
||||
'service/database',
|
||||
SERVICE_SECURITY,
|
||||
SERVICE_KEYMGR,
|
||||
'service/security/account',
|
||||
ACCOUNT_USER,
|
||||
CADF_AUDIT_FILTER,
|
||||
'service/storage',
|
||||
'service/storage/block',
|
||||
'service/storage/image',
|
||||
'service/storage/object',
|
||||
'service/network',
|
||||
'data',
|
||||
'data/message',
|
||||
'data/workload',
|
||||
'data/workload/app',
|
||||
'data/workload/service',
|
||||
'data/workload/task',
|
||||
'data/workload/job',
|
||||
'data/file',
|
||||
'data/file/catalog',
|
||||
'data/file/log',
|
||||
'data/template',
|
||||
'data/package',
|
||||
'data/image',
|
||||
'data/module',
|
||||
'data/config',
|
||||
'data/directory',
|
||||
'data/database',
|
||||
'data/security',
|
||||
SECURITY_ACCOUNT,
|
||||
SECURITY_CREDENTIAL,
|
||||
SECURITY_DOMAIN,
|
||||
SECURITY_ENDPOINT,
|
||||
SECURITY_GROUP,
|
||||
SECURITY_IDENTITY,
|
||||
SECURITY_KEY,
|
||||
SECURITY_LICENCE,
|
||||
SECURITY_POLICY,
|
||||
SECURITY_PROFILE,
|
||||
SECURITY_PROJECT,
|
||||
SECURITY_REGION,
|
||||
SECURITY_ROLE,
|
||||
SECURITY_SERVICE,
|
||||
SECURITY_TRUST,
|
||||
SECURITY_ACCOUNT_USER,
|
||||
'data/security/account/user/privilege',
|
||||
'data/database/alias',
|
||||
'data/database/catalog',
|
||||
'data/database/constraints',
|
||||
'data/database/index',
|
||||
'data/database/instance',
|
||||
'data/database/key',
|
||||
'data/database/routine',
|
||||
'data/database/schema',
|
||||
'data/database/sequence',
|
||||
'data/database/table',
|
||||
'data/database/trigger',
|
||||
'data/database/view',
|
||||
KEYMGR_CONTAINER,
|
||||
KEYMGR_ORDER,
|
||||
KEYMGR_SECRET,
|
||||
KEYMGR_OTHERS,
|
||||
UNKNOWN
|
||||
])
|
||||
RESOURCE_TAXONOMY = frozenset(
|
||||
[
|
||||
'storage',
|
||||
'storage/node',
|
||||
'storage/volume',
|
||||
'storage/memory',
|
||||
'storage/container',
|
||||
'storage/directory',
|
||||
'storage/database',
|
||||
'storage/queue',
|
||||
'compute',
|
||||
'compute/node',
|
||||
'compute/cpu',
|
||||
'compute/machine',
|
||||
'compute/process',
|
||||
'compute/thread',
|
||||
'network',
|
||||
'network/node',
|
||||
'network/node/host',
|
||||
'network/connection',
|
||||
'network/domain',
|
||||
'network/cluster',
|
||||
'service',
|
||||
'service/oss',
|
||||
'service/bss',
|
||||
'service/bss/metering',
|
||||
'service/composition',
|
||||
'service/compute',
|
||||
'service/database',
|
||||
SERVICE_SECURITY,
|
||||
SERVICE_KEYMGR,
|
||||
'service/security/account',
|
||||
ACCOUNT_USER,
|
||||
CADF_AUDIT_FILTER,
|
||||
'service/storage',
|
||||
'service/storage/block',
|
||||
'service/storage/image',
|
||||
'service/storage/object',
|
||||
'service/network',
|
||||
'data',
|
||||
'data/message',
|
||||
'data/workload',
|
||||
'data/workload/app',
|
||||
'data/workload/service',
|
||||
'data/workload/task',
|
||||
'data/workload/job',
|
||||
'data/file',
|
||||
'data/file/catalog',
|
||||
'data/file/log',
|
||||
'data/template',
|
||||
'data/package',
|
||||
'data/image',
|
||||
'data/module',
|
||||
'data/config',
|
||||
'data/directory',
|
||||
'data/database',
|
||||
'data/security',
|
||||
SECURITY_ACCOUNT,
|
||||
SECURITY_CREDENTIAL,
|
||||
SECURITY_DOMAIN,
|
||||
SECURITY_ENDPOINT,
|
||||
SECURITY_GROUP,
|
||||
SECURITY_IDENTITY,
|
||||
SECURITY_KEY,
|
||||
SECURITY_LICENCE,
|
||||
SECURITY_POLICY,
|
||||
SECURITY_PROFILE,
|
||||
SECURITY_PROJECT,
|
||||
SECURITY_REGION,
|
||||
SECURITY_ROLE,
|
||||
SECURITY_SERVICE,
|
||||
SECURITY_TRUST,
|
||||
SECURITY_ACCOUNT_USER,
|
||||
'data/security/account/user/privilege',
|
||||
'data/database/alias',
|
||||
'data/database/catalog',
|
||||
'data/database/constraints',
|
||||
'data/database/index',
|
||||
'data/database/instance',
|
||||
'data/database/key',
|
||||
'data/database/routine',
|
||||
'data/database/schema',
|
||||
'data/database/sequence',
|
||||
'data/database/table',
|
||||
'data/database/trigger',
|
||||
'data/database/view',
|
||||
KEYMGR_CONTAINER,
|
||||
KEYMGR_ORDER,
|
||||
KEYMGR_SECRET,
|
||||
KEYMGR_OTHERS,
|
||||
UNKNOWN,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
# TODO(mrutkows): validate absolute URIs as well
|
||||
|
||||
+10
-13
@@ -24,11 +24,9 @@ EVENTTYPE_ACTIVITY = 'activity'
|
||||
EVENTTYPE_MONITOR = 'monitor'
|
||||
EVENTTYPE_CONTROL = 'control'
|
||||
|
||||
VALID_EVENTTYPES = frozenset([
|
||||
EVENTTYPE_ACTIVITY,
|
||||
EVENTTYPE_MONITOR,
|
||||
EVENTTYPE_CONTROL
|
||||
])
|
||||
VALID_EVENTTYPES = frozenset(
|
||||
[EVENTTYPE_ACTIVITY, EVENTTYPE_MONITOR, EVENTTYPE_CONTROL]
|
||||
)
|
||||
|
||||
|
||||
def is_valid_eventType(value):
|
||||
@@ -40,11 +38,9 @@ REPORTER_ROLE_OBSERVER = 'observer'
|
||||
REPORTER_ROLE_MODIFIER = 'modifier'
|
||||
REPORTER_ROLE_RELAY = 'relay'
|
||||
|
||||
VALID_REPORTER_ROLES = frozenset([
|
||||
REPORTER_ROLE_OBSERVER,
|
||||
REPORTER_ROLE_MODIFIER,
|
||||
REPORTER_ROLE_RELAY
|
||||
])
|
||||
VALID_REPORTER_ROLES = frozenset(
|
||||
[REPORTER_ROLE_OBSERVER, REPORTER_ROLE_MODIFIER, REPORTER_ROLE_RELAY]
|
||||
)
|
||||
|
||||
|
||||
def is_valid_reporter_role(value):
|
||||
@@ -62,12 +58,13 @@ class ValidatorDescriptor:
|
||||
if self.func(value):
|
||||
instance.__dict__[self.name] = value
|
||||
else:
|
||||
raise ValueError('%s failed validation: %s' %
|
||||
(self.name, self.func))
|
||||
raise ValueError(
|
||||
f'{self.name} failed validation: {self.func}'
|
||||
)
|
||||
else:
|
||||
instance.__dict__[self.name] = value
|
||||
else:
|
||||
raise ValueError('%s must not be None.' % self.name)
|
||||
raise ValueError(f'{self.name} must not be None.')
|
||||
|
||||
|
||||
class CADFAbstractType(metaclass=abc.ABCMeta):
|
||||
|
||||
+22
-20
@@ -18,26 +18,29 @@ from pycadf import utils
|
||||
TYPE_URI_CRED = cadftype.CADF_VERSION_1_0_0 + 'credential'
|
||||
|
||||
CRED_KEYNAME_TYPE = "type"
|
||||
CRED_KEYNAME_TOKEN = "token"
|
||||
CRED_KEYNAME_TOKEN = "token" # noqa: S105
|
||||
|
||||
CRED_KEYNAMES = [CRED_KEYNAME_TYPE,
|
||||
CRED_KEYNAME_TOKEN]
|
||||
CRED_KEYNAMES = [CRED_KEYNAME_TYPE, CRED_KEYNAME_TOKEN]
|
||||
|
||||
|
||||
FED_CRED_KEYNAME_IDENTITY_PROVIDER = "identity_provider"
|
||||
FED_CRED_KEYNAME_USER = "user"
|
||||
FED_CRED_KEYNAME_GROUPS = "groups"
|
||||
|
||||
FED_CRED_KEYNAMES = CRED_KEYNAMES + [FED_CRED_KEYNAME_IDENTITY_PROVIDER,
|
||||
FED_CRED_KEYNAME_USER,
|
||||
FED_CRED_KEYNAME_GROUPS]
|
||||
FED_CRED_KEYNAMES = CRED_KEYNAMES + [
|
||||
FED_CRED_KEYNAME_IDENTITY_PROVIDER,
|
||||
FED_CRED_KEYNAME_USER,
|
||||
FED_CRED_KEYNAME_GROUPS,
|
||||
]
|
||||
|
||||
|
||||
class Credential(cadftype.CADFAbstractType):
|
||||
type = cadftype.ValidatorDescriptor(CRED_KEYNAME_TYPE,
|
||||
lambda x: isinstance(x, str))
|
||||
token = cadftype.ValidatorDescriptor(CRED_KEYNAME_TOKEN,
|
||||
lambda x: isinstance(x, str))
|
||||
type = cadftype.ValidatorDescriptor(
|
||||
CRED_KEYNAME_TYPE, lambda x: isinstance(x, str)
|
||||
)
|
||||
token = cadftype.ValidatorDescriptor(
|
||||
CRED_KEYNAME_TOKEN, lambda x: isinstance(x, str)
|
||||
)
|
||||
|
||||
def __init__(self, token, type=None):
|
||||
"""Create Credential data type
|
||||
@@ -62,19 +65,17 @@ class Credential(cadftype.CADFAbstractType):
|
||||
|
||||
class FederatedCredential(Credential):
|
||||
identity_provider = cadftype.ValidatorDescriptor(
|
||||
FED_CRED_KEYNAME_IDENTITY_PROVIDER,
|
||||
lambda x: isinstance(x, str))
|
||||
FED_CRED_KEYNAME_IDENTITY_PROVIDER, lambda x: isinstance(x, str)
|
||||
)
|
||||
user = cadftype.ValidatorDescriptor(
|
||||
FED_CRED_KEYNAME_USER,
|
||||
lambda x: isinstance(x, str))
|
||||
FED_CRED_KEYNAME_USER, lambda x: isinstance(x, str)
|
||||
)
|
||||
groups = cadftype.ValidatorDescriptor(
|
||||
FED_CRED_KEYNAME_GROUPS,
|
||||
lambda x: isinstance(x, list))
|
||||
FED_CRED_KEYNAME_GROUPS, lambda x: isinstance(x, list)
|
||||
)
|
||||
|
||||
def __init__(self, token, type, identity_provider, user, groups):
|
||||
super().__init__(
|
||||
token=token,
|
||||
type=type)
|
||||
super().__init__(token=token, type=type)
|
||||
|
||||
# FederatedCredential.identity_provider
|
||||
setattr(self, FED_CRED_KEYNAME_IDENTITY_PROVIDER, identity_provider)
|
||||
@@ -92,4 +93,5 @@ class FederatedCredential(Credential):
|
||||
and self._isset(CRED_KEYNAME_TYPE)
|
||||
and self._isset(FED_CRED_KEYNAME_IDENTITY_PROVIDER)
|
||||
and self._isset(FED_CRED_KEYNAME_USER)
|
||||
and self._isset(FED_CRED_KEYNAME_GROUPS))
|
||||
and self._isset(FED_CRED_KEYNAME_GROUPS)
|
||||
)
|
||||
|
||||
+12
-9
@@ -20,19 +20,23 @@ ENDPOINT_KEYNAME_URL = "url"
|
||||
ENDPOINT_KEYNAME_NAME = "name"
|
||||
ENDPOINT_KEYNAME_PORT = "port"
|
||||
|
||||
ENDPOINT_KEYNAMES = [ENDPOINT_KEYNAME_URL,
|
||||
ENDPOINT_KEYNAME_NAME,
|
||||
ENDPOINT_KEYNAME_PORT]
|
||||
ENDPOINT_KEYNAMES = [
|
||||
ENDPOINT_KEYNAME_URL,
|
||||
ENDPOINT_KEYNAME_NAME,
|
||||
ENDPOINT_KEYNAME_PORT,
|
||||
]
|
||||
|
||||
|
||||
class Endpoint(cadftype.CADFAbstractType):
|
||||
|
||||
url = cadftype.ValidatorDescriptor(
|
||||
ENDPOINT_KEYNAME_URL, lambda x: isinstance(x, str))
|
||||
ENDPOINT_KEYNAME_URL, lambda x: isinstance(x, str)
|
||||
)
|
||||
name = cadftype.ValidatorDescriptor(
|
||||
ENDPOINT_KEYNAME_NAME, lambda x: isinstance(x, str))
|
||||
ENDPOINT_KEYNAME_NAME, lambda x: isinstance(x, str)
|
||||
)
|
||||
port = cadftype.ValidatorDescriptor(
|
||||
ENDPOINT_KEYNAME_PORT, lambda x: isinstance(x, str))
|
||||
ENDPOINT_KEYNAME_PORT, lambda x: isinstance(x, str)
|
||||
)
|
||||
|
||||
def __init__(self, url, name=None, port=None):
|
||||
"""Create Endpoint data type
|
||||
@@ -53,6 +57,5 @@ class Endpoint(cadftype.CADFAbstractType):
|
||||
|
||||
# TODO(mrutkows): validate this cadf:ENDPOINT type against schema
|
||||
def is_valid(self):
|
||||
"""Validation to ensure Endpoint required attributes are set.
|
||||
"""
|
||||
"""Validation to ensure Endpoint required attributes are set."""
|
||||
return self._isset(ENDPOINT_KEYNAME_URL)
|
||||
|
||||
+114
-77
@@ -46,70 +46,102 @@ EVENT_KEYNAME_OBSERVER = "observer"
|
||||
EVENT_KEYNAME_OBSERVERID = "observerId"
|
||||
EVENT_KEYNAME_REPORTERCHAIN = "reporterchain"
|
||||
|
||||
EVENT_KEYNAMES = [EVENT_KEYNAME_TYPEURI,
|
||||
EVENT_KEYNAME_EVENTTYPE,
|
||||
EVENT_KEYNAME_ID,
|
||||
EVENT_KEYNAME_EVENTTIME,
|
||||
EVENT_KEYNAME_INITIATOR,
|
||||
EVENT_KEYNAME_INITIATORID,
|
||||
EVENT_KEYNAME_ACTION,
|
||||
EVENT_KEYNAME_TARGET,
|
||||
EVENT_KEYNAME_TARGETID,
|
||||
EVENT_KEYNAME_OUTCOME,
|
||||
EVENT_KEYNAME_REASON,
|
||||
EVENT_KEYNAME_SEVERITY,
|
||||
EVENT_KEYNAME_NAME,
|
||||
EVENT_KEYNAME_MEASUREMENTS,
|
||||
EVENT_KEYNAME_TAGS,
|
||||
EVENT_KEYNAME_ATTACHMENTS,
|
||||
EVENT_KEYNAME_OBSERVER,
|
||||
EVENT_KEYNAME_OBSERVERID,
|
||||
EVENT_KEYNAME_REPORTERCHAIN]
|
||||
EVENT_KEYNAMES = [
|
||||
EVENT_KEYNAME_TYPEURI,
|
||||
EVENT_KEYNAME_EVENTTYPE,
|
||||
EVENT_KEYNAME_ID,
|
||||
EVENT_KEYNAME_EVENTTIME,
|
||||
EVENT_KEYNAME_INITIATOR,
|
||||
EVENT_KEYNAME_INITIATORID,
|
||||
EVENT_KEYNAME_ACTION,
|
||||
EVENT_KEYNAME_TARGET,
|
||||
EVENT_KEYNAME_TARGETID,
|
||||
EVENT_KEYNAME_OUTCOME,
|
||||
EVENT_KEYNAME_REASON,
|
||||
EVENT_KEYNAME_SEVERITY,
|
||||
EVENT_KEYNAME_NAME,
|
||||
EVENT_KEYNAME_MEASUREMENTS,
|
||||
EVENT_KEYNAME_TAGS,
|
||||
EVENT_KEYNAME_ATTACHMENTS,
|
||||
EVENT_KEYNAME_OBSERVER,
|
||||
EVENT_KEYNAME_OBSERVERID,
|
||||
EVENT_KEYNAME_REPORTERCHAIN,
|
||||
]
|
||||
|
||||
|
||||
class Event(cadftype.CADFAbstractType):
|
||||
|
||||
eventType = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_EVENTTYPE, lambda x: cadftype.is_valid_eventType(x))
|
||||
id = cadftype.ValidatorDescriptor(EVENT_KEYNAME_ID,
|
||||
lambda x: identifier.is_valid(x))
|
||||
eventTime = cadftype.ValidatorDescriptor(EVENT_KEYNAME_EVENTTIME,
|
||||
lambda x: timestamp.is_valid(x))
|
||||
EVENT_KEYNAME_EVENTTYPE, lambda x: cadftype.is_valid_eventType(x)
|
||||
)
|
||||
id = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_ID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
eventTime = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_EVENTTIME, lambda x: timestamp.is_valid(x)
|
||||
)
|
||||
initiator = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_INITIATOR,
|
||||
(lambda x: isinstance(x, resource.Resource) and x.is_valid()
|
||||
and x.id != 'initiator'))
|
||||
(
|
||||
lambda x: isinstance(x, resource.Resource)
|
||||
and x.is_valid()
|
||||
and x.id != 'initiator'
|
||||
),
|
||||
)
|
||||
initiatorId = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_INITIATORID, lambda x: identifier.is_valid(x))
|
||||
EVENT_KEYNAME_INITIATORID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
action = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_ACTION, lambda x: cadftaxonomy.is_valid_action(x))
|
||||
EVENT_KEYNAME_ACTION, lambda x: cadftaxonomy.is_valid_action(x)
|
||||
)
|
||||
target = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_TARGET,
|
||||
(lambda x: isinstance(x, resource.Resource) and x.is_valid()
|
||||
and x.id != 'target'))
|
||||
(
|
||||
lambda x: isinstance(x, resource.Resource)
|
||||
and x.is_valid()
|
||||
and x.id != 'target'
|
||||
),
|
||||
)
|
||||
targetId = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_TARGETID, lambda x: identifier.is_valid(x))
|
||||
EVENT_KEYNAME_TARGETID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
outcome = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_OUTCOME, lambda x: cadftaxonomy.is_valid_outcome(x))
|
||||
EVENT_KEYNAME_OUTCOME, lambda x: cadftaxonomy.is_valid_outcome(x)
|
||||
)
|
||||
reason = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_REASON,
|
||||
lambda x: isinstance(x, reason.Reason) and x.is_valid())
|
||||
name = cadftype.ValidatorDescriptor(EVENT_KEYNAME_NAME,
|
||||
lambda x: isinstance(x, str))
|
||||
severity = cadftype.ValidatorDescriptor(EVENT_KEYNAME_SEVERITY,
|
||||
lambda x: isinstance(x, str))
|
||||
lambda x: isinstance(x, reason.Reason) and x.is_valid(),
|
||||
)
|
||||
name = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_NAME, lambda x: isinstance(x, str)
|
||||
)
|
||||
severity = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_SEVERITY, lambda x: isinstance(x, str)
|
||||
)
|
||||
observer = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_OBSERVER,
|
||||
(lambda x: isinstance(x, resource.Resource) and x.is_valid()))
|
||||
(lambda x: isinstance(x, resource.Resource) and x.is_valid()),
|
||||
)
|
||||
observerId = cadftype.ValidatorDescriptor(
|
||||
EVENT_KEYNAME_OBSERVERID, lambda x: identifier.is_valid(x))
|
||||
EVENT_KEYNAME_OBSERVERID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
|
||||
def __init__(self, eventType=cadftype.EVENTTYPE_ACTIVITY,
|
||||
id=None, eventTime=None,
|
||||
action=cadftaxonomy.UNKNOWN, outcome=cadftaxonomy.UNKNOWN,
|
||||
initiator=None, initiatorId=None, target=None, targetId=None,
|
||||
severity=None, reason=None, observer=None, observerId=None,
|
||||
name=None):
|
||||
def __init__(
|
||||
self,
|
||||
eventType=cadftype.EVENTTYPE_ACTIVITY,
|
||||
id=None,
|
||||
eventTime=None,
|
||||
action=cadftaxonomy.UNKNOWN,
|
||||
outcome=cadftaxonomy.UNKNOWN,
|
||||
initiator=None,
|
||||
initiatorId=None,
|
||||
target=None,
|
||||
targetId=None,
|
||||
severity=None,
|
||||
reason=None,
|
||||
observer=None,
|
||||
observerId=None,
|
||||
name=None,
|
||||
):
|
||||
"""Create an Event
|
||||
|
||||
:param eventType: eventType of Event. Defaults to 'activity' type
|
||||
@@ -138,8 +170,9 @@ class Event(cadftype.CADFAbstractType):
|
||||
setattr(self, EVENT_KEYNAME_ID, id or identifier.generate_uuid())
|
||||
|
||||
# Event.eventTime (Mandatory)
|
||||
setattr(self, EVENT_KEYNAME_EVENTTIME,
|
||||
eventTime or timestamp.get_utc_now())
|
||||
setattr(
|
||||
self, EVENT_KEYNAME_EVENTTIME, eventTime or timestamp.get_utc_now()
|
||||
)
|
||||
|
||||
# Event.action (Mandatory)
|
||||
setattr(self, EVENT_KEYNAME_ACTION, action)
|
||||
@@ -192,14 +225,14 @@ class Event(cadftype.CADFAbstractType):
|
||||
if not hasattr(self, EVENT_KEYNAME_REPORTERCHAIN):
|
||||
setattr(self, EVENT_KEYNAME_REPORTERCHAIN, list())
|
||||
|
||||
reporterchain = getattr(self,
|
||||
EVENT_KEYNAME_REPORTERCHAIN)
|
||||
reporterchain = getattr(self, EVENT_KEYNAME_REPORTERCHAIN)
|
||||
reporterchain.append(step)
|
||||
else:
|
||||
raise ValueError('Invalid reporterstep')
|
||||
else:
|
||||
raise ValueError('Invalid reporterstep. '
|
||||
'Value must be a Reporterstep')
|
||||
raise ValueError(
|
||||
'Invalid reporterstep. Value must be a Reporterstep'
|
||||
)
|
||||
|
||||
# Event.measurements
|
||||
def add_measurement(self, measure_val):
|
||||
@@ -207,11 +240,10 @@ class Event(cadftype.CADFAbstractType):
|
||||
|
||||
:param measure_val: Measurement data type to be added to Event
|
||||
"""
|
||||
if (measure_val is not None
|
||||
and isinstance(measure_val, measurement.Measurement)):
|
||||
|
||||
if measure_val is not None and isinstance(
|
||||
measure_val, measurement.Measurement
|
||||
):
|
||||
if measure_val.is_valid():
|
||||
|
||||
# Create the list of event.Measurements if needed
|
||||
if not hasattr(self, EVENT_KEYNAME_MEASUREMENTS):
|
||||
setattr(self, EVENT_KEYNAME_MEASUREMENTS, list())
|
||||
@@ -221,8 +253,9 @@ class Event(cadftype.CADFAbstractType):
|
||||
else:
|
||||
raise ValueError('Invalid measurement')
|
||||
else:
|
||||
raise ValueError('Invalid measurement. '
|
||||
'Value must be a Measurement')
|
||||
raise ValueError(
|
||||
'Invalid measurement. Value must be a Measurement'
|
||||
)
|
||||
|
||||
# Event.tags
|
||||
def add_tag(self, tag_val):
|
||||
@@ -243,9 +276,9 @@ class Event(cadftype.CADFAbstractType):
|
||||
|
||||
:param attachment_val: Attachment to add to Event
|
||||
"""
|
||||
if (attachment_val is not None
|
||||
and isinstance(attachment_val, attachment.Attachment)):
|
||||
|
||||
if attachment_val is not None and isinstance(
|
||||
attachment_val, attachment.Attachment
|
||||
):
|
||||
if attachment_val.is_valid():
|
||||
# Create the list of Attachments if needed
|
||||
if not hasattr(self, EVENT_KEYNAME_ATTACHMENTS):
|
||||
@@ -256,27 +289,31 @@ class Event(cadftype.CADFAbstractType):
|
||||
else:
|
||||
raise ValueError('Invalid attachment')
|
||||
else:
|
||||
raise ValueError('Invalid attachment. '
|
||||
'Value must be an Attachment')
|
||||
raise ValueError('Invalid attachment. Value must be an Attachment')
|
||||
|
||||
# self validate cadf:Event record against schema
|
||||
def is_valid(self):
|
||||
"""Validation to ensure Event required attributes are set.
|
||||
"""
|
||||
"""Validation to ensure Event required attributes are set."""
|
||||
# TODO(mrutkows): Eventually, make sure all attributes are
|
||||
# from either the CADF spec. (or profiles thereof)
|
||||
# TODO(mrutkows): validate all child attributes that are CADF types
|
||||
return (
|
||||
self._isset(EVENT_KEYNAME_TYPEURI) and
|
||||
self._isset(EVENT_KEYNAME_EVENTTYPE) and
|
||||
self._isset(EVENT_KEYNAME_ID) and
|
||||
self._isset(EVENT_KEYNAME_EVENTTIME) and
|
||||
self._isset(EVENT_KEYNAME_ACTION) and
|
||||
self._isset(EVENT_KEYNAME_OUTCOME) and
|
||||
(self._isset(EVENT_KEYNAME_INITIATOR) ^
|
||||
self._isset(EVENT_KEYNAME_INITIATORID)) and
|
||||
(self._isset(EVENT_KEYNAME_TARGET) ^
|
||||
self._isset(EVENT_KEYNAME_TARGETID)) and
|
||||
(self._isset(EVENT_KEYNAME_OBSERVER) ^
|
||||
self._isset(EVENT_KEYNAME_OBSERVERID))
|
||||
self._isset(EVENT_KEYNAME_TYPEURI)
|
||||
and self._isset(EVENT_KEYNAME_EVENTTYPE)
|
||||
and self._isset(EVENT_KEYNAME_ID)
|
||||
and self._isset(EVENT_KEYNAME_EVENTTIME)
|
||||
and self._isset(EVENT_KEYNAME_ACTION)
|
||||
and self._isset(EVENT_KEYNAME_OUTCOME)
|
||||
and (
|
||||
self._isset(EVENT_KEYNAME_INITIATOR)
|
||||
^ self._isset(EVENT_KEYNAME_INITIATORID)
|
||||
)
|
||||
and (
|
||||
self._isset(EVENT_KEYNAME_TARGET)
|
||||
^ self._isset(EVENT_KEYNAME_TARGETID)
|
||||
)
|
||||
and (
|
||||
self._isset(EVENT_KEYNAME_OBSERVER)
|
||||
^ self._isset(EVENT_KEYNAME_OBSERVERID)
|
||||
)
|
||||
)
|
||||
|
||||
+11
-7
@@ -19,14 +19,18 @@ ERROR_UNKNOWN_EVENTTYPE = 'Unknown CADF EventType requested on factory method'
|
||||
|
||||
|
||||
class EventFactory:
|
||||
"""Factory class to create different required attributes for
|
||||
the following CADF event types:
|
||||
'activity': for tracking any interesting system activities for audit
|
||||
'monitor': Events that carry Metrics and Measurements and support
|
||||
standards such as NIST
|
||||
'control': For audit events that are based upon (security) policies
|
||||
and reflect some policy decision.
|
||||
"""CADF event factory
|
||||
|
||||
Factory class to create different required attributes for the following
|
||||
CADF event types:
|
||||
|
||||
:activity: for tracking any interesting system activities for audit
|
||||
:monitor: Events that carry Metrics and Measurements and support
|
||||
standards such as NIST
|
||||
:control: For audit events that are based upon (security) policies
|
||||
and reflect some policy decision.
|
||||
"""
|
||||
|
||||
def new_event(self, eventType=cadftype.EVENTTYPE_ACTIVITY, **kwargs):
|
||||
"""Create new event
|
||||
|
||||
|
||||
+45
-30
@@ -29,43 +29,58 @@ GEO_KEYNAME_STATE = "state"
|
||||
GEO_KEYNAME_REGIONICANN = "regionICANN"
|
||||
# GEO_KEYNAME_ANNOTATIONS = "annotations"
|
||||
|
||||
GEO_KEYNAMES = [GEO_KEYNAME_ID,
|
||||
GEO_KEYNAME_LATITUDE,
|
||||
GEO_KEYNAME_LONGITUDE,
|
||||
GEO_KEYNAME_ELEVATION,
|
||||
GEO_KEYNAME_ACCURACY,
|
||||
GEO_KEYNAME_CITY,
|
||||
GEO_KEYNAME_STATE,
|
||||
GEO_KEYNAME_REGIONICANN
|
||||
# GEO_KEYNAME_ANNOTATIONS
|
||||
]
|
||||
GEO_KEYNAMES = [
|
||||
GEO_KEYNAME_ID,
|
||||
GEO_KEYNAME_LATITUDE,
|
||||
GEO_KEYNAME_LONGITUDE,
|
||||
GEO_KEYNAME_ELEVATION,
|
||||
GEO_KEYNAME_ACCURACY,
|
||||
GEO_KEYNAME_CITY,
|
||||
GEO_KEYNAME_STATE,
|
||||
GEO_KEYNAME_REGIONICANN,
|
||||
# GEO_KEYNAME_ANNOTATIONS
|
||||
]
|
||||
|
||||
|
||||
class Geolocation(cadftype.CADFAbstractType):
|
||||
|
||||
id = cadftype.ValidatorDescriptor(GEO_KEYNAME_ID,
|
||||
lambda x: identifier.is_valid(x))
|
||||
id = cadftype.ValidatorDescriptor(
|
||||
GEO_KEYNAME_ID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
# TODO(mrutkows): we may want to do more validation to make
|
||||
# sure numeric range represented by string is valid
|
||||
latitude = cadftype.ValidatorDescriptor(GEO_KEYNAME_LATITUDE,
|
||||
lambda x: isinstance(x, str))
|
||||
longitude = cadftype.ValidatorDescriptor(GEO_KEYNAME_LONGITUDE,
|
||||
lambda x: isinstance(x, str))
|
||||
elevation = cadftype.ValidatorDescriptor(GEO_KEYNAME_ELEVATION,
|
||||
lambda x: isinstance(x, str))
|
||||
accuracy = cadftype.ValidatorDescriptor(GEO_KEYNAME_ACCURACY,
|
||||
lambda x: isinstance(x, str))
|
||||
city = cadftype.ValidatorDescriptor(GEO_KEYNAME_CITY,
|
||||
lambda x: isinstance(x, str))
|
||||
state = cadftype.ValidatorDescriptor(GEO_KEYNAME_STATE,
|
||||
lambda x: isinstance(x, str))
|
||||
latitude = cadftype.ValidatorDescriptor(
|
||||
GEO_KEYNAME_LATITUDE, lambda x: isinstance(x, str)
|
||||
)
|
||||
longitude = cadftype.ValidatorDescriptor(
|
||||
GEO_KEYNAME_LONGITUDE, lambda x: isinstance(x, str)
|
||||
)
|
||||
elevation = cadftype.ValidatorDescriptor(
|
||||
GEO_KEYNAME_ELEVATION, lambda x: isinstance(x, str)
|
||||
)
|
||||
accuracy = cadftype.ValidatorDescriptor(
|
||||
GEO_KEYNAME_ACCURACY, lambda x: isinstance(x, str)
|
||||
)
|
||||
city = cadftype.ValidatorDescriptor(
|
||||
GEO_KEYNAME_CITY, lambda x: isinstance(x, str)
|
||||
)
|
||||
state = cadftype.ValidatorDescriptor(
|
||||
GEO_KEYNAME_STATE, lambda x: isinstance(x, str)
|
||||
)
|
||||
regionICANN = cadftype.ValidatorDescriptor(
|
||||
GEO_KEYNAME_REGIONICANN,
|
||||
lambda x: isinstance(x, str))
|
||||
GEO_KEYNAME_REGIONICANN, lambda x: isinstance(x, str)
|
||||
)
|
||||
|
||||
def __init__(self, id=None, latitude=None, longitude=None,
|
||||
elevation=None, accuracy=None, city=None, state=None,
|
||||
regionICANN=None):
|
||||
def __init__(
|
||||
self,
|
||||
id=None,
|
||||
latitude=None,
|
||||
longitude=None,
|
||||
elevation=None,
|
||||
accuracy=None,
|
||||
city=None,
|
||||
state=None,
|
||||
regionICANN=None,
|
||||
):
|
||||
"""Create Geolocation data type
|
||||
|
||||
:param id: id of geolocation
|
||||
|
||||
+11
-9
@@ -21,18 +21,20 @@ def convert_req_action(method, details=None):
|
||||
:param details: Extra details to append to action.
|
||||
"""
|
||||
|
||||
mapping = {'get': cadftaxonomy.ACTION_READ,
|
||||
'head': cadftaxonomy.ACTION_READ,
|
||||
'post': cadftaxonomy.ACTION_CREATE,
|
||||
'put': cadftaxonomy.ACTION_UPDATE,
|
||||
'delete': cadftaxonomy.ACTION_DELETE,
|
||||
'patch': cadftaxonomy.ACTION_UPDATE,
|
||||
'options': cadftaxonomy.ACTION_READ,
|
||||
'trace': 'capture'}
|
||||
mapping = {
|
||||
'get': cadftaxonomy.ACTION_READ,
|
||||
'head': cadftaxonomy.ACTION_READ,
|
||||
'post': cadftaxonomy.ACTION_CREATE,
|
||||
'put': cadftaxonomy.ACTION_UPDATE,
|
||||
'delete': cadftaxonomy.ACTION_DELETE,
|
||||
'patch': cadftaxonomy.ACTION_UPDATE,
|
||||
'options': cadftaxonomy.ACTION_READ,
|
||||
'trace': 'capture',
|
||||
}
|
||||
|
||||
action = None
|
||||
if isinstance(method, str):
|
||||
action = mapping.get(method.lower())
|
||||
if action and isinstance(details, str):
|
||||
action += '/%s' % details
|
||||
action += f'/{details}'
|
||||
return action or cadftaxonomy.UNKNOWN
|
||||
|
||||
+16
-13
@@ -22,25 +22,29 @@ HOST_KEYNAME_ADDR = "address"
|
||||
HOST_KEYNAME_AGENT = "agent"
|
||||
HOST_KEYNAME_PLATFORM = "platform"
|
||||
|
||||
HOST_KEYNAMES = [HOST_KEYNAME_ID,
|
||||
HOST_KEYNAME_ADDR,
|
||||
HOST_KEYNAME_AGENT,
|
||||
HOST_KEYNAME_PLATFORM]
|
||||
HOST_KEYNAMES = [
|
||||
HOST_KEYNAME_ID,
|
||||
HOST_KEYNAME_ADDR,
|
||||
HOST_KEYNAME_AGENT,
|
||||
HOST_KEYNAME_PLATFORM,
|
||||
]
|
||||
|
||||
|
||||
class Host(cadftype.CADFAbstractType):
|
||||
|
||||
id = cadftype.ValidatorDescriptor(
|
||||
HOST_KEYNAME_ID, lambda x: identifier.is_valid(x))
|
||||
HOST_KEYNAME_ID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
address = cadftype.ValidatorDescriptor(
|
||||
HOST_KEYNAME_ADDR, lambda x: isinstance(x, str))
|
||||
HOST_KEYNAME_ADDR, lambda x: isinstance(x, str)
|
||||
)
|
||||
agent = cadftype.ValidatorDescriptor(
|
||||
HOST_KEYNAME_AGENT, lambda x: isinstance(x, str))
|
||||
HOST_KEYNAME_AGENT, lambda x: isinstance(x, str)
|
||||
)
|
||||
platform = cadftype.ValidatorDescriptor(
|
||||
HOST_KEYNAME_PLATFORM, lambda x: isinstance(x, str))
|
||||
HOST_KEYNAME_PLATFORM, lambda x: isinstance(x, str)
|
||||
)
|
||||
|
||||
def __init__(self, id=None, address=None, agent=None,
|
||||
platform=None):
|
||||
def __init__(self, id=None, address=None, agent=None, platform=None):
|
||||
"""Create Host data type
|
||||
|
||||
:param id: id of Host
|
||||
@@ -64,6 +68,5 @@ class Host(cadftype.CADFAbstractType):
|
||||
|
||||
# TODO(mrutkows): validate this cadf:Host type against schema
|
||||
def is_valid(self):
|
||||
"""Validation to ensure Host required attributes are set.
|
||||
"""
|
||||
"""Validation to ensure Host required attributes are set."""
|
||||
return True
|
||||
|
||||
+10
-6
@@ -20,9 +20,11 @@ from oslo_config import cfg
|
||||
|
||||
CONF = cfg.CONF
|
||||
opts = [
|
||||
cfg.StrOpt('namespace',
|
||||
default='openstack',
|
||||
help='namespace prefix for generated id'),
|
||||
cfg.StrOpt(
|
||||
'namespace',
|
||||
default='openstack',
|
||||
help='namespace prefix for generated id',
|
||||
),
|
||||
]
|
||||
CONF.register_opts(opts, group='audit')
|
||||
|
||||
@@ -49,7 +51,7 @@ def _check_valid_uuid(value):
|
||||
raise ValueError
|
||||
|
||||
value = re.sub('[{}-]|urn:uuid:', '', value)
|
||||
for val in [value[i:i + 32] for i in range(0, len(value), 32)]:
|
||||
for val in [value[i : i + 32] for i in range(0, len(value), 32)]:
|
||||
uuid.UUID(val)
|
||||
|
||||
|
||||
@@ -67,6 +69,8 @@ def is_valid(value):
|
||||
except (ValueError, TypeError):
|
||||
if not isinstance(value, str) or not value:
|
||||
return False
|
||||
warnings.warn('Invalid uuid: %s. To ensure interoperability, '
|
||||
'identifiers should be a valid uuid.' % (value))
|
||||
warnings.warn(
|
||||
f'Invalid uuid: {value}. To ensure interoperability, '
|
||||
'identifiers should be a valid uuid.'
|
||||
)
|
||||
return True
|
||||
|
||||
+21
-16
@@ -22,25 +22,30 @@ MEASUREMENT_KEYNAME_METRIC = "metric"
|
||||
MEASUREMENT_KEYNAME_METRICID = "metricId"
|
||||
MEASUREMENT_KEYNAME_CALCBY = "calculatedBy"
|
||||
|
||||
MEASUREMENT_KEYNAMES = [MEASUREMENT_KEYNAME_RESULT,
|
||||
MEASUREMENT_KEYNAME_METRICID,
|
||||
MEASUREMENT_KEYNAME_METRIC,
|
||||
MEASUREMENT_KEYNAME_CALCBY]
|
||||
MEASUREMENT_KEYNAMES = [
|
||||
MEASUREMENT_KEYNAME_RESULT,
|
||||
MEASUREMENT_KEYNAME_METRICID,
|
||||
MEASUREMENT_KEYNAME_METRIC,
|
||||
MEASUREMENT_KEYNAME_CALCBY,
|
||||
]
|
||||
|
||||
|
||||
class Measurement(cadftype.CADFAbstractType):
|
||||
|
||||
result = cadftype.ValidatorDescriptor(MEASUREMENT_KEYNAME_RESULT)
|
||||
metric = cadftype.ValidatorDescriptor(
|
||||
MEASUREMENT_KEYNAME_METRIC, lambda x: isinstance(x, metric.Metric))
|
||||
metricId = cadftype.ValidatorDescriptor(MEASUREMENT_KEYNAME_METRICID,
|
||||
lambda x: identifier.is_valid(x))
|
||||
MEASUREMENT_KEYNAME_METRIC, lambda x: isinstance(x, metric.Metric)
|
||||
)
|
||||
metricId = cadftype.ValidatorDescriptor(
|
||||
MEASUREMENT_KEYNAME_METRICID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
calculatedBy = cadftype.ValidatorDescriptor(
|
||||
MEASUREMENT_KEYNAME_CALCBY,
|
||||
(lambda x: isinstance(x, resource.Resource) and x.is_valid()))
|
||||
(lambda x: isinstance(x, resource.Resource) and x.is_valid()),
|
||||
)
|
||||
|
||||
def __init__(self, result=None, metric=None, metricId=None,
|
||||
calculatedBy=None):
|
||||
def __init__(
|
||||
self, result=None, metric=None, metricId=None, calculatedBy=None
|
||||
):
|
||||
"""Create Measurement data type
|
||||
|
||||
:param result: value of measurement
|
||||
@@ -66,8 +71,8 @@ class Measurement(cadftype.CADFAbstractType):
|
||||
|
||||
# self validate this cadf:Measurement type against schema
|
||||
def is_valid(self):
|
||||
"""Validation to ensure Measurement required attributes are set.
|
||||
"""
|
||||
return (self._isset(MEASUREMENT_KEYNAME_RESULT) and
|
||||
(self._isset(MEASUREMENT_KEYNAME_METRIC) ^
|
||||
self._isset(MEASUREMENT_KEYNAME_METRICID)))
|
||||
"""Validation to ensure Measurement required attributes are set."""
|
||||
return self._isset(MEASUREMENT_KEYNAME_RESULT) and (
|
||||
self._isset(MEASUREMENT_KEYNAME_METRIC)
|
||||
^ self._isset(MEASUREMENT_KEYNAME_METRICID)
|
||||
)
|
||||
|
||||
+23
-19
@@ -24,21 +24,24 @@ METRIC_KEYNAME_UNIT = "unit"
|
||||
METRIC_KEYNAME_NAME = "name"
|
||||
# METRIC_KEYNAME_ANNOTATIONS = "annotations"
|
||||
|
||||
METRIC_KEYNAMES = [METRIC_KEYNAME_METRICID,
|
||||
METRIC_KEYNAME_UNIT,
|
||||
METRIC_KEYNAME_NAME
|
||||
# METRIC_KEYNAME_ANNOTATIONS
|
||||
]
|
||||
METRIC_KEYNAMES = [
|
||||
METRIC_KEYNAME_METRICID,
|
||||
METRIC_KEYNAME_UNIT,
|
||||
METRIC_KEYNAME_NAME,
|
||||
# METRIC_KEYNAME_ANNOTATIONS
|
||||
]
|
||||
|
||||
|
||||
class Metric(cadftype.CADFAbstractType):
|
||||
|
||||
metricId = cadftype.ValidatorDescriptor(METRIC_KEYNAME_METRICID,
|
||||
lambda x: identifier.is_valid(x))
|
||||
unit = cadftype.ValidatorDescriptor(METRIC_KEYNAME_UNIT,
|
||||
lambda x: isinstance(x, str))
|
||||
name = cadftype.ValidatorDescriptor(METRIC_KEYNAME_NAME,
|
||||
lambda x: isinstance(x, str))
|
||||
metricId = cadftype.ValidatorDescriptor(
|
||||
METRIC_KEYNAME_METRICID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
unit = cadftype.ValidatorDescriptor(
|
||||
METRIC_KEYNAME_UNIT, lambda x: isinstance(x, str)
|
||||
)
|
||||
name = cadftype.ValidatorDescriptor(
|
||||
METRIC_KEYNAME_NAME, lambda x: isinstance(x, str)
|
||||
)
|
||||
|
||||
def __init__(self, metricId=None, unit=None, name=None):
|
||||
"""Create metric data type
|
||||
@@ -48,8 +51,11 @@ class Metric(cadftype.CADFAbstractType):
|
||||
:param name: name of metric
|
||||
"""
|
||||
# Metric.id
|
||||
setattr(self, METRIC_KEYNAME_METRICID,
|
||||
metricId or identifier.generate_uuid())
|
||||
setattr(
|
||||
self,
|
||||
METRIC_KEYNAME_METRICID,
|
||||
metricId or identifier.generate_uuid(),
|
||||
)
|
||||
|
||||
# Metric.unit
|
||||
if unit is not None:
|
||||
@@ -68,10 +74,8 @@ class Metric(cadftype.CADFAbstractType):
|
||||
|
||||
# self validate cadf:Metric type against schema
|
||||
def is_valid(self):
|
||||
"""Validation to ensure Metric required attributes are set.
|
||||
"""
|
||||
"""Validation to ensure Metric required attributes are set."""
|
||||
# Existence test, id, and unit attributes must both exist
|
||||
return (
|
||||
self._isset(METRIC_KEYNAME_METRICID) and
|
||||
self._isset(METRIC_KEYNAME_UNIT)
|
||||
return self._isset(METRIC_KEYNAME_METRICID) and self._isset(
|
||||
METRIC_KEYNAME_UNIT
|
||||
)
|
||||
|
||||
@@ -16,7 +16,6 @@ from pycadf import cadftype
|
||||
|
||||
|
||||
class Path(cadftype.CADFAbstractType):
|
||||
|
||||
def set_path_absolute(self):
|
||||
# TODO(mrutkows): validate absolute path format, else Type error
|
||||
raise NotImplementedError()
|
||||
|
||||
+25
-21
@@ -21,29 +21,31 @@ REASON_KEYNAME_REASONCODE = "reasonCode"
|
||||
REASON_KEYNAME_POLICYTYPE = "policyType"
|
||||
REASON_KEYNAME_POLICYID = "policyId"
|
||||
|
||||
REASON_KEYNAMES = [REASON_KEYNAME_REASONTYPE,
|
||||
REASON_KEYNAME_REASONCODE,
|
||||
REASON_KEYNAME_POLICYTYPE,
|
||||
REASON_KEYNAME_POLICYID]
|
||||
REASON_KEYNAMES = [
|
||||
REASON_KEYNAME_REASONTYPE,
|
||||
REASON_KEYNAME_REASONCODE,
|
||||
REASON_KEYNAME_POLICYTYPE,
|
||||
REASON_KEYNAME_POLICYID,
|
||||
]
|
||||
|
||||
|
||||
class Reason(cadftype.CADFAbstractType):
|
||||
|
||||
reasonType = cadftype.ValidatorDescriptor(
|
||||
REASON_KEYNAME_REASONTYPE,
|
||||
lambda x: isinstance(x, str))
|
||||
REASON_KEYNAME_REASONTYPE, lambda x: isinstance(x, str)
|
||||
)
|
||||
reasonCode = cadftype.ValidatorDescriptor(
|
||||
REASON_KEYNAME_REASONCODE,
|
||||
lambda x: isinstance(x, str))
|
||||
REASON_KEYNAME_REASONCODE, lambda x: isinstance(x, str)
|
||||
)
|
||||
policyType = cadftype.ValidatorDescriptor(
|
||||
REASON_KEYNAME_POLICYTYPE,
|
||||
lambda x: isinstance(x, str))
|
||||
REASON_KEYNAME_POLICYTYPE, lambda x: isinstance(x, str)
|
||||
)
|
||||
policyId = cadftype.ValidatorDescriptor(
|
||||
REASON_KEYNAME_POLICYID,
|
||||
lambda x: isinstance(x, str))
|
||||
REASON_KEYNAME_POLICYID, lambda x: isinstance(x, str)
|
||||
)
|
||||
|
||||
def __init__(self, reasonType=None, reasonCode=None, policyType=None,
|
||||
policyId=None):
|
||||
def __init__(
|
||||
self, reasonType=None, reasonCode=None, policyType=None, policyId=None
|
||||
):
|
||||
"""Create Reason data type
|
||||
|
||||
:param reasonType: domain URI which describes reasonCode
|
||||
@@ -70,10 +72,12 @@ class Reason(cadftype.CADFAbstractType):
|
||||
|
||||
# TODO(mrutkows): validate this cadf:Reason type against schema
|
||||
def is_valid(self):
|
||||
"""Validation to ensure Reason required attributes are set.
|
||||
"""
|
||||
"""Validation to ensure Reason required attributes are set."""
|
||||
# MUST have at least one valid pairing of reason+code or policy+id
|
||||
return ((self._isset(REASON_KEYNAME_REASONTYPE) and
|
||||
self._isset(REASON_KEYNAME_REASONCODE)) or
|
||||
(self._isset(REASON_KEYNAME_POLICYTYPE) and
|
||||
self._isset(REASON_KEYNAME_POLICYID)))
|
||||
return (
|
||||
self._isset(REASON_KEYNAME_REASONTYPE)
|
||||
and self._isset(REASON_KEYNAME_REASONCODE)
|
||||
) or (
|
||||
self._isset(REASON_KEYNAME_POLICYTYPE)
|
||||
and self._isset(REASON_KEYNAME_POLICYID)
|
||||
)
|
||||
|
||||
+26
-20
@@ -23,29 +23,37 @@ REPORTERSTEP_KEYNAME_REPORTERID = "reporterId"
|
||||
REPORTERSTEP_KEYNAME_REPORTERTIME = "reporterTime"
|
||||
# REPORTERSTEP_KEYNAME_ATTACHMENTS = "attachments"
|
||||
|
||||
REPORTERSTEP_KEYNAMES = [REPORTERSTEP_KEYNAME_ROLE,
|
||||
REPORTERSTEP_KEYNAME_REPORTER,
|
||||
REPORTERSTEP_KEYNAME_REPORTERID,
|
||||
REPORTERSTEP_KEYNAME_REPORTERTIME,
|
||||
# REPORTERSTEP_KEYNAME_ATTACHMENTS
|
||||
]
|
||||
REPORTERSTEP_KEYNAMES = [
|
||||
REPORTERSTEP_KEYNAME_ROLE,
|
||||
REPORTERSTEP_KEYNAME_REPORTER,
|
||||
REPORTERSTEP_KEYNAME_REPORTERID,
|
||||
REPORTERSTEP_KEYNAME_REPORTERTIME,
|
||||
# REPORTERSTEP_KEYNAME_ATTACHMENTS
|
||||
]
|
||||
|
||||
|
||||
class Reporterstep(cadftype.CADFAbstractType):
|
||||
|
||||
role = cadftype.ValidatorDescriptor(
|
||||
REPORTERSTEP_KEYNAME_ROLE,
|
||||
lambda x: cadftype.is_valid_reporter_role(x))
|
||||
REPORTERSTEP_KEYNAME_ROLE, lambda x: cadftype.is_valid_reporter_role(x)
|
||||
)
|
||||
reporter = cadftype.ValidatorDescriptor(
|
||||
REPORTERSTEP_KEYNAME_REPORTER,
|
||||
(lambda x: isinstance(x, resource.Resource) and x.is_valid()))
|
||||
(lambda x: isinstance(x, resource.Resource) and x.is_valid()),
|
||||
)
|
||||
reporterId = cadftype.ValidatorDescriptor(
|
||||
REPORTERSTEP_KEYNAME_REPORTERID, lambda x: identifier.is_valid(x))
|
||||
REPORTERSTEP_KEYNAME_REPORTERID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
reporterTime = cadftype.ValidatorDescriptor(
|
||||
REPORTERSTEP_KEYNAME_REPORTERTIME, lambda x: timestamp.is_valid(x))
|
||||
REPORTERSTEP_KEYNAME_REPORTERTIME, lambda x: timestamp.is_valid(x)
|
||||
)
|
||||
|
||||
def __init__(self, role=cadftype.REPORTER_ROLE_MODIFIER,
|
||||
reporterTime=None, reporter=None, reporterId=None):
|
||||
def __init__(
|
||||
self,
|
||||
role=cadftype.REPORTER_ROLE_MODIFIER,
|
||||
reporterTime=None,
|
||||
reporter=None,
|
||||
reporterId=None,
|
||||
):
|
||||
"""Create ReporterStep data type
|
||||
|
||||
:param role: optional role of Reporterstep. Defaults to 'modifier'
|
||||
@@ -70,10 +78,8 @@ class Reporterstep(cadftype.CADFAbstractType):
|
||||
|
||||
# self validate this cadf:Reporterstep type against schema
|
||||
def is_valid(self):
|
||||
"""Validation to ensure Reporterstep required attributes are set.
|
||||
"""
|
||||
return (
|
||||
self._isset(REPORTERSTEP_KEYNAME_ROLE) and
|
||||
(self._isset(REPORTERSTEP_KEYNAME_REPORTER) ^
|
||||
self._isset(REPORTERSTEP_KEYNAME_REPORTERID))
|
||||
"""Validation to ensure Reporterstep required attributes are set."""
|
||||
return self._isset(REPORTERSTEP_KEYNAME_ROLE) and (
|
||||
self._isset(REPORTERSTEP_KEYNAME_REPORTER)
|
||||
^ self._isset(REPORTERSTEP_KEYNAME_REPORTERID)
|
||||
)
|
||||
|
||||
+67
-42
@@ -35,50 +35,68 @@ RESOURCE_KEYNAME_HOST = "host"
|
||||
RESOURCE_KEYNAME_ADDRS = "addresses"
|
||||
RESOURCE_KEYNAME_ATTACHMENTS = "attachments"
|
||||
|
||||
RESOURCE_KEYNAMES = [RESOURCE_KEYNAME_TYPEURI,
|
||||
RESOURCE_KEYNAME_ID,
|
||||
RESOURCE_KEYNAME_NAME,
|
||||
RESOURCE_KEYNAME_DOMAIN,
|
||||
RESOURCE_KEYNAME_CRED,
|
||||
RESOURCE_KEYNAME_REF,
|
||||
RESOURCE_KEYNAME_GEO,
|
||||
RESOURCE_KEYNAME_GEOID,
|
||||
RESOURCE_KEYNAME_HOST,
|
||||
RESOURCE_KEYNAME_ADDRS,
|
||||
RESOURCE_KEYNAME_ATTACHMENTS]
|
||||
RESOURCE_KEYNAMES = [
|
||||
RESOURCE_KEYNAME_TYPEURI,
|
||||
RESOURCE_KEYNAME_ID,
|
||||
RESOURCE_KEYNAME_NAME,
|
||||
RESOURCE_KEYNAME_DOMAIN,
|
||||
RESOURCE_KEYNAME_CRED,
|
||||
RESOURCE_KEYNAME_REF,
|
||||
RESOURCE_KEYNAME_GEO,
|
||||
RESOURCE_KEYNAME_GEOID,
|
||||
RESOURCE_KEYNAME_HOST,
|
||||
RESOURCE_KEYNAME_ADDRS,
|
||||
RESOURCE_KEYNAME_ATTACHMENTS,
|
||||
]
|
||||
|
||||
|
||||
class Resource(cadftype.CADFAbstractType):
|
||||
|
||||
typeURI = cadftype.ValidatorDescriptor(
|
||||
RESOURCE_KEYNAME_TYPEURI, lambda x: cadftaxonomy.is_valid_resource(x))
|
||||
id = cadftype.ValidatorDescriptor(RESOURCE_KEYNAME_ID,
|
||||
lambda x: identifier.is_valid(x))
|
||||
name = cadftype.ValidatorDescriptor(RESOURCE_KEYNAME_NAME,
|
||||
lambda x: isinstance(x, str))
|
||||
domain = cadftype.ValidatorDescriptor(RESOURCE_KEYNAME_DOMAIN,
|
||||
lambda x: isinstance(x, str))
|
||||
RESOURCE_KEYNAME_TYPEURI, lambda x: cadftaxonomy.is_valid_resource(x)
|
||||
)
|
||||
id = cadftype.ValidatorDescriptor(
|
||||
RESOURCE_KEYNAME_ID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
name = cadftype.ValidatorDescriptor(
|
||||
RESOURCE_KEYNAME_NAME, lambda x: isinstance(x, str)
|
||||
)
|
||||
domain = cadftype.ValidatorDescriptor(
|
||||
RESOURCE_KEYNAME_DOMAIN, lambda x: isinstance(x, str)
|
||||
)
|
||||
credential = cadftype.ValidatorDescriptor(
|
||||
RESOURCE_KEYNAME_CRED, (lambda x: isinstance(x, credential.Credential)
|
||||
and x.is_valid()))
|
||||
RESOURCE_KEYNAME_CRED,
|
||||
(lambda x: isinstance(x, credential.Credential) and x.is_valid()),
|
||||
)
|
||||
host = cadftype.ValidatorDescriptor(
|
||||
RESOURCE_KEYNAME_HOST, lambda x: isinstance(x, host.Host))
|
||||
RESOURCE_KEYNAME_HOST, lambda x: isinstance(x, host.Host)
|
||||
)
|
||||
# TODO(mrutkows): validate the "ref" attribute is indeed a URI (format),
|
||||
# If it is a URL, we do not need to validate it is accessible/working,
|
||||
# for audit purposes this could have been a valid URL at some point
|
||||
# in the past or a URL that is only valid within some domain (e.g. a
|
||||
# private cloud)
|
||||
ref = cadftype.ValidatorDescriptor(RESOURCE_KEYNAME_REF,
|
||||
lambda x: isinstance(x, str))
|
||||
ref = cadftype.ValidatorDescriptor(
|
||||
RESOURCE_KEYNAME_REF, lambda x: isinstance(x, str)
|
||||
)
|
||||
geolocation = cadftype.ValidatorDescriptor(
|
||||
RESOURCE_KEYNAME_GEO,
|
||||
lambda x: isinstance(x, geolocation.Geolocation))
|
||||
RESOURCE_KEYNAME_GEO, lambda x: isinstance(x, geolocation.Geolocation)
|
||||
)
|
||||
geolocationId = cadftype.ValidatorDescriptor(
|
||||
RESOURCE_KEYNAME_GEOID, lambda x: identifier.is_valid(x))
|
||||
RESOURCE_KEYNAME_GEOID, lambda x: identifier.is_valid(x)
|
||||
)
|
||||
|
||||
def __init__(self, id=None, typeURI=cadftaxonomy.UNKNOWN, name=None,
|
||||
ref=None, domain=None, credential=None, host=None,
|
||||
geolocation=None, geolocationId=None):
|
||||
def __init__(
|
||||
self,
|
||||
id=None,
|
||||
typeURI=cadftaxonomy.UNKNOWN,
|
||||
name=None,
|
||||
ref=None,
|
||||
domain=None,
|
||||
credential=None,
|
||||
host=None,
|
||||
geolocation=None,
|
||||
geolocationId=None,
|
||||
):
|
||||
"""Resource data type
|
||||
|
||||
:param id: id of resource
|
||||
@@ -95,8 +113,10 @@ class Resource(cadftype.CADFAbstractType):
|
||||
setattr(self, RESOURCE_KEYNAME_ID, id or identifier.generate_uuid())
|
||||
|
||||
# Resource.typeURI
|
||||
if (getattr(self, RESOURCE_KEYNAME_ID) != "target" and
|
||||
getattr(self, RESOURCE_KEYNAME_ID) != "initiator"):
|
||||
if (
|
||||
getattr(self, RESOURCE_KEYNAME_ID) != "target"
|
||||
and getattr(self, RESOURCE_KEYNAME_ID) != "initiator"
|
||||
):
|
||||
setattr(self, RESOURCE_KEYNAME_TYPEURI, typeURI)
|
||||
|
||||
# Resource.name
|
||||
@@ -133,7 +153,7 @@ class Resource(cadftype.CADFAbstractType):
|
||||
|
||||
:param addr: CADF Endpoint to add to Resource
|
||||
"""
|
||||
if (addr is not None and isinstance(addr, endpoint.Endpoint)):
|
||||
if addr is not None and isinstance(addr, endpoint.Endpoint):
|
||||
if addr.is_valid():
|
||||
# Create the list of Endpoints if needed
|
||||
if not hasattr(self, RESOURCE_KEYNAME_ADDRS):
|
||||
@@ -152,8 +172,9 @@ class Resource(cadftype.CADFAbstractType):
|
||||
|
||||
:param attach_val: CADF Attachment to add to Resource
|
||||
"""
|
||||
if (attach_val is not None
|
||||
and isinstance(attach_val, attachment.Attachment)):
|
||||
if attach_val is not None and isinstance(
|
||||
attach_val, attachment.Attachment
|
||||
):
|
||||
if attach_val.is_valid():
|
||||
# Create the list of Attachments if needed
|
||||
if not hasattr(self, RESOURCE_KEYNAME_ATTACHMENTS):
|
||||
@@ -168,11 +189,15 @@ class Resource(cadftype.CADFAbstractType):
|
||||
|
||||
# self validate this cadf:Resource type against schema
|
||||
def is_valid(self):
|
||||
"""Validation to ensure Resource required attributes are set
|
||||
"""
|
||||
return (self._isset(RESOURCE_KEYNAME_ID) and
|
||||
(self._isset(RESOURCE_KEYNAME_TYPEURI) or
|
||||
((getattr(self, RESOURCE_KEYNAME_ID) == "target" or
|
||||
getattr(self, RESOURCE_KEYNAME_ID) == "initiator") and
|
||||
len(vars(self).keys()) == 1)))
|
||||
"""Validation to ensure Resource required attributes are set"""
|
||||
return self._isset(RESOURCE_KEYNAME_ID) and (
|
||||
self._isset(RESOURCE_KEYNAME_TYPEURI)
|
||||
or (
|
||||
(
|
||||
getattr(self, RESOURCE_KEYNAME_ID) == "target"
|
||||
or getattr(self, RESOURCE_KEYNAME_ID) == "initiator"
|
||||
)
|
||||
and len(vars(self).keys()) == 1
|
||||
)
|
||||
)
|
||||
# TODO(mrutkows): validate the Resource's attribute types
|
||||
|
||||
+1
-2
@@ -28,8 +28,7 @@ def generate_name_value_tag(name, value):
|
||||
|
||||
# TODO(mrutkows): validate any Tag's name?value= format
|
||||
def is_valid(value):
|
||||
"""Validation check to ensure proper Tag format
|
||||
"""
|
||||
"""Validation check to ensure proper Tag format"""
|
||||
if not isinstance(value, str):
|
||||
raise TypeError
|
||||
return True
|
||||
|
||||
@@ -22,18 +22,19 @@ import testtools
|
||||
|
||||
|
||||
class TestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.tempdir = self.useFixture(fixtures.TempDir())
|
||||
cfg.CONF([], project='pycadf')
|
||||
|
||||
def path_get(self, project_file=None):
|
||||
root = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
||||
'..',
|
||||
'..',
|
||||
)
|
||||
)
|
||||
root = os.path.abspath(
|
||||
os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'..',
|
||||
'..',
|
||||
)
|
||||
)
|
||||
if project_file:
|
||||
return os.path.join(root, project_file)
|
||||
else:
|
||||
|
||||
@@ -18,12 +18,15 @@ from pycadf.tests import base
|
||||
|
||||
class TestApiHelper(base.TestCase):
|
||||
def test_convert_req_action(self):
|
||||
self.assertEqual(cadftaxonomy.ACTION_READ,
|
||||
api.convert_req_action('get'))
|
||||
self.assertEqual(cadftaxonomy.ACTION_CREATE,
|
||||
api.convert_req_action('POST'))
|
||||
self.assertEqual(cadftaxonomy.ACTION_DELETE,
|
||||
api.convert_req_action('deLetE'))
|
||||
self.assertEqual(
|
||||
cadftaxonomy.ACTION_READ, api.convert_req_action('get')
|
||||
)
|
||||
self.assertEqual(
|
||||
cadftaxonomy.ACTION_CREATE, api.convert_req_action('POST')
|
||||
)
|
||||
self.assertEqual(
|
||||
cadftaxonomy.ACTION_DELETE, api.convert_req_action('deLetE')
|
||||
)
|
||||
|
||||
def test_convert_req_action_invalid(self):
|
||||
self.assertEqual(cadftaxonomy.UNKNOWN, api.convert_req_action(124))
|
||||
@@ -31,14 +34,21 @@ class TestApiHelper(base.TestCase):
|
||||
|
||||
def test_convert_req_action_with_details(self):
|
||||
detail = 'compute/instance'
|
||||
self.assertEqual(cadftaxonomy.ACTION_READ + '/%s' % detail,
|
||||
api.convert_req_action('GET', detail))
|
||||
self.assertEqual(cadftaxonomy.ACTION_DELETE + '/%s' % detail,
|
||||
api.convert_req_action('DELETE', detail))
|
||||
self.assertEqual(
|
||||
cadftaxonomy.ACTION_READ + f'/{detail}',
|
||||
api.convert_req_action('GET', detail),
|
||||
)
|
||||
self.assertEqual(
|
||||
cadftaxonomy.ACTION_DELETE + f'/{detail}',
|
||||
api.convert_req_action('DELETE', detail),
|
||||
)
|
||||
|
||||
def test_convert_req_action_with_details_invalid(self):
|
||||
detail = 123
|
||||
self.assertEqual(cadftaxonomy.ACTION_READ,
|
||||
api.convert_req_action('GET', detail))
|
||||
self.assertEqual(cadftaxonomy.ACTION_DELETE,
|
||||
api.convert_req_action('DELETE', detail))
|
||||
self.assertEqual(
|
||||
cadftaxonomy.ACTION_READ, api.convert_req_action('GET', detail)
|
||||
)
|
||||
self.assertEqual(
|
||||
cadftaxonomy.ACTION_DELETE,
|
||||
api.convert_req_action('DELETE', detail),
|
||||
)
|
||||
|
||||
+204
-146
@@ -35,7 +35,6 @@ from pycadf import timestamp
|
||||
|
||||
|
||||
class TestCADFSpec(base.TestCase):
|
||||
|
||||
@mock.patch('pycadf.identifier.warnings.warn')
|
||||
def test_identifier_generated_uuid(self, warning_mock):
|
||||
# generated uuid
|
||||
@@ -58,19 +57,28 @@ class TestCADFSpec(base.TestCase):
|
||||
def test_identifier_joined_uuids_are_valid(self, warning_mock):
|
||||
# multiple uuids joined together
|
||||
long_128_uuids = [
|
||||
('3adce28e67e44544a5a9d5f1ab54f578a86d310aac3a465e9d'
|
||||
'd2693a78b45c0e42dce28e67e44544a5a9d5f1ab54f578a86d'
|
||||
'310aac3a465e9dd2693a78b45c0e'),
|
||||
('{3adce28e67e44544a5a9d5f1ab54f578a86d310aac3a465e9d'
|
||||
'd2693a78b45c0e42dce28e67e44544a5a9d5f1ab54f578a86d'
|
||||
'310aac3a465e9dd2693a78b45c0e}'),
|
||||
('{12345678-1234-5678-1234-567812345678'
|
||||
'12345678-1234-5678-1234-567812345678'
|
||||
'12345678-1234-5678-1234-567812345678'
|
||||
'12345678-1234-5678-1234-567812345678}'),
|
||||
('urn:uuid:3adce28e67e44544a5a9d5f1ab54f578a86d310aac3a465e9d'
|
||||
'd2693a78b45c0e42dce28e67e44544a5a9d5f1ab54f578a86d'
|
||||
'310aac3a465e9dd2693a78b45c0e')]
|
||||
(
|
||||
'3adce28e67e44544a5a9d5f1ab54f578a86d310aac3a465e9d'
|
||||
'd2693a78b45c0e42dce28e67e44544a5a9d5f1ab54f578a86d'
|
||||
'310aac3a465e9dd2693a78b45c0e'
|
||||
),
|
||||
(
|
||||
'{3adce28e67e44544a5a9d5f1ab54f578a86d310aac3a465e9d'
|
||||
'd2693a78b45c0e42dce28e67e44544a5a9d5f1ab54f578a86d'
|
||||
'310aac3a465e9dd2693a78b45c0e}'
|
||||
),
|
||||
(
|
||||
'{12345678-1234-5678-1234-567812345678'
|
||||
'12345678-1234-5678-1234-567812345678'
|
||||
'12345678-1234-5678-1234-567812345678'
|
||||
'12345678-1234-5678-1234-567812345678}'
|
||||
),
|
||||
(
|
||||
'urn:uuid:3adce28e67e44544a5a9d5f1ab54f578a86d310aac3a465e9d'
|
||||
'd2693a78b45c0e42dce28e67e44544a5a9d5f1ab54f578a86d'
|
||||
'310aac3a465e9dd2693a78b45c0e'
|
||||
),
|
||||
]
|
||||
|
||||
for value in long_128_uuids:
|
||||
self.assertTrue(identifier.is_valid(value))
|
||||
@@ -97,34 +105,38 @@ class TestCADFSpec(base.TestCase):
|
||||
valid_ids = [
|
||||
'{1234567890abcdef1234567890abcdef}',
|
||||
'{12345678-1234-5678-1234-567812345678}',
|
||||
'urn:uuid:12345678-1234-5678-1234-567812345678']
|
||||
'urn:uuid:12345678-1234-5678-1234-567812345678',
|
||||
]
|
||||
|
||||
for value in valid_ids:
|
||||
self.assertTrue(identifier.is_valid(value))
|
||||
self.assertFalse(warning_mock.called)
|
||||
|
||||
def test_endpoint(self):
|
||||
endp = endpoint.Endpoint(url='http://192.168.0.1',
|
||||
name='endpoint name',
|
||||
port='8080')
|
||||
endp = endpoint.Endpoint(
|
||||
url='http://192.168.0.1', name='endpoint name', port='8080'
|
||||
)
|
||||
self.assertEqual(True, endp.is_valid())
|
||||
dict_endp = endp.as_dict()
|
||||
for key in endpoint.ENDPOINT_KEYNAMES:
|
||||
self.assertIn(key, dict_endp)
|
||||
|
||||
def test_host(self):
|
||||
h = host.Host(id=identifier.generate_uuid(),
|
||||
address='192.168.0.1',
|
||||
agent='client',
|
||||
platform='AIX')
|
||||
h = host.Host(
|
||||
id=identifier.generate_uuid(),
|
||||
address='192.168.0.1',
|
||||
agent='client',
|
||||
platform='AIX',
|
||||
)
|
||||
self.assertEqual(True, h.is_valid())
|
||||
dict_host = h.as_dict()
|
||||
for key in host.HOST_KEYNAMES:
|
||||
self.assertIn(key, dict_host)
|
||||
|
||||
def test_credential(self):
|
||||
cred = credential.Credential(type='auth token',
|
||||
token=identifier.generate_uuid())
|
||||
cred = credential.Credential(
|
||||
type='auth token', token=identifier.generate_uuid()
|
||||
)
|
||||
self.assertEqual(True, cred.is_valid())
|
||||
dict_cred = cred.as_dict()
|
||||
for key in credential.CRED_KEYNAMES:
|
||||
@@ -139,21 +151,25 @@ class TestCADFSpec(base.TestCase):
|
||||
groups=[
|
||||
identifier.generate_uuid(),
|
||||
identifier.generate_uuid(),
|
||||
identifier.generate_uuid()])
|
||||
identifier.generate_uuid(),
|
||||
],
|
||||
)
|
||||
self.assertEqual(True, cred.is_valid())
|
||||
dict_cred = cred.as_dict()
|
||||
for key in credential.FED_CRED_KEYNAMES:
|
||||
self.assertIn(key, dict_cred)
|
||||
|
||||
def test_geolocation(self):
|
||||
geo = geolocation.Geolocation(id=identifier.generate_uuid(),
|
||||
latitude='43.6481 N',
|
||||
longitude='79.4042 W',
|
||||
elevation='0',
|
||||
accuracy='1',
|
||||
city='toronto',
|
||||
state='ontario',
|
||||
regionICANN='ca')
|
||||
geo = geolocation.Geolocation(
|
||||
id=identifier.generate_uuid(),
|
||||
latitude='43.6481 N',
|
||||
longitude='79.4042 W',
|
||||
elevation='0',
|
||||
accuracy='1',
|
||||
city='toronto',
|
||||
state='ontario',
|
||||
regionICANN='ca',
|
||||
)
|
||||
self.assertEqual(True, geo.is_valid())
|
||||
|
||||
dict_geo = geo.as_dict()
|
||||
@@ -161,9 +177,9 @@ class TestCADFSpec(base.TestCase):
|
||||
self.assertIn(key, dict_geo)
|
||||
|
||||
def test_metric(self):
|
||||
metric_val = metric.Metric(metricId=identifier.generate_uuid(),
|
||||
unit='b',
|
||||
name='bytes')
|
||||
metric_val = metric.Metric(
|
||||
metricId=identifier.generate_uuid(), unit='b', name='bytes'
|
||||
)
|
||||
self.assertEqual(True, metric_val.is_valid())
|
||||
|
||||
dict_metric_val = metric_val.as_dict()
|
||||
@@ -175,7 +191,8 @@ class TestCADFSpec(base.TestCase):
|
||||
result='100',
|
||||
metric=metric.Metric(),
|
||||
metricId=identifier.generate_uuid(),
|
||||
calculatedBy=resource.Resource(typeURI='storage'))
|
||||
calculatedBy=resource.Resource(typeURI='storage'),
|
||||
)
|
||||
self.assertEqual(False, measure_val.is_valid())
|
||||
|
||||
dict_measure_val = measure_val.as_dict()
|
||||
@@ -185,20 +202,24 @@ class TestCADFSpec(base.TestCase):
|
||||
measure_val = measurement.Measurement(
|
||||
result='100',
|
||||
metric=metric.Metric(),
|
||||
calculatedBy=resource.Resource(typeURI='storage'))
|
||||
calculatedBy=resource.Resource(typeURI='storage'),
|
||||
)
|
||||
self.assertEqual(True, measure_val.is_valid())
|
||||
|
||||
measure_val = measurement.Measurement(
|
||||
result='100',
|
||||
metricId=identifier.generate_uuid(),
|
||||
calculatedBy=resource.Resource(typeURI='storage'))
|
||||
calculatedBy=resource.Resource(typeURI='storage'),
|
||||
)
|
||||
self.assertEqual(True, measure_val.is_valid())
|
||||
|
||||
def test_reason(self):
|
||||
reason_val = reason.Reason(reasonType='HTTP',
|
||||
reasonCode='200',
|
||||
policyType='poltype',
|
||||
policyId=identifier.generate_uuid())
|
||||
reason_val = reason.Reason(
|
||||
reasonType='HTTP',
|
||||
reasonCode='200',
|
||||
policyType='poltype',
|
||||
policyId=identifier.generate_uuid(),
|
||||
)
|
||||
self.assertEqual(True, reason_val.is_valid())
|
||||
|
||||
dict_reason_val = reason_val.as_dict()
|
||||
@@ -210,7 +231,8 @@ class TestCADFSpec(base.TestCase):
|
||||
role='modifier',
|
||||
reporter=resource.Resource(typeURI='storage'),
|
||||
reporterId=identifier.generate_uuid(),
|
||||
reporterTime=timestamp.get_utc_now())
|
||||
reporterTime=timestamp.get_utc_now(),
|
||||
)
|
||||
self.assertEqual(False, step.is_valid())
|
||||
|
||||
dict_step = step.as_dict()
|
||||
@@ -220,19 +242,21 @@ class TestCADFSpec(base.TestCase):
|
||||
step = reporterstep.Reporterstep(
|
||||
role='modifier',
|
||||
reporter=resource.Resource(typeURI='storage'),
|
||||
reporterTime=timestamp.get_utc_now())
|
||||
reporterTime=timestamp.get_utc_now(),
|
||||
)
|
||||
self.assertEqual(True, step.is_valid())
|
||||
|
||||
step = reporterstep.Reporterstep(
|
||||
role='modifier',
|
||||
reporterId=identifier.generate_uuid(),
|
||||
reporterTime=timestamp.get_utc_now())
|
||||
reporterTime=timestamp.get_utc_now(),
|
||||
)
|
||||
self.assertEqual(True, step.is_valid())
|
||||
|
||||
def test_attachment(self):
|
||||
attach = attachment.Attachment(typeURI='attachURI',
|
||||
content='content',
|
||||
name='attachment_name')
|
||||
attach = attachment.Attachment(
|
||||
typeURI='attachURI', content='content', name='attachment_name'
|
||||
)
|
||||
self.assertEqual(True, attach.is_valid())
|
||||
|
||||
dict_attach = attach.as_dict()
|
||||
@@ -240,19 +264,22 @@ class TestCADFSpec(base.TestCase):
|
||||
self.assertIn(key, dict_attach)
|
||||
|
||||
def test_resource(self):
|
||||
res = resource.Resource(typeURI='storage',
|
||||
name='res_name',
|
||||
domain='res_domain',
|
||||
ref='res_ref',
|
||||
credential=credential.Credential(
|
||||
token=identifier.generate_uuid()),
|
||||
host=host.Host(address='192.168.0.1'),
|
||||
geolocation=geolocation.Geolocation(),
|
||||
geolocationId=identifier.generate_uuid())
|
||||
res = resource.Resource(
|
||||
typeURI='storage',
|
||||
name='res_name',
|
||||
domain='res_domain',
|
||||
ref='res_ref',
|
||||
credential=credential.Credential(token=identifier.generate_uuid()),
|
||||
host=host.Host(address='192.168.0.1'),
|
||||
geolocation=geolocation.Geolocation(),
|
||||
geolocationId=identifier.generate_uuid(),
|
||||
)
|
||||
|
||||
res.add_attachment(attachment.Attachment(typeURI='attachURI',
|
||||
content='content',
|
||||
name='attachment_name'))
|
||||
res.add_attachment(
|
||||
attachment.Attachment(
|
||||
typeURI='attachURI', content='content', name='attachment_name'
|
||||
)
|
||||
)
|
||||
res.add_address(endpoint.Endpoint(url='http://192.168.0.1'))
|
||||
|
||||
self.assertEqual(True, res.is_valid())
|
||||
@@ -264,110 +291,139 @@ class TestCADFSpec(base.TestCase):
|
||||
res = resource.Resource(id='target')
|
||||
self.assertEqual(True, res.is_valid())
|
||||
|
||||
res.add_attachment(attachment.Attachment(typeURI='attachURI',
|
||||
content='content',
|
||||
name='attachment_name'))
|
||||
res.add_attachment(
|
||||
attachment.Attachment(
|
||||
typeURI='attachURI', content='content', name='attachment_name'
|
||||
)
|
||||
)
|
||||
self.assertEqual(False, res.is_valid())
|
||||
|
||||
def test_event(self):
|
||||
ev = event.Event(eventType='activity',
|
||||
id=identifier.generate_uuid(),
|
||||
eventTime=timestamp.get_utc_now(),
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
initiatorId=identifier.generate_uuid(),
|
||||
action='read',
|
||||
target=resource.Resource(typeURI='storage'),
|
||||
targetId=identifier.generate_uuid(),
|
||||
observer=resource.Resource(id='target'),
|
||||
observerId=identifier.generate_uuid(),
|
||||
outcome='success',
|
||||
reason=reason.Reason(reasonType='HTTP',
|
||||
reasonCode='200'),
|
||||
severity='high',
|
||||
name='descriptive name')
|
||||
ev.add_measurement(
|
||||
measurement.Measurement(result='100',
|
||||
metricId=identifier.generate_uuid())),
|
||||
ev = event.Event(
|
||||
eventType='activity',
|
||||
id=identifier.generate_uuid(),
|
||||
eventTime=timestamp.get_utc_now(),
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
initiatorId=identifier.generate_uuid(),
|
||||
action='read',
|
||||
target=resource.Resource(typeURI='storage'),
|
||||
targetId=identifier.generate_uuid(),
|
||||
observer=resource.Resource(id='target'),
|
||||
observerId=identifier.generate_uuid(),
|
||||
outcome='success',
|
||||
reason=reason.Reason(reasonType='HTTP', reasonCode='200'),
|
||||
severity='high',
|
||||
name='descriptive name',
|
||||
)
|
||||
(
|
||||
ev.add_measurement(
|
||||
measurement.Measurement(
|
||||
result='100', metricId=identifier.generate_uuid()
|
||||
)
|
||||
),
|
||||
)
|
||||
ev.add_tag(tag.generate_name_value_tag('name', 'val'))
|
||||
ev.add_attachment(attachment.Attachment(typeURI='attachURI',
|
||||
content='content',
|
||||
name='attachment_name'))
|
||||
ev.add_attachment(
|
||||
attachment.Attachment(
|
||||
typeURI='attachURI', content='content', name='attachment_name'
|
||||
)
|
||||
)
|
||||
ev.observer = resource.Resource(typeURI='service/security')
|
||||
ev.add_reporterstep(reporterstep.Reporterstep(
|
||||
role='observer',
|
||||
reporter=resource.Resource(typeURI='service/security')))
|
||||
ev.add_reporterstep(reporterstep.Reporterstep(
|
||||
reporterId=identifier.generate_uuid()))
|
||||
ev.add_reporterstep(
|
||||
reporterstep.Reporterstep(
|
||||
role='observer',
|
||||
reporter=resource.Resource(typeURI='service/security'),
|
||||
)
|
||||
)
|
||||
ev.add_reporterstep(
|
||||
reporterstep.Reporterstep(reporterId=identifier.generate_uuid())
|
||||
)
|
||||
self.assertEqual(False, ev.is_valid())
|
||||
|
||||
dict_ev = ev.as_dict()
|
||||
for key in event.EVENT_KEYNAMES:
|
||||
self.assertIn(key, dict_ev)
|
||||
|
||||
ev = event.Event(eventType='activity',
|
||||
id=identifier.generate_uuid(),
|
||||
eventTime=timestamp.get_utc_now(),
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
action='read',
|
||||
target=resource.Resource(typeURI='storage'),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success')
|
||||
ev = event.Event(
|
||||
eventType='activity',
|
||||
id=identifier.generate_uuid(),
|
||||
eventTime=timestamp.get_utc_now(),
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
action='read',
|
||||
target=resource.Resource(typeURI='storage'),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success',
|
||||
)
|
||||
self.assertEqual(True, ev.is_valid())
|
||||
|
||||
ev = event.Event(eventType='activity',
|
||||
id=identifier.generate_uuid(),
|
||||
eventTime=timestamp.get_utc_now(),
|
||||
initiatorId=identifier.generate_uuid(),
|
||||
action='read',
|
||||
targetId=identifier.generate_uuid(),
|
||||
observerId=identifier.generate_uuid(),
|
||||
outcome='success')
|
||||
ev = event.Event(
|
||||
eventType='activity',
|
||||
id=identifier.generate_uuid(),
|
||||
eventTime=timestamp.get_utc_now(),
|
||||
initiatorId=identifier.generate_uuid(),
|
||||
action='read',
|
||||
targetId=identifier.generate_uuid(),
|
||||
observerId=identifier.generate_uuid(),
|
||||
outcome='success',
|
||||
)
|
||||
self.assertEqual(True, ev.is_valid())
|
||||
|
||||
ev = event.Event(eventType='activity',
|
||||
id=identifier.generate_uuid(),
|
||||
eventTime=timestamp.get_utc_now(),
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
action='read',
|
||||
targetId=identifier.generate_uuid(),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success')
|
||||
ev = event.Event(
|
||||
eventType='activity',
|
||||
id=identifier.generate_uuid(),
|
||||
eventTime=timestamp.get_utc_now(),
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
action='read',
|
||||
targetId=identifier.generate_uuid(),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success',
|
||||
)
|
||||
self.assertEqual(True, ev.is_valid())
|
||||
|
||||
def test_event_unique(self):
|
||||
ev = event.Event(eventType='activity',
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
action='read',
|
||||
target=resource.Resource(typeURI='storage'),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success')
|
||||
ev = event.Event(
|
||||
eventType='activity',
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
action='read',
|
||||
target=resource.Resource(typeURI='storage'),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success',
|
||||
)
|
||||
time.sleep(1)
|
||||
ev2 = event.Event(eventType='activity',
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
action='read',
|
||||
target=resource.Resource(typeURI='storage'),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success')
|
||||
ev2 = event.Event(
|
||||
eventType='activity',
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
action='read',
|
||||
target=resource.Resource(typeURI='storage'),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success',
|
||||
)
|
||||
self.assertNotEqual(ev.id, ev2.id)
|
||||
self.assertNotEqual(ev.eventTime, ev2.eventTime)
|
||||
|
||||
def test_event_resource_shortform_not_self(self):
|
||||
self.assertRaises(ValueError,
|
||||
lambda: event.Event(
|
||||
eventType='activity',
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
action='read',
|
||||
target=resource.Resource(id='target'),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success'))
|
||||
self.assertRaises(ValueError,
|
||||
lambda: event.Event(
|
||||
eventType='activity',
|
||||
initiator=resource.Resource(id='initiator'),
|
||||
action='read',
|
||||
target=resource.Resource(typeURI='storage'),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success'))
|
||||
self.assertRaises(
|
||||
ValueError,
|
||||
lambda: event.Event(
|
||||
eventType='activity',
|
||||
initiator=resource.Resource(typeURI='storage'),
|
||||
action='read',
|
||||
target=resource.Resource(id='target'),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success',
|
||||
),
|
||||
)
|
||||
self.assertRaises(
|
||||
ValueError,
|
||||
lambda: event.Event(
|
||||
eventType='activity',
|
||||
initiator=resource.Resource(id='initiator'),
|
||||
action='read',
|
||||
target=resource.Resource(typeURI='storage'),
|
||||
observer=resource.Resource(id='target'),
|
||||
outcome='success',
|
||||
),
|
||||
)
|
||||
|
||||
def _create_none_validator_descriptor(self):
|
||||
class Owner:
|
||||
@@ -384,8 +440,10 @@ class TestCADFSpec(base.TestCase):
|
||||
def test_cadfabstracttype_attribute_error(self):
|
||||
"""Test an invalid CADFAbstractType attribute is set returns False"""
|
||||
|
||||
h = host.Host(id=identifier.generate_uuid(),
|
||||
address='192.168.0.1',
|
||||
agent='client',
|
||||
platform='AIX')
|
||||
h = host.Host(
|
||||
id=identifier.generate_uuid(),
|
||||
address='192.168.0.1',
|
||||
agent='client',
|
||||
platform='AIX',
|
||||
)
|
||||
self.assertEqual(False, h._isset(uuid.uuid4().hex))
|
||||
|
||||
@@ -25,9 +25,9 @@ class TestUtils(base.TestCase):
|
||||
obfuscate = utils.mask_value(value, m_percent)
|
||||
visible = int(round(len(value) * m_percent))
|
||||
self.assertEqual(value[:visible], obfuscate[:visible])
|
||||
self.assertNotEqual(value[:visible + 1], obfuscate[:visible + 1])
|
||||
self.assertNotEqual(value[: visible + 1], obfuscate[: visible + 1])
|
||||
self.assertEqual(value[-visible:], obfuscate[-visible:])
|
||||
self.assertNotEqual(value[-visible - 1:], obfuscate[-visible - 1:])
|
||||
self.assertNotEqual(value[-visible - 1 :], obfuscate[-visible - 1 :])
|
||||
|
||||
def test_mask_value_nonstring(self):
|
||||
value = 12
|
||||
|
||||
+1
-2
@@ -36,8 +36,7 @@ def get_utc_now(timezone=None):
|
||||
# TODO(mrutkows): validate any cadf:Timestamp (type) record against
|
||||
# CADF schema
|
||||
def is_valid(value):
|
||||
"""Validation to ensure timestamp is a string.
|
||||
"""
|
||||
"""Validation to ensure timestamp is a string."""
|
||||
if not isinstance(value, str):
|
||||
raise ValueError('Timestamp should be a String')
|
||||
|
||||
|
||||
+5
-2
@@ -20,7 +20,10 @@ def mask_value(value, s_percent=0.125):
|
||||
:param s_percent: The percentage (in decimal) of characters to replace
|
||||
"""
|
||||
if isinstance(value, str):
|
||||
visible = (32 if int(round(len(value) * s_percent)) > 32
|
||||
else int(round(len(value) * s_percent)))
|
||||
visible = (
|
||||
32
|
||||
if int(round(len(value) * s_percent)) > 32
|
||||
else int(round(len(value) * s_percent))
|
||||
)
|
||||
return value[:visible] + " xxxxxxxx " + value[-visible:]
|
||||
return value
|
||||
|
||||
@@ -47,3 +47,20 @@ packages = [
|
||||
"etc/pycadf/trove_api_audit_map.conf",
|
||||
"etc/pycadf/swift_api_audit_map.conf",
|
||||
]
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 79
|
||||
|
||||
[tool.ruff.format]
|
||||
quote-style = "preserve"
|
||||
docstring-code-format = true
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = ["E4", "E7", "E9", "F", "S", "U"]
|
||||
ignore = [
|
||||
# we only use asserts for type narrowing
|
||||
"S101",
|
||||
]
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"pycadf/tests/*" = ["S"]
|
||||
|
||||
@@ -13,17 +13,9 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
|
||||
import setuptools
|
||||
|
||||
# In python < 2.7.4, a lazy loading of package `pbr` will break
|
||||
# setuptools if some other modules registered functions in `atexit`.
|
||||
# solution from: http://bugs.python.org/issue15881#msg170215
|
||||
try:
|
||||
import multiprocessing # noqa
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['pbr>=2.0.0'],
|
||||
pbr=True)
|
||||
pbr=True,
|
||||
)
|
||||
|
||||
@@ -43,28 +43,8 @@ commands = {posargs}
|
||||
commands = oslo_debug_helper {posargs}
|
||||
|
||||
[flake8]
|
||||
show-source = True
|
||||
# H405: Multi line docstrings should start with a one line summary followed by
|
||||
# an empty line.
|
||||
# D100: Missing docstring in public module
|
||||
# D101: Missing docstring in public class
|
||||
# D102: Missing docstring in public method
|
||||
# D103: Missing docstring in public function
|
||||
# D104: Missing docstring in public package
|
||||
# D105: Missing docstring in magic method
|
||||
# D107: Missing docstring in __init__
|
||||
# D200: One-line docstring should fit on one line with quotes
|
||||
# D202: No blank lines allowed after function docstring
|
||||
# D203: 1 blank required before class docstring
|
||||
# D204: 1 blank line required after class docstring
|
||||
# D205: 1 blank line required between summary line and description
|
||||
# D208: Docstring is over-indented
|
||||
# D400: First line should end with a period
|
||||
# D401: First line should be in imperative mood
|
||||
# I100: Import statements are in the wrong order.
|
||||
# I201: Missing newline between import groups.
|
||||
# I202: Additional newline in a group of imports.
|
||||
# W503: line break before binary operator
|
||||
# W504: line break after binary operator
|
||||
ignore = H405,D100,D101,D102,D103,D104,D105,D107,D200,D202,D203,D204,D205,D208,D400,D401,I100,I201,I202,W503,W504
|
||||
# We only enable the hacking (H) checks
|
||||
select = H
|
||||
ignore = H301,H403,H404,H405
|
||||
show-source = true
|
||||
exclude = .tox,dist,doc,*.egg,build
|
||||
|
||||
Reference in New Issue
Block a user