Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions rest-service/manager_rest/rest/endpoint_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def setup_resources(api):
}

# Set version endpoint as a non versioned endpoint
api.add_resource(resources_v1.Version, '/api/version', endpoint='version')
# api.add_resource(
# resources_v1.Version, '/api/version', endpoint='version')
for resource, endpoint_suffix in resources_endpoints.items():
if isinstance(endpoint_suffix, str):
_set_versioned_urls(api, resource, endpoint_suffix)
Expand All @@ -174,10 +175,11 @@ def _set_versioned_urls(api, resource_name, endpoint_suffix):
for version in SUPPORTED_API_VERSIONS:
version_name, resources_impl = version
if hasattr(resources_impl, resource_name):
resource = getattr(resources_impl, resource_name)
resource = getattr(resources_impl, resource_name).as_view(
f'{version_name}/{endpoint_suffix}')
# 'resource' will persist throughout iterations, holding a reference
# to the latest impl.
if resource:
endpoint = '{0}/{1}'.format(version_name, endpoint_suffix)
url = '/api/{0}'.format(endpoint)
api.add_resource(resource, url, endpoint=endpoint)
api.add_url_rule(url, view_func=resource)
Empty file.
2 changes: 1 addition & 1 deletion rest-service/manager_rest/rest/resources_v1/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,4 @@ def delete(self, blueprint_id, **kwargs):
# However, there is no handling of possible concurrency issue with
# regard to that matter at the moment.
get_resource_manager().delete_blueprint(blueprint_id, force=False)
return None, 204
return "", 204
79 changes: 40 additions & 39 deletions rest-service/manager_rest/rest/resources_v1/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
# * limitations under the License.
#

from flask_restful.reqparse import Argument
from flask_restful.inputs import boolean
import pydantic
from typing import Optional, Dict, Any

from flask import request

from cloudify.models_states import DeploymentState

Expand All @@ -30,13 +32,10 @@
from manager_rest.resource_manager import (ResourceManager,
get_resource_manager)
from manager_rest.rest.rest_decorators import marshal_with
from manager_rest.rest.rest_utils import (get_args_and_verify_arguments,
get_json_and_verify_params,
validate_inputs)
from manager_rest.rest.rest_utils import validate_inputs


class Deployments(SecuredResource):

@swagger.operation(
responseClass='List[{0}]'.format(models.Deployment.__name__),
nickname="list",
Expand All @@ -52,6 +51,20 @@ def get(self, _include=None, **kwargs):
models.Deployment, include=_include).items


class _DeploymentCreateArgs(pydantic.BaseModel):
blueprint_id: str
inputs: Optional[Dict[str, Any]] = {}


class _DeploymentDeleteQuery(pydantic.BaseModel):
force: Optional[bool] = False
delete_logs: Optional[bool] = False


class _PrivateResourceArgs(pydantic.BaseModel):
private_resource: Optional[bool] = False


class DeploymentsId(SecuredResource):
@swagger.operation(
responseClass=models.Deployment,
Expand Down Expand Up @@ -86,14 +99,10 @@ def put(self, deployment_id, **kwargs):
Create a deployment
"""
validate_inputs({'deployment_id': deployment_id})
request_schema = self.create_request_schema()
request_dict = get_json_and_verify_params(request_schema)
request_dict = _DeploymentCreateArgs.parse_obj(request.json).dict()
blueprint_id = request_dict['blueprint_id']
bypass_maintenance = is_bypass_maintenance_mode()
args = get_args_and_verify_arguments(
[Argument('private_resource', type=boolean,
default=False)]
)
args = _PrivateResourceArgs.parse_obj(request.args)
skip_plugins_validation = self.get_skip_plugin_validation_flag(
request_dict)
rm = get_resource_manager()
Expand All @@ -119,13 +128,6 @@ def put(self, deployment_id, **kwargs):
raise
return deployment, 201

def create_request_schema(self):
request_schema = {
'blueprint_id': {},
'inputs': {'optional': True, 'type': dict}
}
return request_schema

def get_skip_plugin_validation_flag(self, request_dict):
return True

Expand All @@ -146,11 +148,7 @@ def get_skip_plugin_validation_flag(self, request_dict):
@authorize('deployment_delete')
def delete(self, deployment_id, **kwargs):
"""Delete deployment by id"""
args = get_args_and_verify_arguments([
Argument('force', type=boolean, default=False),
Argument('delete_logs', type=boolean, default=False)
])

args = _DeploymentDeleteQuery.parse_obj(request.args)
bypass_maintenance = is_bypass_maintenance_mode()
sm = get_storage_manager()
dep = sm.get(models.Deployment, deployment_id)
Expand All @@ -166,11 +164,20 @@ def delete(self, deployment_id, **kwargs):
[delete_execution], bypass_maintenance=bypass_maintenance)
workflow_executor.execute_workflow(messages)
workflow_executor.delete_source_plugins(dep.id)
return None, 204
return "", 204


class DeploymentModifications(SecuredResource):
class _DeploymentModificationArgs(pydantic.BaseModel):
deployment_id: str
context: Optional[Dict[str, Any]] = {}
nodes: Optional[Dict[str, Any]] = {}


class _DeploymentIDArgs(pydantic.BaseModel):
deployment_id: Optional[str] = None


class DeploymentModifications(SecuredResource):
@swagger.operation(
responseClass=models.DeploymentModification,
nickname="modifyDeployment",
Expand All @@ -189,16 +196,12 @@ class DeploymentModifications(SecuredResource):
@authorize('deployment_modify')
@marshal_with(models.DeploymentModification)
def post(self, **kwargs):
request_dict = get_json_and_verify_params({
'deployment_id': {},
'context': {'optional': True, 'type': dict},
'nodes': {'optional': True, 'type': dict}
})
deployment_id = request_dict['deployment_id']
context = request_dict.get('context', {})
nodes = request_dict.get('nodes', {})
modification = get_resource_manager(). \
start_deployment_modification(deployment_id, nodes, context)
args = _DeploymentModificationArgs.parse_obj(request.json)
modification = get_resource_manager().start_deployment_modification(
args.deployment_id,
args.nodes,
args.context,
)
return modification, 201

@swagger.operation(
Expand All @@ -216,9 +219,7 @@ def post(self, **kwargs):
@authorize('deployment_modification_list')
@marshal_with(models.DeploymentModification)
def get(self, _include=None, **kwargs):
args = get_args_and_verify_arguments(
[Argument('deployment_id', required=False)]
)
args = _DeploymentIDArgs.parse_obj(request.args)
deployment_id_filter = ResourceManager.create_filters_dict(
deployment_id=args.deployment_id)
return get_storage_manager().list(
Expand Down
38 changes: 20 additions & 18 deletions rest-service/manager_rest/rest/resources_v1/evaluate_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@
# * See the License for the specific language governing permissions and
# * limitations under the License.

import pydantic
from flask import request
from typing import Any, Dict, Optional

from manager_rest.rest import requests_schema, responses, swagger
from manager_rest.rest.rest_decorators import marshal_with
from manager_rest.security import SecuredResource
from manager_rest.security.authorization import authorize
from manager_rest.dsl_functions import evaluate_intrinsic_functions
from manager_rest.rest.rest_utils import get_json_and_verify_params


class EvaluateFunctions(SecuredResource):
class _EvaluateFunctionsArgs(pydantic.BaseModel):
deployment_id: str
context: Optional[Dict[str, Any]] = {}
payload: Dict[str, Any]


class EvaluateFunctions(SecuredResource):
@swagger.operation(
responseClass=responses.EvaluatedFunctions,
nickname='evaluateFunctions',
Expand All @@ -41,20 +49,14 @@ class EvaluateFunctions(SecuredResource):
@authorize('functions_evaluate')
@marshal_with(responses.EvaluatedFunctions)
def post(self, **kwargs):
"""
Evaluate intrinsic in payload
"""
request_dict = get_json_and_verify_params({
'deployment_id': {},
'context': {'optional': True, 'type': dict},
'payload': {'type': dict}
})

deployment_id = request_dict['deployment_id']
context = request_dict.get('context', {})
payload = request_dict.get('payload')
"""Evaluate intrinsic in payload"""
args = _EvaluateFunctionsArgs.parse_obj(request.json)
processed_payload = evaluate_intrinsic_functions(
deployment_id=deployment_id,
context=context,
payload=payload)
return dict(deployment_id=deployment_id, payload=processed_payload)
deployment_id=args.deployment_id,
context=args.context,
payload=args.payload,
)
return dict(
deployment_id=args.deployment_id,
payload=processed_payload,
)
Loading