Skip to content

Commit 8a8d698

Browse files
authored
Merge pull request oracle-samples#40 from mohitmagal/master
Samples to push to object storage with custom certificates
2 parents 195b226 + e12b075 commit 8a8d698

File tree

22 files changed

+1124
-3
lines changed

22 files changed

+1124
-3
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2020 Oracle and/or its affiliates.
1+
Copyright (c) 2021 Oracle and/or its affiliates.
22

33
The Universal Permissive License (UPL), Version 1.0
44

THIRD_PARTY_LICENSES.txt

Lines changed: 180 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ The following software (or subsets of the software) are dependencies that are us
44

55
--------------------------------------------------------------------------------
66

7-
oci-java-sdk and oci-python-sdk are dual-licensed to you under the Universal Permissive License (UPL) 1.0 or Apache License 2.0. See below for license terms. You may choose either license.
7+
oci-java-sdk, oci-python-sdk, oci-go-sdk and oci-ruby-sdk are dual-licensed to you under the Universal Permissive License (UPL) 1.0 or Apache License 2.0. See below for license terms. You may choose either license.
88
Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
99
License: Copies of the Apache License V2 and the Universal Permissive License 1.0 are included at the end of this file.
1010

1111
--------------------------------------------------------------------------------
1212

13-
fdk-java and fdk-python are licensed under the Apache License, Version 2.0.
13+
fdk-java,fdk-python, fdk-go and fdk-ruby are licensed under the Apache License, Version 2.0.
1414
License: A copy of the Apache License V2 is included at the end of this file.
1515

1616
--------------------------------------------------------------------------------
@@ -579,10 +579,188 @@ py_zipkin
579579
Copyright (c) 2018, Yelp, Inc. All Rights reserved. Apache v2
580580
License: Apache License 2.0, a copy of the license is included at the end of this file.
581581

582+
--------------------------------------------------------------------------------
583+
584+
mockito-core
585+
Copyright (c) 2007 Mockito contributors
586+
587+
This product includes software developed at
588+
https://github.com/mockito/mockito.
589+
590+
License
591+
The MIT License
592+
593+
Copyright (c) 2007 Mockito contributors
594+
595+
Permission is hereby granted, free of charge, to any person obtaining a copy
596+
of this software and associated documentation files (the "Software"), to deal
597+
in the Software without restriction, including without limitation the rights
598+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
599+
copies of the Software, and to permit persons to whom the Software is
600+
furnished to do so, subject to the following conditions:
601+
602+
The above copyright notice and this permission notice shall be included in
603+
all copies or substantial portions of the Software.
582604

605+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
606+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
607+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
608+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
609+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
610+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
611+
THE SOFTWARE.
612+
613+
--------------------------------------------------------------------------------
614+
615+
assertj-core
616+
617+
This product includes software developed at https://github.com/assertj/assertj-core.
618+
619+
License: Apache License 2.0, a copy of the license is included at the end of this file.
583620
--------------------------------------------------------------------------------
584621

622+
Webrick
585623

624+
This product includes software developed at https://github.com/ruby/webrick.
625+
626+
License:
627+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
628+
629+
Redistribution and use in source and binary forms, with or without
630+
modification, are permitted provided that the following conditions
631+
are met:
632+
1. Redistributions of source code must retain the above copyright
633+
notice, this list of conditions and the following disclaimer.
634+
2. Redistributions in binary form must reproduce the above copyright
635+
notice, this list of conditions and the following disclaimer in the
636+
documentation and/or other materials provided with the distribution.
637+
638+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
639+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
640+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
641+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
642+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
643+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
644+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
645+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
646+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
647+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
648+
SUCH DAMAGE.
649+
--------------------------------------------------------------------------------
650+
Inifile
651+
* MIT License Copyright (c) 2006 - 2014
652+
* License: MIT License
653+
MIT License Copyright (c) 2006 - 2014
654+
655+
Copyright (c) 2011 Jeff Lindsay
656+
657+
Permission is hereby granted, free of charge, to any person obtaining a copy
658+
of this software and associated documentation files (the "Software"), to deal
659+
in the Software without restriction, including without limitation the rights
660+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
661+
copies of the Software, and to permit persons to whom the Software is
662+
furnished to do so, subject to the following conditions:
663+
664+
The above copyright notice and this permission notice shall be included in all
665+
copies or substantial portions of the Software.
666+
667+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
668+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
669+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
670+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
671+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
672+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
673+
SOFTWARE.
674+
675+
* Source code: https://github.com/twp/inifile/
676+
* Project home: https://rubygems.org/gems/inifile
677+
--------------------------------------------------------------------------------
678+
json
679+
* License: Ruby License
680+
681+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
682+
You can redistribute it and/or modify it under either the terms of the
683+
2-clause BSDL (see the file BSDL), or the conditions below:
684+
685+
1. You may make and give away verbatim copies of the source form of the
686+
software without restriction, provided that you duplicate all of the
687+
original copyright notices and associated disclaimers.
688+
689+
2. You may modify your copy of the software in any way, provided that
690+
you do at least ONE of the following:
691+
692+
a) place your modifications in the Public Domain or otherwise
693+
make them Freely Available, such as by posting said
694+
modifications to Usenet or an equivalent medium, or by allowing
695+
the author to include your modifications in the software.
696+
697+
b) use the modified software only within your corporation or
698+
organization.
699+
700+
c) give non-standard binaries non-standard names, with
701+
instructions on where to get the original software distribution.
702+
703+
d) make other distribution arrangements with the author.
704+
705+
3. You may distribute the software in object code or binary form,
706+
provided that you do at least ONE of the following:
707+
708+
a) distribute the binaries and library files of the software,
709+
together with instructions (in the manual page or equivalent)
710+
on where to get the original distribution.
711+
712+
b) accompany the distribution with the machine-readable source of
713+
the software.
714+
715+
c) give non-standard binaries non-standard names, with
716+
instructions on where to get the original software distribution.
717+
718+
d) make other distribution arrangements with the author.
719+
720+
4. You may modify and include the part of the software into any other
721+
software (possibly commercial). But some files in the distribution
722+
are not written by the author, so that they are not under these terms.
723+
724+
For the list of those files and their copying conditions, see the
725+
file LEGAL.
726+
727+
5. The scripts and library files supplied as input to or produced as
728+
output from the software do not automatically fall under the
729+
copyright of the software, but belong to whomever generated them,
730+
and may be sold commercially, and may be aggregated with this
731+
software.
732+
733+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
734+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
735+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
736+
PURPOSE.
737+
* Source code: https://github.com/flori/json/
738+
* Project home: http://flori.github.io/json/
739+
--------------------------------------------------------------------------------
740+
jwt
741+
* Copyright (c) 2011 Jeff Lindsay
742+
* License: MIT License
743+
Copyright (c) 2011 Jeff Lindsay
744+
745+
Permission is hereby granted, free of charge, to any person obtaining a copy
746+
of this software and associated documentation files (the "Software"), to deal
747+
in the Software without restriction, including without limitation the rights
748+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
749+
copies of the Software, and to permit persons to whom the Software is
750+
furnished to do so, subject to the following conditions:
751+
752+
The above copyright notice and this permission notice shall be included in all
753+
copies or substantial portions of the Software.
754+
755+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
756+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
757+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
758+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
759+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
760+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
761+
SOFTWARE.
762+
* Source code: https://github.com/jwt/ruby-jwt
763+
* Project home: https://github.com/jwt/ruby-jwt
586764

587765
================================================================================
588766
Apache License
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Function that creates an object in a bucket in Object Storage using the OCI Java SDK with custom certificate
2+
3+
This function uses Resource Principals to securely authorize a function to make
4+
API calls to OCI services using the [OCI Go SDK](hhttps://docs.oracle.com/en-us/iaas/tools/go/46.1.0/).
5+
It creates an object in a bucket in Object Storage and returns a message with a status.
6+
7+
The function calls the following OCI Go SDK classes:
8+
* [ResourcePrincipalConfigurationProvider](https://docs.oracle.com/en-us/iaas/tools/go/47.1.0/common/auth/index.html#ResourcePrincipalConfigurationProvider) to authenticate
9+
* [NewObjectStorageClientWithConfigurationProvider](https://docs.oracle.com/en-us/iaas/tools/go/47.1.0/objectstorage/index.html#NewObjectStorageClientWithConfigurationProvider) to interact with Object Storage
10+
11+
As you make your way through this tutorial, look out for this icon ![user input icon](./images/userinput.png).
12+
Whenever you see it, it's time for you to perform an action.
13+
14+
15+
## Prerequisites
16+
17+
1. Before you deploy this sample function, make sure you have run steps A, B
18+
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)
19+
* A - Set up your tenancy
20+
* B - Create application
21+
* C - Set up your Cloud Shell dev environment
22+
23+
2. Have your Oracle Object Storage Namespace available. This can be found by
24+
logging into your [cloud account](https://console.us-ashburn-1.oraclecloud.com/),
25+
under your user profile, click on your Tenancy. Your Object Storage Namespace
26+
is shown there.
27+
28+
29+
## List Applications
30+
31+
Assuming you have successfully completed the prerequisites, you should see your
32+
application in the list of applications.
33+
34+
```
35+
fn ls apps
36+
```
37+
38+
39+
## Create or Update your Dynamic Group
40+
41+
In order to use other OCI Services, your function must be part of a dynamic
42+
group. For information on how to create a dynamic group, refer to the
43+
[documentation](https://docs.cloud.oracle.com/iaas/Content/Identity/Tasks/managingdynamicgroups.htm#To).
44+
45+
When specifying the *Matching Rules*, we suggest matching all functions in a compartment with:
46+
47+
```
48+
ALL {resource.type = 'fnfunc', resource.compartment.id = 'ocid1.compartment.oc1..aaaaaxxxxx'}
49+
```
50+
51+
52+
## Create or Update IAM Policies
53+
Create a new policy that allows the dynamic group to `manage objects` in
54+
the functions related compartment.
55+
56+
![user input icon](./images/userinput.png)
57+
58+
Your policy should look something like this:
59+
```
60+
Allow dynamic-group <dynamic-group-name> to manage objects in compartment <compartment-name>
61+
```
62+
e.g.
63+
```
64+
Allow dynamic-group demo-func-dyn-group to manage objects in compartment demo-func-compartment
65+
```
66+
For more information on how to create policies, go [here](https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/policysyntax.htm).
67+
68+
69+
## Review and customize the function
70+
71+
Review the following files in the current folder:
72+
- [go.mod](./go.mod) specifies all the dependencies for your function
73+
- [func.yaml](./func.yaml) that contains metadata about your function and declares properties
74+
- [func.go](./func.go) which contains the go code
75+
76+
The name of your function is specified in [func.yaml](./func.yaml).
77+
78+
79+
## Deploy the function
80+
81+
In Cloud Shell, run the *fn deploy* command to build the function and its dependencies as a Docker image,
82+
push the image to the specified Docker registry, and deploy the function to Oracle Functions
83+
in the application created earlier:
84+
85+
![user input icon](./images/userinput.png)
86+
87+
```
88+
fn -v deploy --app <app-name>
89+
```
90+
e.g.
91+
```
92+
fn -v deploy --app myapp
93+
```
94+
95+
## Create a bucket called "test"
96+
97+
![user input icon](./images/userinput.png)
98+
99+
From the OCI Console > Core Infrastructure > Object Storage > Create Bucket with bucket name = "test"
100+
101+
## Test
102+
103+
Use the *fn* CLI to invoke your function with your own bucket name and app name:
104+
105+
![user input icon](./images/userinput.png)
106+
```
107+
echo -n '{"name": "<object-name>", "bucketName":"<bucket-name>", "content": "<text-content>"}' | fn invoke <app-name> <function-name>
108+
```
109+
e.g.
110+
```
111+
echo -n '{"name": "file1.txt", "bucketName":"mybucket", "content": "This file was created in OCI object storage bucket using Oracle Functions"}' | fn invoke myapp oci-objectstorage-custom-cert-put-object-go
112+
```
113+
You should see a success message appear in your terminal.
114+
115+
116+
## Monitoring Functions
117+
118+
Learn how to configure basic observability for your function using metrics, alarms and email alerts:
119+
* [Basic Guidance for Monitoring your Functions](../basic-observability/functions.md)
120+

0 commit comments

Comments
 (0)