Skip to content

Sample code for dotnet platform #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
05e11c9
Added helloworld sample for dotnet
ddevadat Sep 8, 2022
a13385b
Updated the readme instructions for deploy & test
ddevadat Sep 8, 2022
4f53197
added the test icon
ddevadat Sep 8, 2022
b4aa547
Added function for list compute instance dotnet
ddevadat Sep 8, 2022
4c270be
added deployment image
ddevadat Sep 8, 2022
c11f01f
updated readme index
ddevadat Sep 8, 2022
36af33d
Merge pull request #1 from ddevadat/dotnet-samples
ddevadat Sep 8, 2022
a5e8b80
Added compute control dotnet function
ddevadat Sep 12, 2022
e166def
added function readme
ddevadat Sep 12, 2022
9710bb2
Updated readme index for comput control dotnet
ddevadat Sep 12, 2022
308537e
Added dotnet function for listing compartments in a tenancy
ddevadat Sep 28, 2022
c3c0120
corrected readme
ddevadat Sep 28, 2022
08391dc
updated index readme
ddevadat Sep 28, 2022
95dcbdb
Merge pull request #2 from ddevadat/dotnet-samples
ddevadat Sep 28, 2022
1ef50b8
added list object dotnet function
ddevadat Sep 28, 2022
73f06dc
updated index for list object dotnet function
ddevadat Sep 28, 2022
a607258
Merge pull request #3 from ddevadat/dotnet-samples
ddevadat Sep 28, 2022
854bf7f
added get oss object in dotnet function
ddevadat Sep 28, 2022
89b76a7
Merge pull request #4 from ddevadat/dotnet-samples
ddevadat Sep 28, 2022
4cb8390
added put object in oss dotnet function
ddevadat Sep 28, 2022
c0547f3
Merge pull request #5 from ddevadat/dotnet-samples
ddevadat Sep 28, 2022
dd36258
added create par dotnet function
ddevadat Oct 4, 2022
6d68d86
Merge pull request #6 from ddevadat/dotnet-samples
ddevadat Oct 4, 2022
d860a79
added copy object dotnet function
ddevadat Oct 4, 2022
19e55cd
Merge pull request #7 from ddevadat/dotnet-samples
ddevadat Oct 4, 2022
aa4ac58
updated readme for create par dotnet function
ddevadat Oct 4, 2022
a238aab
Merge pull request #8 from ddevadat/dotnet-samples
ddevadat Oct 4, 2022
35890c7
removed redundant inputmessage.cs
ddevadat Oct 5, 2022
003a810
added display oci event dotnet function
ddevadat Oct 5, 2022
ad8d8b1
Merge pull request #9 from ddevadat/dotnet-samples
ddevadat Oct 5, 2022
7949980
added invoke function from another function - dotnet function
ddevadat Oct 6, 2022
3147633
Merge pull request #10 from ddevadat/dotnet-samples
ddevadat Oct 6, 2022
cf6a0be
added get secret value dotnet function
ddevadat Oct 17, 2022
ef96d42
Merge pull request #11 from ddevadat/dotnet-samples
ddevadat Oct 17, 2022
7d34df0
added dotnet function for deciphering using using vault key
ddevadat Oct 17, 2022
9bd05fe
Merge pull request #12 from ddevadat/dotnet-samples
ddevadat Oct 17, 2022
0aa2170
added dotnet function for ords sql queries
ddevadat Oct 20, 2022
1cd3f9e
Merge pull request #13 from ddevadat/dotnet-samples
ddevadat Oct 20, 2022
72ed54a
dotnet function for query adb using oracle client
ddevadat Oct 27, 2022
2594c01
Merge pull request #14 from ddevadat/dotnet-samples
ddevadat Oct 27, 2022
edbf6b1
added missing screenshot images
ddevadat Oct 27, 2022
eee0140
updated readme for sql client run dotnet function
ddevadat Oct 27, 2022
adaee25
Merge pull request #15 from ddevadat/dotnet-samples
ddevadat Oct 27, 2022
0f5a53a
dotnet function for sending message to ONS
ddevadat Oct 27, 2022
7a4b4f5
Merge pull request #16 from ddevadat/dotnet-samples
ddevadat Oct 27, 2022
9e5ad54
dotnet function to send email
ddevadat Oct 27, 2022
3ceeefa
Merge pull request #17 from ddevadat/dotnet-samples
ddevadat Oct 27, 2022
7f32dd9
corrected readme index
ddevadat Oct 27, 2022
dd9a8a0
Merge pull request #18 from ddevadat/dotnet-samples
ddevadat Oct 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ This repository provides examples demonstrating how to use Oracle Functions.
* [Notifications Service](./samples/basic-observability/notifications.md)

## How To
| Description | Python | Java |
|------------------------------------------------------|:------:|:----:|
| Hello World |[sample](./samples/helloworld)|[sample](./samples/helloworld)|
| List OCI Compute instances |[sample](./samples/oci-list-instances-python)|[sample](./samples/oci-list-instances-java)|
| Control OCI Compute instances (start/stop/status) |[sample](./samples/oci-compute-control-python)|
| List OCI compartments |[sample](./samples/oci-list-compartments-python)|
| List objects in OCI Object Storage |[sample](./samples/oci-objectstorage-list-objects-python)|[sample](./samples/oci-objectstorage-list-objects-java)|
| Read an object in OCI Object Storage |[sample](./samples/oci-objectstorage-get-object-python)|[sample](./samples/oci-objectstorage-get-object-java)|
| Create an object in OCI Object Storage |[sample](./samples/oci-objectstorage-put-object-python)|[sample](./samples/oci-objectstorage-put-object-java)|
| Create a PAR in OCI Object Storage |[sample](./samples/oci-objectstorage-create-par-python)||
| Copy object from one OCI Object Storage bucket to another |[sample](./samples/oci-objectstorage-copy-objects-python)||
| Display an OCI Cloud Event |[sample](./samples/oci-event-display-python)|
| Invoke another Function using the OCI SDK |[sample](./samples/oci-invoke-function-python)|||
| Run a SQL statement against Autonomous DB using ORDS | [sample](./samples/oci-adb-ords-runsql-python) |
| Run a SQL statement against Autonomous DB using DB Client |[sample](./samples/oci-adb-client-runsql-python)||
| Publish a notification using ONS |[sample](./samples/oci-ons-publish-python)|
| Send an email using Email Delivery Service |[sample](./samples/oci-email-send-python)|
| Decrypt cipher using Vault keys |[sample](./samples/oci-vault-decrypt-python)
| Get a secret from Vault |[sample](./samples/oci-vault-get-secret-python)|
| Description | Python | Java | Dotnet |
|------------------------------------------------------|:------:|:----:|:----:|
| Hello World |[sample](./samples/helloworld)|[sample](./samples/helloworld)|[sample](./samples/helloworld)|
| List OCI Compute instances |[sample](./samples/oci-list-instances-python)|[sample](./samples/oci-list-instances-java)|[sample](./samples/oci-list-instances-dotnet)|
| Control OCI Compute instances (start/stop/status) |[sample](./samples/oci-compute-control-python)||[sample](./samples/oci-compute-control-dotnet)|
| List OCI compartments |[sample](./samples/oci-list-compartments-python)||[sample](./samples/oci-list-compartments-dotnet)|
| List objects in OCI Object Storage |[sample](./samples/oci-objectstorage-list-objects-python)|[sample](./samples/oci-objectstorage-list-objects-java)|[sample](./samples/oci-objectstorage-list-objects-dotnet)|
| Read an object in OCI Object Storage |[sample](./samples/oci-objectstorage-get-object-python)|[sample](./samples/oci-objectstorage-get-object-java)|[sample](./samples/oci-objectstorage-get-object-dotnet)|
| Create an object in OCI Object Storage |[sample](./samples/oci-objectstorage-put-object-python)|[sample](./samples/oci-objectstorage-put-object-java)|[sample](./samples/oci-objectstorage-put-object-dotnet)|
| Create a PAR in OCI Object Storage |[sample](./samples/oci-objectstorage-create-par-python)||[sample](./samples/oci-objectstorage-create-par-dotnet)|
| Copy object from one OCI Object Storage bucket to another |[sample](./samples/oci-objectstorage-copy-objects-python)||[sample](./samples/oci-objectstorage-copy-objects-dotnet)|
| Display an OCI Cloud Event |[sample](./samples/oci-event-display-python)||[sample](./samples/oci-event-display-dotnet)|
| Invoke another Function using the OCI SDK |[sample](./samples/oci-invoke-function-python)||[sample](./samples/oci-invoke-function-dotnet)|
| Run a SQL statement against Autonomous DB using ORDS | [sample](./samples/oci-adb-ords-runsql-python) ||[sample](./samples/oci-adb-ords-runsql-dotnet)|
| Run a SQL statement against Autonomous DB using DB Client |[sample](./samples/oci-adb-client-runsql-python)|| [sample](./samples/oci-adb-client-runsql-dotnet)|
| Publish a notification using ONS |[sample](./samples/oci-ons-publish-python)||[sample](./samples/oci-ons-publish-dotnet)|
| Send an email using Email Delivery Service |[sample](./samples/oci-email-send-python)||[sample](./samples/oci-email-send-dotnet)|
| Decrypt cipher using Vault keys |[sample](./samples/oci-vault-decrypt-python)||[sample](./samples/oci-vault-decrypt-dotnet)|
| Get a secret from Vault |[sample](./samples/oci-vault-get-secret-python)||[sample](./samples/oci-vault-get-secret-dotnet)|
| Write IAM policies that enables Functions in a tenancy to access resources in other tenancies ||[sample](./samples/oci-cross-tenancy-policies-java)
| Trace a function with APM and add custom child spans using Zipkin |[sample](./samples/trace-functions-with-apm)|

Expand Down
48 changes: 48 additions & 0 deletions samples/helloworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ fn -v deploy --app myapp

#### Test

![user input icon](./images/userinput.png)

To invoke the Java `hello-java` function, run:
```
fn invoke myapp hello-java
Expand All @@ -123,6 +125,52 @@ The `Hello, Bob!` output is displayed.
Congratulations! You've just created, deployed, and invoked a Java HelloWorld function using Oracle Functions!


### Dotnet

#### Code

The [Dotnet folder](./dotnet) contains the files to deploy the `hello-dotnet` function in Dotnet:
* the code of the function, [HelloWorld.cs](./dotnet/HelloWorld.cs)
* its dependencies, [HelloWorld.csproj](./dotnet/HelloWorld.csproj)
* the function metadata, [func.yaml](./dotnet/func.yaml)


#### Deploy

![user input icon](./images/userinput.png)

Change directory to *dotnet* and deploy the `hello-dotnet` function using:

```
fn -v deploy --app <app-name>
```

e.g.
```
fn -v deploy --app myapp
```

#### Test

![user input icon](./images/userinput.png)

To invoke the Dotnet `hello-dotnet` function, run:
```
fn invoke myapp hello-dotnet
```
The Dotnet version displays `Hello, world!`



To invoke the Dotnet function with a payload, run:
```
echo -n "Bob" | fn invoke myapp hello-dotnet
```
The `Hello, Bob!` output is displayed.


Congratulations! You've just created, deployed, and invoked a Dotnet HelloWorld function using Oracle Functions!


### Node, Golang, and Ruby

Expand Down
11 changes: 11 additions & 0 deletions samples/helloworld/dotnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM fnproject/dotnet:3.1-1.0.4-dev as build-stage
WORKDIR /function
COPY . .
RUN dotnet sln add HelloWorld.csproj
RUN dotnet build HelloWorld.csproj -c Release
RUN dotnet publish HelloWorld.csproj -c Release -o out
FROM fnproject/dotnet:3.1-1.0.4
WORKDIR /function
COPY --from=build-stage /function/out/ /function/
ENTRYPOINT ["dotnet", "HelloWorld.dll"]
CMD ["Function:Greeter:greet"]
17 changes: 17 additions & 0 deletions samples/helloworld/dotnet/Function.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions samples/helloworld/dotnet/HelloWorld.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Fnproject.Fn.Fdk;

using System.Runtime.CompilerServices;
namespace Function {
class Greeter {
public string greet(string input) {
return string.Format("Hello {0}!",
string.IsNullOrEmpty(input) ? "World" : input.Trim());
}

static void Main(string[] args) { Fdk.Handle(args[0]); }
}
}
11 changes: 11 additions & 0 deletions samples/helloworld/dotnet/HelloWorld.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Fnproject.Fn.Fdk" Version="1.0.4" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions samples/helloworld/dotnet/func.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
schema_version: 20180708
name: hello-dotnet
version: 0.0.4
runtime: dotnet3.1
build_image: fnproject/dotnet:3.1-1.0.4-dev
run_image: fnproject/dotnet:3.1-1.0.4
cmd: Function:Greeter:greet
entrypoint: dotnet HelloWorld.dll
29 changes: 29 additions & 0 deletions samples/oci-adb-client-runsql-dotnet/Common/DBClientHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

using System;
using System.Threading.Tasks;
using System.Text;

using Oci.Common;
using Oci.Common.Auth;
using Oci.DatabaseService;

namespace RunSQL
{
public class DBClientHelper
{
public static DatabaseClient GetDBClient()
{
try
{
return new DatabaseClient(ResourcePrincipalAuthenticationDetailsProvider.GetProvider(), new ClientConfiguration());
}
catch (Exception ex)
{
Console.WriteLine("Unable To Create Resource Principal Provider : {0}", ex.Message);
Console.WriteLine("Defaulting to Instance Provider");
return new DatabaseClient(new InstancePrincipalsAuthenticationDetailsProvider(), new ClientConfiguration());
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

using System;
using System.Linq;
using System.Threading.Tasks;
using System.Text;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using Oci.Common.Model;
using Oci.Common;
using Oci.Common.Auth;
using Oci.DatabaseService;
using Oci.DatabaseService.Models;
using Oci.DatabaseService.Requests;
using Oci.DatabaseService.Responses;


namespace RunSQL
{
public class GenerateDBWalletHelper
{

public static string RandomString(int length)
{
const string pool = "abcdefghijklmnopqrstuvwxyz0123456789#%^$@";
Random random = new Random();
var chars = Enumerable.Range(0, length)
.Select(x => pool[random.Next(0, pool.Length)]);
return new string(chars.ToArray());
}

public static string GenerateWalletPassword(int length)
{
Random ran = new Random();
String b = "abcdefghijklmnopqrstuvwxyz0123456789";
String sc = "!@#$%^&*~";
String random = "";
for (int i = 0; i < length; i++)
{
int a = ran.Next(b.Length);
random = random + b.ElementAt(a);
}
for (int j = 0; j < 2; j++)
{
int sz = ran.Next(sc.Length);
random = random + sc.ElementAt(sz);
}
return random;
}
public static async Task<string> GenWallet(DatabaseClient client, string adb_ocid, string extractPath)

{

try
{
var wallet_password = GenerateWalletPassword(10);

Console.WriteLine("Inside GenWallet Method");
var generateAutonomousDatabaseWalletDetails = new Oci.DatabaseService.Models.GenerateAutonomousDatabaseWalletDetails
{
GenerateType = Oci.DatabaseService.Models.GenerateAutonomousDatabaseWalletDetails.GenerateTypeEnum.Single,
Password = wallet_password
};

var generateAutonomousDatabaseWalletRequest = new Oci.DatabaseService.Requests.GenerateAutonomousDatabaseWalletRequest
{
AutonomousDatabaseId = adb_ocid,
GenerateAutonomousDatabaseWalletDetails = generateAutonomousDatabaseWalletDetails,
};

var response = await client.GenerateAutonomousDatabaseWallet(generateAutonomousDatabaseWalletRequest);

using (var memoryStream = new MemoryStream())
{

response.InputStream.CopyTo(memoryStream);
Console.WriteLine("Generating zip file...");
var fileName = $"gen_wallet.zip";
string zipPath = Path.Combine(extractPath + "/" + fileName);
Console.WriteLine("Wallet location : {0}", zipPath);
using (var fs = new FileStream(zipPath, FileMode.Create, FileAccess.Write))
{
memoryStream.WriteTo(fs);
}
Console.WriteLine("extracting : {0} to {1}", zipPath, extractPath);

using (ZipArchive source = ZipFile.Open(zipPath, ZipArchiveMode.Read, null))
{
foreach (ZipArchiveEntry entry in source.Entries)
{
string fullPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName));

if (Path.GetFileName(fullPath).Length != 0)
{
entry.ExtractToFile(fullPath, true);
}
}
}

}
return "success";


}

catch (OciException ex)
{
Console.WriteLine("Unable To Generate wallet : {0}", ex.Message);
return "Failed " + ex.Message;
}

}


}
}
12 changes: 12 additions & 0 deletions samples/oci-adb-client-runsql-dotnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM fnproject/dotnet:3.1-1.0.4-dev as build-stage
WORKDIR /function
COPY . .
RUN dotnet sln add RunSQL.csproj
RUN dotnet build RunSQL.csproj -c Release
RUN dotnet publish RunSQL.csproj -c Release -o out
FROM fnproject/dotnet:3.1-1.0.4
WORKDIR /function
COPY --from=build-stage /function/out/ /function/
ENV TNS_ADMIN=/tmp
ENTRYPOINT ["dotnet", "RunSQL.dll"]
CMD ["RunSQL:Function:function_handler"]
17 changes: 17 additions & 0 deletions samples/oci-adb-client-runsql-dotnet/Function.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions samples/oci-adb-client-runsql-dotnet/Models/InputMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace RunSQL
{

class InputMessage
{
public string sql { get; set; }


}

}
18 changes: 18 additions & 0 deletions samples/oci-adb-client-runsql-dotnet/Models/OutputMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
// using System.Collections;
// using System.Collections.Specialized;

namespace RunSQL
{

class OutputDetails
{
public string sql { get; set; }

public List<Dictionary<string, string>> result { get; set; }

}


}
Loading