2020-10-12 04:44:30 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2023-02-07 08:21:26 +00:00
|
|
|
import argparse
|
2020-10-12 04:44:30 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2023-02-07 08:21:26 +00:00
|
|
|
|
2020-10-12 04:44:30 +00:00
|
|
|
import django
|
|
|
|
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
APPS_DIR = os.path.join(BASE_DIR, 'apps')
|
|
|
|
sys.path.insert(0, APPS_DIR)
|
|
|
|
|
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings")
|
|
|
|
django.setup()
|
|
|
|
|
2022-08-22 07:23:28 +00:00
|
|
|
from resources.assets import AssetsGenerator, NodesGenerator, PlatformGenerator
|
2020-10-12 04:44:30 +00:00
|
|
|
from resources.users import UserGroupGenerator, UserGenerator
|
|
|
|
from resources.perms import AssetPermissionGenerator
|
2022-05-30 08:01:57 +00:00
|
|
|
from resources.terminal import CommandGenerator, SessionGenerator
|
2024-01-02 08:11:56 +00:00
|
|
|
from resources.accounts import AccountGenerator
|
2020-10-12 04:44:30 +00:00
|
|
|
|
|
|
|
resource_generator_mapper = {
|
|
|
|
'asset': AssetsGenerator,
|
2022-08-22 07:23:28 +00:00
|
|
|
'platform': PlatformGenerator,
|
2020-10-12 04:44:30 +00:00
|
|
|
'node': NodesGenerator,
|
|
|
|
'user': UserGenerator,
|
|
|
|
'user_group': UserGroupGenerator,
|
2020-12-08 06:26:18 +00:00
|
|
|
'asset_permission': AssetPermissionGenerator,
|
2022-03-30 11:07:49 +00:00
|
|
|
'command': CommandGenerator,
|
2023-02-07 08:21:26 +00:00
|
|
|
'session': SessionGenerator,
|
2024-01-02 08:11:56 +00:00
|
|
|
'account': AccountGenerator,
|
2023-02-07 08:21:26 +00:00
|
|
|
'all': None
|
2021-01-29 15:52:16 +00:00
|
|
|
# 'stat': StatGenerator
|
2020-10-12 04:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description='Generate fake data')
|
|
|
|
parser.add_argument(
|
|
|
|
'resource', type=str,
|
|
|
|
choices=resource_generator_mapper.keys(),
|
2023-02-07 08:21:26 +00:00
|
|
|
default='all',
|
2020-10-12 04:44:30 +00:00
|
|
|
help="resource to generate"
|
|
|
|
)
|
2023-02-13 12:04:17 +00:00
|
|
|
parser.add_argument('-c', '--count', type=int, default=1000)
|
2020-10-12 04:44:30 +00:00
|
|
|
parser.add_argument('-b', '--batch_size', type=int, default=100)
|
|
|
|
parser.add_argument('-o', '--org', type=str, default='')
|
|
|
|
args = parser.parse_args()
|
|
|
|
resource, count, batch_size, org_id = args.resource, args.count, args.batch_size, args.org
|
2024-01-02 08:11:56 +00:00
|
|
|
resource = resource.lower().rstrip('s')
|
2023-02-07 08:21:26 +00:00
|
|
|
|
|
|
|
generator_cls = []
|
|
|
|
if resource == 'all':
|
|
|
|
generator_cls = resource_generator_mapper.values()
|
|
|
|
else:
|
2023-02-09 12:48:25 +00:00
|
|
|
generator_cls.append(resource_generator_mapper[resource])
|
2023-02-07 08:21:26 +00:00
|
|
|
|
|
|
|
for _cls in generator_cls:
|
|
|
|
generator = _cls(org_id=org_id, batch_size=batch_size)
|
|
|
|
generator.generate(count)
|
2020-10-12 04:44:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|