1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
import re |
17
|
|
|
|
18
|
|
|
import yaml |
19
|
|
|
import requests |
20
|
|
|
|
21
|
|
|
from st2common.runners.base_action import Action |
22
|
|
|
from st2common.services.packs import get_pack_from_index |
23
|
|
|
|
24
|
|
|
MANIFEST_FILE = 'pack.yaml' |
25
|
|
|
EXCHANGE_REPO_URL_REGEX = r'(git@|https?://)github\.com[/:]StackStorm-Exchange/stackstorm-\S+' |
26
|
|
|
EXCHANGE_YAML_PATH = 'https://index.stackstorm.org/v1/packs/%s.yaml' |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
class LookupRemote(Action): |
30
|
|
|
def run(self, pack): |
31
|
|
|
pack_meta = get_pack_from_index(pack) |
32
|
|
|
pack_formatted = None |
33
|
|
|
# Try to get the original yaml file because we know |
34
|
|
|
# how it's stored in the Exchange, otherwise fall back |
35
|
|
|
# to transforming json. |
36
|
|
|
if pack_meta: |
37
|
|
|
if re.match(EXCHANGE_REPO_URL_REGEX, pack_meta['repo_url'], re.IGNORECASE): |
38
|
|
|
pack_formatted = requests.get(EXCHANGE_YAML_PATH % pack).text |
39
|
|
|
else: |
40
|
|
|
pack_formatted = yaml.dump(pack_meta) |
41
|
|
|
|
42
|
|
|
return { |
43
|
|
|
'pack': pack_meta, |
44
|
|
|
'pack_formatted': pack_formatted |
45
|
|
|
} |
46
|
|
|
|