|
| 1 | +# Copyright 2022 The StackStorm Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +import abc |
| 17 | + |
| 18 | +DEFAULT_PACK_NAME = "default" |
| 19 | + |
| 20 | + |
| 21 | +NotificationSubSchemaAPI = { |
| 22 | + "type": "object", |
| 23 | + "properties": { |
| 24 | + "message": {"type": "string", "description": "Message to use for notification"}, |
| 25 | + "data": { |
| 26 | + "type": "object", |
| 27 | + "description": "Data to be sent as part of notification", |
| 28 | + }, |
| 29 | + "routes": { |
| 30 | + "type": "array", |
| 31 | + "description": "Channels to post notifications to.", |
| 32 | + }, |
| 33 | + "channels": { # Deprecated. Only here for backward compatibility. |
| 34 | + "type": "array", |
| 35 | + "description": "Channels to post notifications to.", |
| 36 | + }, |
| 37 | + }, |
| 38 | + "additionalProperties": False, |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +def get_schema(**kwargs): |
| 43 | + return {} |
| 44 | + |
| 45 | + |
| 46 | +# copied from st2common.models.api.base |
| 47 | +class BaseAPI(abc.ABC): |
| 48 | + schema = abc.abstractproperty |
| 49 | + name = None |
| 50 | + |
| 51 | + |
| 52 | +# copied from st2common.models.api.action |
| 53 | +class ActionAPI(BaseAPI): |
| 54 | + """ |
| 55 | + The system entity that represents a Stack Action/Automation in the system. |
| 56 | + """ |
| 57 | + |
| 58 | + schema = { |
| 59 | + "title": "Action", |
| 60 | + "description": "An activity that happens as a response to the external event.", |
| 61 | + "type": "object", |
| 62 | + "properties": { |
| 63 | + "id": { |
| 64 | + "description": "The unique identifier for the action.", |
| 65 | + "type": "string", |
| 66 | + }, |
| 67 | + "ref": { |
| 68 | + "description": "System computed user friendly reference for the action. \ |
| 69 | + Provided value will be overridden by computed value.", |
| 70 | + "type": "string", |
| 71 | + }, |
| 72 | + "uid": {"type": "string"}, |
| 73 | + "name": { # used in test |
| 74 | + "description": "The name of the action.", |
| 75 | + "type": "string", |
| 76 | + "required": True, |
| 77 | + }, |
| 78 | + "description": { # used in test |
| 79 | + "description": "The description of the action.", |
| 80 | + "type": "string", |
| 81 | + }, |
| 82 | + "enabled": { |
| 83 | + "description": "Enable or disable the action from invocation.", |
| 84 | + "type": "boolean", |
| 85 | + "default": True, |
| 86 | + }, |
| 87 | + "runner_type": { # used in test |
| 88 | + "description": "The type of runner that executes the action.", |
| 89 | + "type": "string", |
| 90 | + "required": True, |
| 91 | + }, |
| 92 | + "entry_point": { |
| 93 | + "description": "The entry point for the action.", |
| 94 | + "type": "string", |
| 95 | + "default": "", |
| 96 | + }, |
| 97 | + "pack": { |
| 98 | + "description": "The content pack this action belongs to.", |
| 99 | + "type": "string", |
| 100 | + "default": DEFAULT_PACK_NAME, |
| 101 | + }, |
| 102 | + "parameters": { |
| 103 | + "description": "Input parameters for the action.", |
| 104 | + "type": "object", |
| 105 | + "patternProperties": {r"^\w+$": get_schema()}, |
| 106 | + "additionalProperties": False, |
| 107 | + "default": {}, |
| 108 | + }, |
| 109 | + "output_schema": get_schema(description="Action Output Schema"), |
| 110 | + "tags": { |
| 111 | + "description": "User associated metadata assigned to this object.", |
| 112 | + "type": "array", |
| 113 | + "items": {"type": "object"}, |
| 114 | + }, |
| 115 | + "notify": { |
| 116 | + "description": "Notification settings for action.", |
| 117 | + "type": "object", |
| 118 | + "properties": { |
| 119 | + "on-complete": NotificationSubSchemaAPI, |
| 120 | + "on-failure": NotificationSubSchemaAPI, |
| 121 | + "on-success": NotificationSubSchemaAPI, |
| 122 | + }, |
| 123 | + "additionalProperties": False, |
| 124 | + }, |
| 125 | + "metadata_file": { |
| 126 | + "description": "Path to the metadata file relative to the pack directory.", |
| 127 | + "type": "string", |
| 128 | + "default": "", |
| 129 | + }, |
| 130 | + }, |
| 131 | + "additionalProperties": False, |
| 132 | + } |
| 133 | + |
| 134 | + |
| 135 | +class TriggerTypeAPI(BaseAPI): |
| 136 | + schema = { |
| 137 | + "type": "object", |
| 138 | + "properties": { |
| 139 | + "id": {"type": "string", "default": None}, |
| 140 | + "ref": {"type": "string"}, |
| 141 | + "uid": {"type": "string"}, |
| 142 | + "name": {"type": "string", "required": True}, |
| 143 | + "pack": {"type": "string"}, |
| 144 | + "description": {"type": "string"}, |
| 145 | + "payload_schema": {"type": "object", "default": {}}, |
| 146 | + "parameters_schema": {"type": "object", "default": {}}, |
| 147 | + "tags": { |
| 148 | + "description": "User associated metadata assigned to this object.", |
| 149 | + "type": "array", |
| 150 | + "items": {"type": "object"}, |
| 151 | + }, |
| 152 | + "metadata_file": { |
| 153 | + "description": "Path to the metadata file relative to the pack directory.", |
| 154 | + "type": "string", |
| 155 | + "default": "", |
| 156 | + }, |
| 157 | + }, |
| 158 | + "additionalProperties": False, |
| 159 | + } |
0 commit comments