Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6d1547c

Browse files
committed
adding oci-oic-hcm-object-upload
1 parent d97ec51 commit 6d1547c

File tree

7 files changed

+190
-0
lines changed

7 files changed

+190
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
__pycache__
3+
test.py
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 ![user input icon](./images/userinput.png).
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+
![user input icon](./images/userinput.png)
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+
![user input icon](./images/userinput.png)
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+
![user input icon](./images/userinput.png)
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+
![Payload on OIC](./images/function-payload.png)
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).
129 KB
Loading[フレーム]
2.96 KB
Loading[フレーム]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#
2+
# oci-oic-hsm-object-upload version 1.0.
3+
#
4+
# Copyright (c) 2020 Oracle, Inc.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
6+
#
7+
8+
from fdk import response
9+
import os
10+
import io
11+
import json
12+
import sys
13+
import oci.object_storage
14+
15+
16+
def handler(ctx, data: io.BytesIO = None):
17+
18+
signer = oci.auth.signers.get_resource_principals_signer()
19+
bucketname = "saas-oic-oci-poc"
20+
21+
try:
22+
cfg = ctx.Config()
23+
cfg_namespace = cfg["OCI_NAMESPACE"]
24+
except Exception as ex:
25+
print("Error: Configuration key has not been set.", ex, flush=True)
26+
raise
27+
28+
try:
29+
info = json.load(data)
30+
firstname = info.get("firstname")
31+
lastname = info.get("lastname")
32+
workemail = info.get("workemail")
33+
hiredate = info.get("hiredate")
34+
effectivestartdate = info.get("effectivestartdate")
35+
personid = info.get("personid")
36+
37+
except (Exception, ValueError) as ex:
38+
return str(ex)
39+
40+
filename = personid + "_data.csv"
41+
personinfo = personid + ", " + firstname + ", " + lastname + ", " + workemail + ", " + hiredate + ", " + effectivestartdate
42+
43+
return_output = put_object(signer, bucketname, filename, personinfo, cfg_namespace=cfg_namespace)
44+
return response.Response(
45+
ctx,
46+
response_data=json.dumps(return_output),
47+
headers={"Content-Type": "application/json"}
48+
)
49+
50+
51+
def put_object(signer, bucketname, objectname, content, cfg_namespace):
52+
client = oci.object_storage.ObjectStorageClient(config={}, signer=signer)
53+
try:
54+
client.put_object(cfg_namespace, bucketname, objectname, content)
55+
output = "Success State"
56+
except Exception as e:
57+
output = "Failed State"
58+
response = {"state": output}
59+
return response
60+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
schema_version: 20180708
2+
name: processemployee
3+
version: 0.0.1
4+
runtime: python
5+
entrypoint: /python/bin/fdk /function/func.py handler
6+
memory: 256
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fdk
2+
requests
3+
oci

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /