Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions .github/workflows/keyfactor-bootstrap-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Keyfactor Bootstrap Workflow

on:
workflow_dispatch:
pull_request:
types: [opened, closed, synchronize, edited, reopened]
push:
create:
branches:
- 'release-*.*'

jobs:
call-starter-workflow:
uses: keyfactor/actions/.github/workflows/starter.yml@v2
secrets:
token: ${{ secrets.V2BUILDTOKEN}}
APPROVE_README_PUSH: ${{ secrets.APPROVE_README_PUSH}}
gpg_key: ${{ secrets.KF_GPG_PRIVATE_KEY }}
gpg_pass: ${{ secrets.KF_GPG_PASSPHRASE }}
26 changes: 0 additions & 26 deletions .github/workflows/keyfactor-starter-workflow.yml

This file was deleted.

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 Public 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