|
| 1 | +from ..service import Service |
| 2 | + |
| 3 | + |
| 4 | +class Functions(Service): |
| 5 | + |
| 6 | + def __init__(self, client): |
| 7 | + super(Functions, self).__init__(client) |
| 8 | + |
| 9 | + def list(self, search='', limit=25, offset=0, order_type='ASC'): |
| 10 | + """List Functions""" |
| 11 | + |
| 12 | + params = {} |
| 13 | + path = '/functions' |
| 14 | + params['search'] = search |
| 15 | + params['limit'] = limit |
| 16 | + params['offset'] = offset |
| 17 | + params['orderType'] = order_type |
| 18 | + |
| 19 | + return self.client.call('get', path, { |
| 20 | + 'content-type': 'application/json', |
| 21 | + }, params) |
| 22 | + |
| 23 | + def create(self, name, execute, env, vars={}, events=[], schedule='', timeout=15): |
| 24 | + """Create Function""" |
| 25 | + |
| 26 | + params = {} |
| 27 | + path = '/functions' |
| 28 | + params['name'] = name |
| 29 | + params['execute'] = execute |
| 30 | + params['env'] = env |
| 31 | + params['vars'] = vars |
| 32 | + params['events'] = events |
| 33 | + params['schedule'] = schedule |
| 34 | + params['timeout'] = timeout |
| 35 | + |
| 36 | + return self.client.call('post', path, { |
| 37 | + 'content-type': 'application/json', |
| 38 | + }, params) |
| 39 | + |
| 40 | + def get(self, function_id): |
| 41 | + """Get Function""" |
| 42 | + |
| 43 | + params = {} |
| 44 | + path = '/functions/{functionId}' |
| 45 | + path = path.replace('{functionId}', function_id) |
| 46 | + |
| 47 | + return self.client.call('get', path, { |
| 48 | + 'content-type': 'application/json', |
| 49 | + }, params) |
| 50 | + |
| 51 | + def update(self, function_id, name, execute, vars={}, events=[], schedule='', timeout=15): |
| 52 | + """Update Function""" |
| 53 | + |
| 54 | + params = {} |
| 55 | + path = '/functions/{functionId}' |
| 56 | + path = path.replace('{functionId}', function_id) |
| 57 | + params['name'] = name |
| 58 | + params['execute'] = execute |
| 59 | + params['vars'] = vars |
| 60 | + params['events'] = events |
| 61 | + params['schedule'] = schedule |
| 62 | + params['timeout'] = timeout |
| 63 | + |
| 64 | + return self.client.call('put', path, { |
| 65 | + 'content-type': 'application/json', |
| 66 | + }, params) |
| 67 | + |
| 68 | + def delete(self, function_id): |
| 69 | + """Delete Function""" |
| 70 | + |
| 71 | + params = {} |
| 72 | + path = '/functions/{functionId}' |
| 73 | + path = path.replace('{functionId}', function_id) |
| 74 | + |
| 75 | + return self.client.call('delete', path, { |
| 76 | + 'content-type': 'application/json', |
| 77 | + }, params) |
| 78 | + |
| 79 | + def list_executions(self, function_id, search='', limit=25, offset=0, order_type='ASC'): |
| 80 | + """List Executions""" |
| 81 | + |
| 82 | + params = {} |
| 83 | + path = '/functions/{functionId}/executions' |
| 84 | + path = path.replace('{functionId}', function_id) |
| 85 | + params['search'] = search |
| 86 | + params['limit'] = limit |
| 87 | + params['offset'] = offset |
| 88 | + params['orderType'] = order_type |
| 89 | + |
| 90 | + return self.client.call('get', path, { |
| 91 | + 'content-type': 'application/json', |
| 92 | + }, params) |
| 93 | + |
| 94 | + def create_execution(self, function_id): |
| 95 | + """Create Execution""" |
| 96 | + |
| 97 | + params = {} |
| 98 | + path = '/functions/{functionId}/executions' |
| 99 | + path = path.replace('{functionId}', function_id) |
| 100 | + |
| 101 | + return self.client.call('post', path, { |
| 102 | + 'content-type': 'application/json', |
| 103 | + }, params) |
| 104 | + |
| 105 | + def get_execution(self, function_id, execution_id): |
| 106 | + """Get Execution""" |
| 107 | + |
| 108 | + params = {} |
| 109 | + path = '/functions/{functionId}/executions/{executionId}' |
| 110 | + path = path.replace('{functionId}', function_id) |
| 111 | + path = path.replace('{executionId}', execution_id) |
| 112 | + |
| 113 | + return self.client.call('get', path, { |
| 114 | + 'content-type': 'application/json', |
| 115 | + }, params) |
| 116 | + |
| 117 | + def update_tag(self, function_id, tag): |
| 118 | + """Update Function Tag""" |
| 119 | + |
| 120 | + params = {} |
| 121 | + path = '/functions/{functionId}/tag' |
| 122 | + path = path.replace('{functionId}', function_id) |
| 123 | + params['tag'] = tag |
| 124 | + |
| 125 | + return self.client.call('patch', path, { |
| 126 | + 'content-type': 'application/json', |
| 127 | + }, params) |
| 128 | + |
| 129 | + def list_tags(self, function_id, search='', limit=25, offset=0, order_type='ASC'): |
| 130 | + """List Tags""" |
| 131 | + |
| 132 | + params = {} |
| 133 | + path = '/functions/{functionId}/tags' |
| 134 | + path = path.replace('{functionId}', function_id) |
| 135 | + params['search'] = search |
| 136 | + params['limit'] = limit |
| 137 | + params['offset'] = offset |
| 138 | + params['orderType'] = order_type |
| 139 | + |
| 140 | + return self.client.call('get', path, { |
| 141 | + 'content-type': 'application/json', |
| 142 | + }, params) |
| 143 | + |
| 144 | + def create_tag(self, function_id, command, code): |
| 145 | + """Create Tag""" |
| 146 | + |
| 147 | + params = {} |
| 148 | + path = '/functions/{functionId}/tags' |
| 149 | + path = path.replace('{functionId}', function_id) |
| 150 | + params['command'] = command |
| 151 | + params['code'] = code |
| 152 | + |
| 153 | + return self.client.call('post', path, { |
| 154 | + 'content-type': 'multipart/form-data', |
| 155 | + }, params) |
| 156 | + |
| 157 | + def get_tag(self, function_id, tag_id): |
| 158 | + """Get Tag""" |
| 159 | + |
| 160 | + params = {} |
| 161 | + path = '/functions/{functionId}/tags/{tagId}' |
| 162 | + path = path.replace('{functionId}', function_id) |
| 163 | + path = path.replace('{tagId}', tag_id) |
| 164 | + |
| 165 | + return self.client.call('get', path, { |
| 166 | + 'content-type': 'application/json', |
| 167 | + }, params) |
| 168 | + |
| 169 | + def delete_tag(self, function_id, tag_id): |
| 170 | + """Delete Tag""" |
| 171 | + |
| 172 | + params = {} |
| 173 | + path = '/functions/{functionId}/tags/{tagId}' |
| 174 | + path = path.replace('{functionId}', function_id) |
| 175 | + path = path.replace('{tagId}', tag_id) |
| 176 | + |
| 177 | + return self.client.call('delete', path, { |
| 178 | + 'content-type': 'application/json', |
| 179 | + }, params) |
0 commit comments