SMA-2501 add new process-search to PMCI
parent
afa0552d4e
commit
81f5e65b3d
@ -1,36 +1,89 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
DOCUMENTATION = '''
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: smardigo_user_token
|
||||
short_description: create smardigo user token
|
||||
'''
|
||||
EXAMPLES = '''
|
||||
- hosts: localhost
|
||||
tasks:
|
||||
|
||||
EXAMPLES = r'''
|
||||
# Pass in secret and user_id
|
||||
- name: create smardigo user token
|
||||
smardigo_user_token:
|
||||
secret: ""
|
||||
user_id: ""
|
||||
register: result
|
||||
- debug: var=result
|
||||
secret: "some-secret"
|
||||
user_id: "some-user"
|
||||
|
||||
# Also pass in realm and client_id
|
||||
- name: create smardigo user token
|
||||
smardigo_user_token:
|
||||
secret: "some-secret"
|
||||
user_id: "some-user"
|
||||
realm: "some-some"
|
||||
client_id: "some-client"
|
||||
'''
|
||||
|
||||
RETURN = r'''
|
||||
token:
|
||||
description: The generated user token.
|
||||
type: str
|
||||
returned: always
|
||||
sample: 'eyJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiZGlyIn0..Q1NwxoSW8iHpceK8PhEycA.XNJc_8h5rW2aQ2788hpw6XumG-bKIiNIdDxWaRrvIyc._BJSwA_Y_0RlvgM5R8gaXA'
|
||||
changed:
|
||||
description: A user token was generated.
|
||||
type: bool
|
||||
returned: always
|
||||
sample: true
|
||||
'''
|
||||
|
||||
from jose import jwe
|
||||
from ansible.module_utils.basic import *
|
||||
import json
|
||||
|
||||
def main():
|
||||
def run_module():
|
||||
module_args = dict(
|
||||
secret=dict(type='str', required=True),
|
||||
user_id=dict(type='str', required=True),
|
||||
realm=dict(type='str', required=False, default=''),
|
||||
client_id=dict(type='str', required=False, default='')
|
||||
)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_args,
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
result = dict(
|
||||
changed=False,
|
||||
token=''
|
||||
)
|
||||
|
||||
claims = dict(
|
||||
sub=module.params["user_id"],
|
||||
)
|
||||
|
||||
fields = {
|
||||
"secret": {"default": False, "type": "str"},
|
||||
"user_id": {"default": False, "type": "str"}
|
||||
}
|
||||
if module.params['realm'] and module.params['client_id']:
|
||||
claims['iam'] = dict(
|
||||
realm=module.params['realm'],
|
||||
clientId=module.params['client_id'],
|
||||
client_id=module.params['client_id'],
|
||||
)
|
||||
elif module.params['realm'] or module.params['client_id']:
|
||||
module.fail_json(
|
||||
msg='Please specify both \'realm\' and \'client_id\'', **result)
|
||||
|
||||
module = AnsibleModule(argument_spec=fields)
|
||||
result['token'] = jwe.encrypt(json.dumps(
|
||||
claims), module.params["secret"], algorithm='dir', encryption='A128CBC-HS256')
|
||||
result['changed'] = True
|
||||
|
||||
token = jwe.encrypt('{"sub":"' + module.params["user_id"] + '"}', module.params["secret"], algorithm='dir', encryption='A128CBC-HS256')
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
def main():
|
||||
run_module()
|
||||
|
||||
module.exit_json(changed=True, token=token)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
smardigo:
|
||||
cloudevents:
|
||||
event-distributor:
|
||||
rest:
|
||||
connect-timeout: PT1S
|
||||
read-timeout: PT30S
|
||||
consumers:
|
||||
- type: process-created
|
||||
urls:
|
||||
- "http://{{ process_search_id }}:8080/process-created"
|
||||
- type: process-data-updated
|
||||
urls:
|
||||
- "http://{{ process_search_id }}:8080/process-data-updated"
|
||||
- type: process-deleted
|
||||
urls:
|
||||
- "http://{{ process_search_id }}:8080/process-deleted"
|
||||
- type: delete-scope
|
||||
urls:
|
||||
- "http://{{ process_search_id }}:8080/delete-scope"
|
||||
- type: activate-config
|
||||
urls:
|
||||
- "http://{{ process_search_id }}:8080/activate-config"
|
||||
- type: index-rebuild
|
||||
urls:
|
||||
- "http://{{ process_search_id }}:8080/index-rebuild"
|
||||
Loading…
Reference in New Issue