|
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 os |
|
17
|
|
|
|
|
18
|
|
|
from st2common.runners.base_action import Action |
|
19
|
|
|
from st2common.services.packs import search_pack_index |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
class PackSearch(Action): |
|
23
|
|
|
def __init__(self, config=None, action_service=None): |
|
24
|
|
|
super(PackSearch, self).__init__(config=config, action_service=action_service) |
|
25
|
|
|
self.https_proxy = os.environ.get('https_proxy', self.config.get('https_proxy', None)) |
|
26
|
|
|
self.http_proxy = os.environ.get('http_proxy', self.config.get('http_proxy', None)) |
|
27
|
|
|
self.proxy_ca_bundle_path = os.environ.get( |
|
28
|
|
|
'proxy_ca_bundle_path', |
|
29
|
|
|
self.config.get('proxy_ca_bundle_path', None) |
|
30
|
|
|
) |
|
31
|
|
|
self.no_proxy = os.environ.get('no_proxy', self.config.get('no_proxy', None)) |
|
32
|
|
|
|
|
33
|
|
|
self.proxy_config = None |
|
34
|
|
|
|
|
35
|
|
|
if self.http_proxy or self.https_proxy: |
|
36
|
|
|
self.logger.debug('Using proxy %s', |
|
37
|
|
|
self.http_proxy if self.http_proxy else self.https_proxy) |
|
38
|
|
|
self.proxy_config = { |
|
39
|
|
|
'https_proxy': self.https_proxy, |
|
40
|
|
|
'http_proxy': self.http_proxy, |
|
41
|
|
|
'proxy_ca_bundle_path': self.proxy_ca_bundle_path, |
|
42
|
|
|
'no_proxy': self.no_proxy |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if self.https_proxy and not os.environ.get('https_proxy', None): |
|
46
|
|
|
os.environ['https_proxy'] = self.https_proxy |
|
47
|
|
|
|
|
48
|
|
|
if self.http_proxy and not os.environ.get('http_proxy', None): |
|
49
|
|
|
os.environ['http_proxy'] = self.http_proxy |
|
50
|
|
|
|
|
51
|
|
|
if self.no_proxy and not os.environ.get('no_proxy', None): |
|
52
|
|
|
os.environ['no_proxy'] = self.no_proxy |
|
53
|
|
|
|
|
54
|
|
|
if self.proxy_ca_bundle_path and not os.environ.get('proxy_ca_bundle_path', None): |
|
55
|
|
|
os.environ['no_proxy'] = self.no_proxy |
|
56
|
|
|
|
|
57
|
|
|
""""Search for packs in StackStorm Exchange and other directories.""" |
|
|
|
|
|
|
58
|
|
|
def run(self, query): |
|
59
|
|
|
""" |
|
60
|
|
|
:param query: A word or a phrase to search for |
|
61
|
|
|
:type query: ``str`` |
|
62
|
|
|
""" |
|
63
|
|
|
self.logger.debug('Proxy config: %s', self.proxy_config) |
|
64
|
|
|
return search_pack_index(query, proxy_config=self.proxy_config) |
|
65
|
|
|
|