Skip to content

Commit

Permalink
Merge pull request #9 from Infisical/daniel/csharp-sdk
Browse files Browse the repository at this point in the history
Feat: .NET SDK (breaking change for Java)
  • Loading branch information
DanielHougaard authored Jan 8, 2024
2 parents 984641c + 274e9fa commit 9bdbae0
Show file tree
Hide file tree
Showing 17 changed files with 515 additions and 10 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/generate-schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ jobs:
path: ${{ github.workspace }}/languages/node/src/infisical_client/schemas.ts
if-no-files-found: error

# - name: Upload CSharp schemas artifact
# uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
# with:
# name: schemas.cs
# path: ${{ github.workspace }}/languages/csharp/Infisical.Sdk/schemas.cs
# if-no-files-found: error
- name: Upload CSharp schemas artifact
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: schemas.cs
path: ${{ github.workspace }}/languages/csharp/Infisical.Sdk/schemas.cs
if-no-files-found: error

- name: Upload Python schemas artifact
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
Expand Down
83 changes: 83 additions & 0 deletions .github/workflows/release-dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Release .NET SDK
run-name: Release .NET SDK

on:
push:
tags:
- "*.*.*" # version, e.g. 1.0.0

jobs:
generate_schemas:
uses: ./.github/workflows/generate-schemas.yml

build_rust:
uses: ./.github/workflows/build-c-bindings.yml

test-rust-crate:
uses: ./.github/workflows/rust-test.yml

build_dotnet:
name: Build .NET
runs-on: ubuntu-22.04
needs:
- test-rust-crate
- generate_schemas
- build_rust

steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Download C# schemas artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: schemas.cs
path: languages/csharp/Infisical.Sdk

- name: Set up .NET Core
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
with:
global-json-file: languages/csharp/global.json

- name: Download x86_64-apple-darwin files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libinfisical_c_files-x86_64-apple-darwin
path: languages/csharp/Infisical.Sdk/macos-x64

- name: Download aarch64-apple-darwin files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libinfisical_c_files-aarch64-apple-darwin
path: languages/csharp/Infisical.Sdk/macos-arm64

- name: Download x86_64-unknown-linux-gnu files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libinfisical_c_files-x86_64-unknown-linux-gnu
path: languages/csharp/Infisical.Sdk/ubuntu-x64

- name: Download x86_64-pc-windows-msvc files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libinfisical_c_files-x86_64-pc-windows-msvc
path: languages/csharp/Infisical.Sdk/windows-x64

- name: Build .NET 8 Project
working-directory: languages/csharp/Infisical.Sdk
run: |
dotnet restore
dotnet build --configuration Release
- name: Pack NuGet Package
env:
VERSION: ${{ github.ref_name }}
run: dotnet pack --configuration Release -p:PackageID=Infisical.Sdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n
working-directory: languages/csharp/Infisical.Sdk

- name: Upload NuGet package
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: Infisical.Sdk.${{github.ref_name}}.nupkg
path: |
./languages/csharp/Infisical.Sdk/nuget-output/*.nupkg
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,9 @@ languages/java/src/main/java/com/infisical/sdk/schema/*.java
languages/java/build
languages/java/.gradle
languages/java/src/main/resources/*
infisical-sdk.sln

languages/csharp/Infisical.Sdk/obj/**/*
languages/csharp/Infisical.Sdk/bin/**/*
languages/csharp/Infisical.Sdk.Samples/obj/**/*
languages/csharp/Infisical.Sdk.Samples/bin/**/*
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"./crates/infisical-py/Cargo.toml"
],
"cSpell.words": [
"Cdecl",
"ciphertext",
"dotenv",
"indicies",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Infisical.Sdk\Infisical.Sdk.csproj" />
</ItemGroup>

</Project>
54 changes: 54 additions & 0 deletions languages/csharp/Infisical.Sdk.Samples/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace Infisical.Sdk.Samples;


using Infisical.Sdk;



internal class Program
{
private static void Main(string[] args)
{

ClientSettings settings = new ClientSettings
{
ClientId = "Test"
};


using var infisicalClient = new InfisicalClient(settings);

var key = infisicalClient.createSymmetricKey();

Console.WriteLine($"Key: {key}");


EncryptSymmetricOptions options = new EncryptSymmetricOptions
{
Key = key,
Plaintext = "Hello World!"
};

var encrypted = infisicalClient.encryptSymmetric(options);

Console.WriteLine($"Encrypted: {encrypted.Ciphertext}");



DecryptSymmetricOptions decryptOptions = new DecryptSymmetricOptions
{
Key = key,
Ciphertext = encrypted.Ciphertext,
Iv = encrypted.Iv,
Tag = encrypted.Tag
};

var decrypted = infisicalClient.decryptSymmetric(decryptOptions);

Console.WriteLine($"Decrypted: {decrypted}");




}
}
20 changes: 20 additions & 0 deletions languages/csharp/Infisical.Sdk/CommandRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json;

namespace Infisical.Sdk;

internal class CommandRunner
{
private readonly InfisicalHandle _handle;

internal CommandRunner(InfisicalHandle handle)
{
_handle = handle;
}

internal T? RunCommand<T>(Command command)
{
var req = JsonSerializer.Serialize(command, Converter.Settings);
var result = InfisicalLibrary.RunCommand(req, _handle);
return JsonSerializer.Deserialize<T>(result, Converter.Settings);
}
}
76 changes: 76 additions & 0 deletions languages/csharp/Infisical.Sdk/Infisical.Sdk.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Infisical.Sdk</RootNamespace>

<Title>Infisical SDK</Title>
<Authors>Infisical</Authors>
<Description>.NET SDK for Infisical</Description>
<Copyright>Infisical</Copyright>
<Product>SDK</Product>

<RepositoryUrl>https://github.com/infisical/sdk/tree/master/languages/csharp</RepositoryUrl>
<RepositoryType>Git</RepositoryType>

<PackageProjectUrl>https://infisical.com</PackageProjectUrl>
<PackageId>Infisical.Sdk</PackageId>
<PackageIcon>infisical.png</PackageIcon>
<PackageTags>Infisical;Sdk;.NET</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="7.0.3" />
<None Include="infisical.png" Pack="true" PackagePath="\" />
<None Include="../README.md" Pack="true" PackagePath="\" />
<None Include="../LICENSE.txt" Pack="true" PackagePath="\" />
</ItemGroup>

<PropertyGroup>
<!--Debugonly-->
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug||AnyCPU' ">
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<Content Include="../../../target/debug/libinfisical_c*.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
<Content Include="../../../target/debug/libinfisical*.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
<Content Include="../../../target/debug/infisical_c*.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Release'">
<Content Include="macos-x64/libinfisical*.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
<PackagePath>runtimes/osx-x64/native</PackagePath>
</Content>
<Content Include="macos-arm64/libinfisical*.dylib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
<PackagePath>runtimes/osx-arm64/native</PackagePath>
</Content>
<Content Include="ubuntu-x64/libinfisical*.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
<PackagePath>runtimes/linux-x64/native</PackagePath>
</Content>
<Content Include="windows-x64/infisical_c*.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
<PackagePath>runtimes/win-x64/native</PackagePath>
</Content>
</ItemGroup>
</Project>
Loading

0 comments on commit 9bdbae0

Please sign in to comment.