Add a representation of the ActionContext in mistral-lib
This allows us to better define the expected interface and provide
additional context information to actions.
The existing context is deprecated with this change and will output
deprecation warnings for the old property names.
Change-Id: Ib879ba58d4b9a04d4f5ea668ae94d79a82758919
Partial-Bug: #1718353
(cherry picked from commit db09c50dbe
)
This commit is contained in:
parent
d8483fa6cb
commit
9c2d6d922a
|
@ -0,0 +1,85 @@
|
|||
# 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.
|
||||
|
||||
import warnings
|
||||
|
||||
|
||||
class ActionContext(object):
|
||||
|
||||
def __init__(self, security_ctx=None, execution_ctx=None):
|
||||
self.security = security_ctx
|
||||
self.execution = execution_ctx
|
||||
|
||||
def _deprecation_warning(self, name):
|
||||
warnings.warn(
|
||||
"context.{0} is deprecated from the context passed to actions. "
|
||||
"Please use context.security.{0}. It will be removed in a future "
|
||||
"release.", DeprecationWarning
|
||||
)
|
||||
|
||||
@property
|
||||
def auth_uri(self):
|
||||
self._deprecation_warning("auth_uri")
|
||||
return self.security.auth_uri
|
||||
|
||||
@property
|
||||
def user_name(self):
|
||||
self._deprecation_warning("user_name")
|
||||
return self.security.user_name
|
||||
|
||||
@property
|
||||
def auth_token(self):
|
||||
self._deprecation_warning("auth_token")
|
||||
return self.security.auth_token
|
||||
|
||||
@property
|
||||
def project_name(self):
|
||||
self._deprecation_warning("project_name")
|
||||
return self.security.project_name
|
||||
|
||||
@property
|
||||
def project_id(self):
|
||||
self._deprecation_warning("project_id")
|
||||
return self.security.project_id
|
||||
|
||||
@property
|
||||
def insecure(self):
|
||||
self._deprecation_warning("insecure")
|
||||
return self.security.insecure
|
||||
|
||||
|
||||
class SecurityContext(object):
|
||||
def __init__(self, auth_uri=None, auth_cacert=None, insecure=None,
|
||||
service_catalog=None, region_name=None, is_trust_scoped=None,
|
||||
redelivered=None, expires_at=None, trust_id=None,
|
||||
is_target=None):
|
||||
self.auth_uri = auth_uri
|
||||
self.auth_cacert = auth_cacert
|
||||
self.insecure = insecure
|
||||
self.service_catalog = service_catalog
|
||||
self.region_name = region_name
|
||||
self.is_trust_scoped = is_trust_scoped
|
||||
self.redelivered = redelivered
|
||||
self.expires_at = expires_at
|
||||
self.trust_id = trust_id
|
||||
self.is_target = is_target
|
||||
|
||||
|
||||
class ExecutionContext(object):
|
||||
def __init__(self, workflow_execution_id=None, task_id=None,
|
||||
action_execution_id=None, workflow_name=None,
|
||||
callback_url=None):
|
||||
self.workflow_execution_id = workflow_execution_id
|
||||
self.task_id = task_id
|
||||
self.action_execution_id = action_execution_id
|
||||
self.workflow_name = workflow_name
|
||||
self.callback_url = callback_url
|
Loading…
Reference in New Issue