# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 # # Permission is hereby granted, free of charge, to any person obtaining a copy of this # software and associated documentation files (the "Software"), to deal in the Software # without restriction, including without limitation the rights to use, copy, modify, # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import logging from typing import Any, MutableMapping, Optional from cloudformation_cli_python_lib import ( Action, ProgressEvent, Resource, SessionProxy, exceptions, ) from cloudformation_cli_python_lib.interface import OperationStatus from .create_handler import _create_handler from .delete_handler import _delete_handler from .models import ResourceHandlerRequest, ResourceModel from .read_handler import _read_handler # Use this logger to forward log messages to CloudWatch Logs. LOG = logging.getLogger(__name__) TYPE_NAME = "ProServe::Organizations::PolicyAttachment" resource = Resource(TYPE_NAME, ResourceModel) test_entrypoint = resource.test_entrypoint @resource.handler(Action.CREATE) def create_handler( session: Optional[SessionProxy], request: ResourceHandlerRequest, callback_context: MutableMapping[str, Any], ) -> ProgressEvent: model = request.desiredResourceState if isinstance(session, SessionProxy): progress = _create_handler(session, model, callback_context, LOG) else: LOG.error("No session available") raise exceptions.InternalFailure("No session available") return read_handler(session, request, callback_context) @resource.handler(Action.DELETE) def delete_handler( session: Optional[SessionProxy], request: ResourceHandlerRequest, callback_context: MutableMapping[str, Any], ) -> ProgressEvent: model = request.desiredResourceState if isinstance(session, SessionProxy): progress = _delete_handler(session, model, callback_context, LOG) else: LOG.error("No session available") raise exceptions.InternalFailure("No session available") return progress @resource.handler(Action.READ) def read_handler( session: Optional[SessionProxy], request: ResourceHandlerRequest, callback_context: MutableMapping[str, Any], ) -> ProgressEvent: model = request.desiredResourceState if isinstance(session, SessionProxy): progress = _read_handler(session, model, callback_context, LOG) else: LOG.error("No session available") raise exceptions.InternalFailure("No session available") return progress @resource.handler(Action.UPDATE) def update_handler( session: Optional[SessionProxy], request: ResourceHandlerRequest, callback_context: MutableMapping[str, Any], ) -> ProgressEvent: progress: ProgressEvent = ProgressEvent( resourceModel=request.desiredResourceState, status=OperationStatus.SUCCESS ) return progress