From 523465d3c0f2471365d19497ddff91a433379cd0 Mon Sep 17 00:00:00 2001 From: Petr Panuska Date: Thu, 7 May 2020 14:04:20 +0000 Subject: [PATCH] Implementing create_user flow + Refactoring to use http_graph_action --- .../System Properties/office365.prop.sl | 4 +- .../office365/_tools/http_graph_action.sl | 60 ++++++++++++++++ .../Library/office365/auth/authenticate.sl | 6 ++ .../office365/mail/list_mail_folders.sl | 21 +++--- .../Library/office365/mail/list_messages.sl | 23 +++--- .../Library/office365/user/create_user.sl | 72 +++++++++++++++++++ .../Library/office365/user/list_users.sl | 23 +++--- 7 files changed, 172 insertions(+), 37 deletions(-) create mode 100644 office365/Content/Library/office365/_tools/http_graph_action.sl create mode 100644 office365/Content/Library/office365/user/create_user.sl diff --git a/office365/Content/Configuration/System Properties/office365.prop.sl b/office365/Content/Configuration/System Properties/office365.prop.sl index e8bdbab..db76487 100644 --- a/office365/Content/Configuration/System Properties/office365.prop.sl +++ b/office365/Content/Configuration/System Properties/office365.prop.sl @@ -5,7 +5,7 @@ ######################################################################################################################## namespace: '' properties: - - tenant: '' + - tenant: rpamf.onmicrosoft.com - client_id: '' - client_secret: value: '' @@ -14,7 +14,7 @@ properties: value: '' sensitive: false - proxy_host: '' - - proxy_port: '' + - proxy_port: '8080' - proxy_username: '' - proxy_password: value: '' diff --git a/office365/Content/Library/office365/_tools/http_graph_action.sl b/office365/Content/Library/office365/_tools/http_graph_action.sl new file mode 100644 index 0000000..afb401c --- /dev/null +++ b/office365/Content/Library/office365/_tools/http_graph_action.sl @@ -0,0 +1,60 @@ +namespace: office365._tools +flow: + name: http_graph_action + inputs: + - url + - token + - method + - body: + required: false + workflow: + - http_client_action: + do: + io.cloudslang.base.http.http_client_action: + - url: "${'https://graph.microsoft.com/v1.0%s' % url}" + - auth_type: anonymous + - proxy_host: "${get_sp('proxy_host')}" + - proxy_port: "${get_sp('proxy_port')}" + - proxy_username: "${get_sp('proxy_username')}" + - proxy_password: + value: "${get_sp('proxy_password')}" + sensitive: true + - trust_all_roots: 'false' + - x_509_hostname_verifier: strict + - headers: "${'Authorization: Bearer ' + token}" + - body: '${body}' + - content_type: application/json + - method: '${method}' + publish: + - return_result + - error_message + - status_code + - return_code + - response_headers + navigate: + - SUCCESS: SUCCESS + - FAILURE: on_failure + outputs: + - return_result: '${return_result}' + - response_headers: '${response_headers}' + - error_message: '${error_message}' + - status_code: '${status_code}' + - return_code: '${return_code}' + results: + - FAILURE + - SUCCESS +extensions: + graph: + steps: + http_client_action: + x: 85 + 'y': 96 + navigate: + 157930d8-a607-4c4d-9e14-cf9639670613: + targetId: 4e80e608-6286-2b58-a16a-2847a30b06d5 + port: SUCCESS + results: + SUCCESS: + 4e80e608-6286-2b58-a16a-2847a30b06d5: + x: 253 + 'y': 91 diff --git a/office365/Content/Library/office365/auth/authenticate.sl b/office365/Content/Library/office365/auth/authenticate.sl index ec71dd9..36d428c 100644 --- a/office365/Content/Library/office365/auth/authenticate.sl +++ b/office365/Content/Library/office365/auth/authenticate.sl @@ -15,6 +15,12 @@ flow: do: io.cloudslang.base.http.http_client_post: - url: "${'https://login.microsoftonline.com/%s/oauth2/v2.0/token' % tenant_q}" + - proxy_host: "${get_sp('proxy_host')}" + - proxy_port: "${get_sp('proxy_port')}" + - proxy_username: "${get_sp('proxy_username')}" + - proxy_password: + value: "${get_sp('proxy_password')}" + sensitive: true - body: "${'client_id=%s&client_secret=%s&scope=https%%3A%%2F%%2Fgraph.microsoft.com%%2F.default&grant_type=client_credentials' % (client_id_q, client_secret_q)}" - content_type: application/x-www-form-urlencoded publish: diff --git a/office365/Content/Library/office365/mail/list_mail_folders.sl b/office365/Content/Library/office365/mail/list_mail_folders.sl index a55f931..1bb2921 100644 --- a/office365/Content/Library/office365/mail/list_mail_folders.sl +++ b/office365/Content/Library/office365/mail/list_mail_folders.sl @@ -11,19 +11,18 @@ flow: - token navigate: - FAILURE: on_failure - - SUCCESS: http_client_get - - http_client_get: + - SUCCESS: http_graph_action + - http_graph_action: do: - io.cloudslang.base.http.http_client_get: - - url: "${'https://graph.microsoft.com/v1.0/users/%s/mailFolders' % user_principal_name}" - - auth_type: anonymous - - headers: "${'Authorization: Bearer ' + token}" - - content_type: application/json + office365._tools.http_graph_action: + - url: "${'/users/%s/mailFolders' % user_principal_name}" + - token: '${token}' + - method: GET publish: - json: '${return_result}' navigate: - - SUCCESS: SUCCESS - FAILURE: on_failure + - SUCCESS: SUCCESS outputs: - json: '${json}' results: @@ -35,11 +34,11 @@ extensions: authenticate: x: 110 'y': 102 - http_client_get: + http_graph_action: x: 300 - 'y': 102 + 'y': 95 navigate: - 73cf73b4-7c40-cee9-6357-15280d6d1fba: + f5cb9d45-73b8-a8b4-b98f-1f77a2fba12a: targetId: 0de24e87-f841-d198-f608-1f8d4812b488 port: SUCCESS results: diff --git a/office365/Content/Library/office365/mail/list_messages.sl b/office365/Content/Library/office365/mail/list_messages.sl index 29d3345..b519645 100644 --- a/office365/Content/Library/office365/mail/list_messages.sl +++ b/office365/Content/Library/office365/mail/list_messages.sl @@ -14,19 +14,18 @@ flow: - token navigate: - FAILURE: on_failure - - SUCCESS: http_client_get - - http_client_get: + - SUCCESS: http_graph_action + - http_graph_action: do: - io.cloudslang.base.http.http_client_get: - - url: "${'https://graph.microsoft.com/v1.0/users/%s%s/messages%s' % (user_principal_name, '' if not folder_name else '/mailFolders'+folder_name, \"\" if not top else '?$top='+top)}" - - auth_type: anonymous - - headers: "${'Authorization: Bearer ' + token}" - - content_type: application/json + office365._tools.http_graph_action: + - url: "${'/users/%s%s/messages%s' % (user_principal_name, '' if not folder_name else '/mailFolders'+folder_name, \"\" if not top else '?$top='+top)}" + - token: '${token}' + - method: GET publish: - json: '${return_result}' navigate: - - SUCCESS: SUCCESS - FAILURE: on_failure + - SUCCESS: SUCCESS outputs: - json: '${json}' results: @@ -38,11 +37,11 @@ extensions: authenticate: x: 110 'y': 102 - http_client_get: - x: 300 - 'y': 102 + http_graph_action: + x: 289 + 'y': 96 navigate: - 73cf73b4-7c40-cee9-6357-15280d6d1fba: + 936d4249-beaf-485b-c21e-8916df2ba740: targetId: 0de24e87-f841-d198-f608-1f8d4812b488 port: SUCCESS results: diff --git a/office365/Content/Library/office365/user/create_user.sl b/office365/Content/Library/office365/user/create_user.sl new file mode 100644 index 0000000..c1b66fa --- /dev/null +++ b/office365/Content/Library/office365/user/create_user.sl @@ -0,0 +1,72 @@ +######################################################################################################################## +#!! +#! @input user_principal_name: Unique identifier of the user +#! @input force_change_password: Force the user to change his/her password first time he/she signs in +#!!# +######################################################################################################################## +namespace: office365.user +flow: + name: create_user + inputs: + - display_name: Test + - mail_nick_name: test + - user_principal_name: test@rpamf.onmicrosoft.com + - password: + sensitive: true + - force_change_password: 'false' + workflow: + - authenticate: + do: + office365.auth.authenticate: [] + publish: + - token + navigate: + - FAILURE: on_failure + - SUCCESS: http_graph_action + - http_graph_action: + do: + office365._tools.http_graph_action: + - url: /users + - token: '${token}' + - method: POST + - body: |- + ${''' + { + "accountEnabled": true, + "displayName": "%s", + "mailNickname": "%s", + "userPrincipalName": "%s", + "passwordProfile" : { + "forceChangePasswordNextSignIn": %s, + "password": "%s" + } + } + ''' % (display_name, mail_nick_name, user_principal_name, force_change_password, password)} + publish: + - json: '${return_result}' + navigate: + - FAILURE: on_failure + - SUCCESS: SUCCESS + outputs: + - json: '${json}' + results: + - FAILURE + - SUCCESS +extensions: + graph: + steps: + http_graph_action: + x: 229 + 'y': 83 + navigate: + 297032fa-a883-67fe-0ef2-c59f849f7d77: + targetId: f9ca98c4-3b22-08dc-b07e-53dfa4d7d54f + port: SUCCESS + authenticate: + x: 55 + 'y': 88 + results: + SUCCESS: + f9ca98c4-3b22-08dc-b07e-53dfa4d7d54f: + x: 393 + 'y': 81 diff --git a/office365/Content/Library/office365/user/list_users.sl b/office365/Content/Library/office365/user/list_users.sl index 08b1654..6a7d3b5 100644 --- a/office365/Content/Library/office365/user/list_users.sl +++ b/office365/Content/Library/office365/user/list_users.sl @@ -9,19 +9,18 @@ flow: - token navigate: - FAILURE: on_failure - - SUCCESS: http_client_get - - http_client_get: + - SUCCESS: http_graph_action + - http_graph_action: do: - io.cloudslang.base.http.http_client_get: - - url: 'https://graph.microsoft.com/v1.0/users' - - auth_type: anonymous - - headers: "${'Authorization: Bearer ' + token}" - - content_type: application/json + office365._tools.http_graph_action: + - url: /users + - token: '${token}' + - method: GET publish: - json: '${return_result}' navigate: - - SUCCESS: SUCCESS - FAILURE: on_failure + - SUCCESS: SUCCESS outputs: - json: '${json}' results: @@ -32,12 +31,12 @@ extensions: steps: authenticate: x: 110 - 'y': 102 - http_client_get: + 'y': 101 + http_graph_action: x: 300 - 'y': 102 + 'y': 119 navigate: - 73cf73b4-7c40-cee9-6357-15280d6d1fba: + 0d6410c8-cf40-3261-e842-8dd338ed2d10: targetId: 0de24e87-f841-d198-f608-1f8d4812b488 port: SUCCESS results: