|
| 1 | +# OCI-OIC-HCM Object Upload Function |
| 2 | +## About |
| 3 | +This function shows simplified uploading of a CSV file into Oracle Object Storage using data received from Oracle Integration Cloud (OIC) through REST to invoke this function. The function expects a POST operation with a payload to put into a CSV file. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Setup Instructions |
| 8 | +As you make your way through this tutorial, look out for this icon . |
| 9 | +Whenever you see it, it's time for you to perform an action. |
| 10 | + |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | +Before you deploy this sample function, make sure you have run step A, B and C of the [Oracle Functions Quick Start Guide for Cloud Shell](https://www.oracle.com/webfolder/technetwork/tutorials/infographics/oci_functions_cloudshell_quickview/functions_quickview_top/functions_quickview/index.html) |
| 14 | +* A - Set up your tenancy |
| 15 | +* B - Create application |
| 16 | +* C - Set up your Cloud Shell dev environment |
| 17 | + |
| 18 | + |
| 19 | +## List Applications |
| 20 | +Assuming your have successfully completed the prerequisites, you should see your |
| 21 | +application in the list of applications. |
| 22 | +``` |
| 23 | +fn ls apps |
| 24 | +``` |
| 25 | + |
| 26 | + |
| 27 | +## Create or Update your Dynamic Group |
| 28 | +In order to use other OCI Services, your function must be part of a dynamic group. For information on how to create a dynamic group, refer to the [documentation](https://docs.cloud.oracle.com/iaas/Content/Identity/Tasks/managingdynamicgroups.htm#To). |
| 29 | + |
| 30 | +When specifying the *Matching Rules*, we suggest matching all functions in a compartment with: |
| 31 | +``` |
| 32 | +ALL {resource.type = 'fnfunc', resource.compartment.id = 'ocid1.compartment.oc1..aaaaaxxxxx'} |
| 33 | +``` |
| 34 | +Please check the [Accessing Other Oracle Cloud Infrastructure Resources from Running Functions](https://docs.cloud.oracle.com/en-us/iaas/Content/Functions/Tasks/functionsaccessingociresources.htm) for other *Matching Rules* options. |
| 35 | + |
| 36 | + |
| 37 | +## Create or Update IAM Policies |
| 38 | +Create a new policy that allows the dynamic group to manage compute instances. We will grant `inspect/use/manage` access to `xxx` in the compartment. |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +Your policy should look something like this: |
| 43 | +``` |
| 44 | +Allow dynamic-group <dynamic-group-name> to xxx XXX in compartment <compartment-name> |
| 45 | +``` |
| 46 | + |
| 47 | +For more information on how to create policies, check the [documentation](https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/policysyntax.htm). |
| 48 | + |
| 49 | + |
| 50 | +## Review and customize the function |
| 51 | +Review the following files in the current folder: |
| 52 | +* the code of the function, [func.py](./processEmployee/func.py) |
| 53 | +* its dependencies, [requirements.txt](./processEmployee/requirements.txt) |
| 54 | +* the function metadata, [func.yaml](./processEmployee/func.yaml) |
| 55 | + |
| 56 | + |
| 57 | +## Deploy the function |
| 58 | +In Cloud Shell, run the *fn deploy* command to build the function and its dependencies as a Docker image, |
| 59 | +push the image to OCIR, and deploy the function to Oracle Functions in your application. |
| 60 | + |
| 61 | + |
| 62 | +``` |
| 63 | +fn -v deploy --app <app-name> |
| 64 | +``` |
| 65 | + |
| 66 | +## Set the function configuration values |
| 67 | +The function requires the following configuration values to be set: |
| 68 | +- OCI_NAMESPACE |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +Use the *fn CLI* to set the config value: |
| 73 | +``` |
| 74 | +fn config function <app-name> <function-name> OCI_NAMESPACE <NAMESPACE> |
| 75 | +``` |
| 76 | +e.g. |
| 77 | +``` |
| 78 | +fn config function myapp OCI_NAMESPACE mynamespace |
| 79 | +``` |
| 80 | + |
| 81 | +## Test the function |
| 82 | +```bash |
| 83 | +# After deploying the function and configuring the namespace, you can test the function by invoking: |
| 84 | + |
| 85 | +echo -n "{ |
| 86 | + 'firstname': '', |
| 87 | + 'lastname': '', |
| 88 | + 'workemail': '', |
| 89 | + 'hiredate': '', |
| 90 | + 'effectivestartdate': '', |
| 91 | + 'personid': '' |
| 92 | +}" | fn invoke <app-name> <function-name> |
| 93 | + |
| 94 | +# where the json is the expected payload structure |
| 95 | +``` |
| 96 | + |
| 97 | +## Calling the function from OIC |
| 98 | +To call the function from OIC, you will have to have an integration using a REST adapter connection pointing to this function. |
| 99 | + |
| 100 | + |
| 101 | +To setup your REST connection in your integration, the option `Configure a request payload for this endpoint` in the Basic Info page must be *checked*. On the next tab, `Requests`, the below sample json needs to be set for the target data to appear inside the mapper. |
| 102 | + |
| 103 | +```bash |
| 104 | +{ |
| 105 | + 'firstname': '', |
| 106 | + 'lastname': '', |
| 107 | + 'workemail': '', |
| 108 | + 'hiredate': '', |
| 109 | + 'effectivestartdate': '', |
| 110 | + 'personid': '' |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +In the mapper connecting to the REST adapter connection, the data in the source needs to be mapped to the target. In this case, the source data is from a GET request pulling the information from Oracle Human Capital Management (HCM). |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +An example of how this invocation is done from OIC can be found in this [documentation](https://docs.oracle.com/en/cloud/paas/integration-cloud/rest-adapter/configure-rest-adapter-consume-oracle-functions.html). |
0 commit comments