mirror of https://github.com/jumpserver/jumpserver
perf: 修改 playbook 目录结构
parent
894f153638
commit
f6fdc258b1
|
@ -131,7 +131,7 @@ class DatabaseTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
|
|||
|
||||
|
||||
class WebTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
|
||||
General = 'general', 'General'
|
||||
WEBSITE = 'website', _('General Website')
|
||||
|
||||
|
||||
class CloudTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
|
||||
|
|
|
@ -6,3 +6,7 @@ from .common import Asset
|
|||
|
||||
class Web(Asset):
|
||||
url = models.CharField(max_length=1024, verbose_name=_("url"))
|
||||
|
||||
username_selector = models.CharField()
|
||||
password_selector = models.CharField()
|
||||
confirm_selector = models.CharField()
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
import os
|
||||
import yaml
|
||||
from functools import partial
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def check_platform_method(manifest, manifest_path):
|
||||
required_keys = ['category', 'method', 'name', 'id', 'type']
|
||||
less_key = set(required_keys) - set(manifest.keys())
|
||||
if less_key:
|
||||
raise ValueError("Manifest missing keys: {}, {}".format(less_key, manifest_path))
|
||||
if not isinstance(manifest['type'], list):
|
||||
raise ValueError("Manifest type must be a list: {}".format(manifest_path))
|
||||
return True
|
||||
|
||||
|
||||
def check_platform_methods(methods):
|
||||
ids = [m['id'] for m in methods]
|
||||
for i, _id in enumerate(ids):
|
||||
if _id in ids[i+1:]:
|
||||
raise ValueError("Duplicate id: {}".format(_id))
|
||||
|
||||
|
||||
def get_platform_methods():
|
||||
methods = []
|
||||
for root, dirs, files in os.walk(BASE_DIR, topdown=False):
|
||||
for name in dirs:
|
||||
path = os.path.join(root, name)
|
||||
rel_path = path.replace(BASE_DIR, '.')
|
||||
if len(rel_path.split('/')) != 3:
|
||||
continue
|
||||
|
||||
manifest_path = os.path.join(path, 'manifest.yml')
|
||||
if not os.path.exists(manifest_path):
|
||||
continue
|
||||
|
||||
with open(manifest_path, 'r') as f:
|
||||
manifest = yaml.safe_load(f)
|
||||
check_platform_method(manifest, manifest_path)
|
||||
methods.append(manifest)
|
||||
|
||||
check_platform_methods(methods)
|
||||
return methods
|
||||
|
||||
|
||||
def filter_key(manifest, attr, value):
|
||||
manifest_value = manifest.get(attr, '')
|
||||
if isinstance(manifest_value, str):
|
||||
manifest_value = [manifest_value]
|
||||
return value in manifest_value or 'all' in manifest_value
|
||||
|
||||
|
||||
def filter_platform_methods(category, tp, method):
|
||||
methods = platform_ops_methods
|
||||
if category:
|
||||
methods = filter(partial(filter_key, attr='category', value=category), methods)
|
||||
if tp:
|
||||
methods = filter(partial(filter_key, attr='type', value=tp), methods)
|
||||
if method:
|
||||
methods = filter(lambda x: x['method'] == method, methods)
|
||||
return methods
|
||||
|
||||
|
||||
platform_ops_methods = get_platform_methods()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(get_platform_methods())
|
|
@ -1,9 +0,0 @@
|
|||
id: change_password_example
|
||||
name: Change password example
|
||||
category: host
|
||||
method: change_password
|
||||
vars:
|
||||
account:
|
||||
username: test
|
||||
password: teset123
|
||||
public_key: test
|
|
@ -1,6 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
"""
|
||||
Will run with the args:
|
||||
$0 $asset_json $account_json
|
||||
"""
|
Loading…
Reference in New Issue