Skip to content

Commit 9bad561

Browse files
authored
Merge pull request #9 from Keyfactor/release-1.0
1.0.2 to main
2 parents a04a6f0 + 87cb72d commit 9bad561

30 files changed

+484
-863
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Keyfactor Bootstrap Workflow
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types: [opened, closed, synchronize, edited, reopened]
7+
push:
8+
create:
9+
branches:
10+
- 'release-*.*'
11+
12+
jobs:
13+
call-starter-workflow:
14+
uses: keyfactor/actions/.github/workflows/starter.yml@v2
15+
secrets:
16+
token: ${{ secrets.V2BUILDTOKEN}}
17+
APPROVE_README_PUSH: ${{ secrets.APPROVE_README_PUSH}}
18+
gpg_key: ${{ secrets.KF_GPG_PRIVATE_KEY }}
19+
gpg_pass: ${{ secrets.KF_GPG_PASSPHRASE }}

.github/workflows/keyfactor-starter-workflow.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
v1.0.2
2+
- Initial Public Version

GcpCertManager.sln

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30717.126
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32929.385
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GcpCertManager", "GcpCertManager\GcpCertManager.csproj", "{33FBC5A1-3466-4F10-B9A6-7186F804A65A}"
77
EndProject
@@ -13,8 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1313
EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "images", "images", "{6302034E-DF8C-4B65-AC36-CED24C068999}"
1515
EndProject
16-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GcpCertManagerTestConsole", "GcpCertManagerTestConsole\GcpCertManagerTestConsole.csproj", "{FFF21E91-1820-4090-922B-A78D5CC38D7B}"
17-
EndProject
1816
Global
1917
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2018
Debug|Any CPU = Debug|Any CPU
@@ -25,10 +23,6 @@ Global
2523
{33FBC5A1-3466-4F10-B9A6-7186F804A65A}.Debug|Any CPU.Build.0 = Debug|Any CPU
2624
{33FBC5A1-3466-4F10-B9A6-7186F804A65A}.Release|Any CPU.ActiveCfg = Release|Any CPU
2725
{33FBC5A1-3466-4F10-B9A6-7186F804A65A}.Release|Any CPU.Build.0 = Release|Any CPU
28-
{FFF21E91-1820-4090-922B-A78D5CC38D7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29-
{FFF21E91-1820-4090-922B-A78D5CC38D7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
30-
{FFF21E91-1820-4090-922B-A78D5CC38D7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
31-
{FFF21E91-1820-4090-922B-A78D5CC38D7B}.Release|Any CPU.Build.0 = Release|Any CPU
3226
EndGlobalSection
3327
GlobalSection(SolutionProperties) = preSolution
3428
HideSolutionNode = FALSE

GcpCertManager/Client/GcpCertificateManagerClient.cs

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,44 @@
33
using Google.Apis.Auth.OAuth2;
44
using Google.Apis.CertificateManager.v1;
55
using Google.Apis.Services;
6+
using Google.Apis.Iam.v1;
7+
using Google.Apis.Iam.v1.Data;
8+
using System.Text;
9+
using System;
10+
11+
using Keyfactor.Logging;
12+
using Microsoft.Extensions.Logging;
13+
614

715
namespace Keyfactor.Extensions.Orchestrator.GcpCertManager.Client
816
{
917
public class GcpCertificateManagerClient
1018
{
1119
public CertificateManagerService GetGoogleCredentials(string credentialFileName)
1220
{
21+
ILogger _logger = LogHandler.GetClassLogger<CertificateManagerService>();
22+
1323
//Credentials file needs to be in the same location of the executing assembly
14-
var strExeFilePath = Assembly.GetExecutingAssembly().Location;
15-
var strWorkPath = Path.GetDirectoryName(strExeFilePath);
16-
var strSettingsJsonFilePath = Path.Combine(strWorkPath ?? string.Empty, credentialFileName);
24+
GoogleCredential credentials;
1725

18-
var stream = new FileStream(strSettingsJsonFilePath,
19-
FileMode.Open
20-
);
26+
if (!string.IsNullOrEmpty(credentialFileName))
27+
{
28+
_logger.LogDebug("Has credential file name");
29+
var strExeFilePath = Assembly.GetExecutingAssembly().Location;
30+
var strWorkPath = Path.GetDirectoryName(strExeFilePath);
31+
var strSettingsJsonFilePath = Path.Combine(strWorkPath ?? string.Empty, credentialFileName);
2132

22-
var credentials = GoogleCredential.FromStream(stream);
33+
var stream = new FileStream(strSettingsJsonFilePath,
34+
FileMode.Open
35+
);
36+
37+
credentials = GoogleCredential.FromStream(stream);
38+
}
39+
else
40+
{
41+
_logger.LogDebug("No credential file name");
42+
credentials = GoogleCredential.GetApplicationDefaultAsync().Result;
43+
}
2344

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

2950
return service;
3051
}
52+
53+
public ServiceAccountKey CreateServiceAccountKey(string serviceAccountEmail)
54+
{
55+
GoogleCredential credential = GoogleCredential.GetApplicationDefault().CreateScoped(IamService.Scope.CloudPlatform);
56+
IamService service = new IamService(new IamService.Initializer
57+
{
58+
HttpClientInitializer = credential
59+
});
60+
61+
var key = service.Projects.ServiceAccounts.Keys.Create(new CreateServiceAccountKeyRequest(), "projects/-/serviceAccounts/" + serviceAccountEmail).Execute();
62+
63+
byte[] valueBytes = System.Convert.FromBase64String(key.PrivateKeyData);
64+
string jsonKeyContent = Encoding.UTF8.GetString(valueBytes);
65+
66+
return key;
67+
}
3168
}
3269
}

GcpCertManager/GcpCertManager.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
45
<TargetFramework>netcoreapp3.1</TargetFramework>
56
<RootNamespace>Keyfactor.Extensions.Orchestrator.GcpCertManager</RootNamespace>
67
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
@@ -18,12 +19,11 @@
1819
</ItemGroup>
1920

2021
<ItemGroup>
21-
<PackageReference Include="Google.Apis.Auth" Version="1.57.0" />
2222
<PackageReference Include="Google.Apis.CertificateManager.v1" Version="1.57.0.2653" />
23+
<PackageReference Include="Google.Apis.Iam.v1" Version="1.68.0.3395" />
2324
<PackageReference Include="Google.Protobuf" Version="3.20.1" />
2425
<PackageReference Include="Keyfactor.Logging" Version="1.1.1" />
2526
<PackageReference Include="Keyfactor.Orchestrators.IOrchestratorJobExtensions" Version="0.6.0" />
26-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2727
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
2828
<PackageReference Include="RestSharp" Version="107.2.1" />
2929
<PackageReference Include="System.Management.Automation" Version="7.0.5" />

0 commit comments

Comments
 (0)