Skip to content

Commit

Permalink
Merge 0403d94 into 6b50822
Browse files Browse the repository at this point in the history
  • Loading branch information
leefine02 committed May 21, 2024
2 parents 6b50822 + 0403d94 commit 6b5648c
Show file tree
Hide file tree
Showing 30 changed files with 500 additions and 841 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/keyfactor-merge-store-types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Keyfactor Merge Cert Store Types
on: [workflow_dispatch]

jobs:
get-manifest-properties:
runs-on: windows-latest
outputs:
update_catalog: ${{ steps.read-json.outputs.update_catalog }}
integration_type: ${{ steps.read-json.outputs.integration_type }}
steps:
- uses: actions/checkout@v3
- name: Store json
id: read-json
shell: pwsh
run: |
$json = Get-Content integration-manifest.json | ConvertFrom-Json
$myvar = $json.update_catalog
echo "update_catalog=$myvar" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
$myvar = $json.integration_type
echo "integration_type=$myvar" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
call-update-store-types-workflow:
needs: get-manifest-properties
if: needs.get-manifest-properties.outputs.integration_type == 'orchestrator' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
uses: Keyfactor/actions/.github/workflows/update-store-types.yml@main
secrets:
token: ${{ secrets.UPDATE_STORE_TYPES }}
13 changes: 10 additions & 3 deletions .github/workflows/keyfactor-starter-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@ jobs:
call-create-github-release-workflow:
uses: Keyfactor/actions/.github/workflows/github-release.yml@main

call-assign-from-json-workflow:
uses: Keyfactor/actions/.github/workflows/assign-env-from-json.yml@main

call-dotnet-build-and-release-workflow:
needs: [call-create-github-release-workflow]
needs: [call-create-github-release-workflow, call-assign-from-json-workflow]
uses: Keyfactor/actions/.github/workflows/dotnet-build-and-release.yml@main
with:
release_version: ${{ needs.call-create-github-release-workflow.outputs.release_version }}
release_url: ${{ needs.call-create-github-release-workflow.outputs.release_url }}
release_dir: GcpCertManager/bin/Release/netcoreapp3.1 # TODO: set build output directory to upload as a release, relative to checkout workspace
release_dir: ${{ needs.call-assign-from-json-workflow.outputs.release_dir }}

secrets:
token: ${{ secrets.PRIVATE_PACKAGE_ACCESS }}

call-generate-readme-workflow:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: Keyfactor/actions/.github/workflows/generate-readme.yml@main
secrets:
token: ${{ secrets.APPROVE_README_PUSH }}

call-update-catalog-workflow:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: call-assign-from-json-workflow
if: needs.call-assign-from-json-workflow.outputs.update_catalog == 'True' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
uses: Keyfactor/actions/.github/workflows/update-catalog.yml@main
secrets:
token: ${{ secrets.SDK_SYNC_PAT }}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
v1.0.2
- Initial Version
10 changes: 2 additions & 8 deletions GcpCertManager.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GcpCertManager", "GcpCertManager\GcpCertManager.csproj", "{33FBC5A1-3466-4F10-B9A6-7186F804A65A}"
EndProject
Expand All @@ -13,8 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "images", "images", "{6302034E-DF8C-4B65-AC36-CED24C068999}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GcpCertManagerTestConsole", "GcpCertManagerTestConsole\GcpCertManagerTestConsole.csproj", "{FFF21E91-1820-4090-922B-A78D5CC38D7B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -25,10 +23,6 @@ Global
{33FBC5A1-3466-4F10-B9A6-7186F804A65A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33FBC5A1-3466-4F10-B9A6-7186F804A65A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33FBC5A1-3466-4F10-B9A6-7186F804A65A}.Release|Any CPU.Build.0 = Release|Any CPU
{FFF21E91-1820-4090-922B-A78D5CC38D7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FFF21E91-1820-4090-922B-A78D5CC38D7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFF21E91-1820-4090-922B-A78D5CC38D7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FFF21E91-1820-4090-922B-A78D5CC38D7B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
51 changes: 44 additions & 7 deletions GcpCertManager/Client/GcpCertificateManagerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,44 @@
using Google.Apis.Auth.OAuth2;
using Google.Apis.CertificateManager.v1;
using Google.Apis.Services;
using Google.Apis.Iam.v1;
using Google.Apis.Iam.v1.Data;
using System.Text;
using System;

using Keyfactor.Logging;
using Microsoft.Extensions.Logging;


namespace Keyfactor.Extensions.Orchestrator.GcpCertManager.Client
{
public class GcpCertificateManagerClient
{
public CertificateManagerService GetGoogleCredentials(string credentialFileName)
{
ILogger _logger = LogHandler.GetClassLogger<CertificateManagerService>();

//Credentials file needs to be in the same location of the executing assembly
var strExeFilePath = Assembly.GetExecutingAssembly().Location;
var strWorkPath = Path.GetDirectoryName(strExeFilePath);
var strSettingsJsonFilePath = Path.Combine(strWorkPath ?? string.Empty, credentialFileName);
GoogleCredential credentials;

var stream = new FileStream(strSettingsJsonFilePath,
FileMode.Open
);
if (!string.IsNullOrEmpty(credentialFileName))
{
_logger.LogDebug("Has credential file name");
var strExeFilePath = Assembly.GetExecutingAssembly().Location;
var strWorkPath = Path.GetDirectoryName(strExeFilePath);
var strSettingsJsonFilePath = Path.Combine(strWorkPath ?? string.Empty, credentialFileName);

var credentials = GoogleCredential.FromStream(stream);
var stream = new FileStream(strSettingsJsonFilePath,
FileMode.Open
);

credentials = GoogleCredential.FromStream(stream);
}
else
{
_logger.LogDebug("No credential file name");
credentials = GoogleCredential.GetApplicationDefaultAsync().Result;
}

var service = new CertificateManagerService(new BaseClientService.Initializer
{
Expand All @@ -28,5 +49,21 @@ public CertificateManagerService GetGoogleCredentials(string credentialFileName)

return service;
}

public ServiceAccountKey CreateServiceAccountKey(string serviceAccountEmail)
{
GoogleCredential credential = GoogleCredential.GetApplicationDefault().CreateScoped(IamService.Scope.CloudPlatform);
IamService service = new IamService(new IamService.Initializer
{
HttpClientInitializer = credential
});

var key = service.Projects.ServiceAccounts.Keys.Create(new CreateServiceAccountKeyRequest(), "projects/-/serviceAccounts/" + serviceAccountEmail).Execute();

byte[] valueBytes = System.Convert.FromBase64String(key.PrivateKeyData);
string jsonKeyContent = Encoding.UTF8.GetString(valueBytes);

return key;
}
}
}
4 changes: 2 additions & 2 deletions GcpCertManager/GcpCertManager.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Keyfactor.Extensions.Orchestrator.GcpCertManager</RootNamespace>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
Expand All @@ -18,12 +19,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Google.Apis.Auth" Version="1.57.0" />
<PackageReference Include="Google.Apis.CertificateManager.v1" Version="1.57.0.2653" />
<PackageReference Include="Google.Apis.Iam.v1" Version="1.68.0.3395" />
<PackageReference Include="Google.Protobuf" Version="3.20.1" />
<PackageReference Include="Keyfactor.Logging" Version="1.1.1" />
<PackageReference Include="Keyfactor.Orchestrators.IOrchestratorJobExtensions" Version="0.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="RestSharp" Version="107.2.1" />
<PackageReference Include="System.Management.Automation" Version="7.0.5" />
Expand Down
Loading

0 comments on commit 6b5648c

Please sign in to comment.