Skip to content

Commit

Permalink
Merge pull request #11 from nizanrosh/feature/auto-update
Browse files Browse the repository at this point in the history
Feature/auto update
  • Loading branch information
nizanrosh authored Dec 28, 2022
2 parents 3578ff7 + abb9d72 commit c52db11
Show file tree
Hide file tree
Showing 52 changed files with 1,106 additions and 222 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionPrefix>1.2.1</VersionPrefix>
<VersionPrefix>1.3.0</VersionPrefix>
<LangVersion>latest</LangVersion>

<Authors>Nizan Rosh</Authors>
Expand Down
Binary file modified installer/Installer
Binary file not shown.
92 changes: 88 additions & 4 deletions installer/Installer.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"Installer/1.2.0": {
"Installer/1.3.0": {
"dependencies": {
"Kurukuru": "1.4.2"
"Kurukuru": "1.4.2",
"Microsoft.Extensions.Configuration": "6.0.0",
"Microsoft.Extensions.Configuration.CommandLine": "6.0.0"
},
"runtime": {
"Installer.dll": {}
Expand All @@ -21,11 +23,58 @@
"fileVersion": "1.4.2.0"
}
}
}
},
"Microsoft.Extensions.Configuration/6.0.0": {
"dependencies": {
"Microsoft.Extensions.Configuration.Abstractions": "6.0.0",
"Microsoft.Extensions.Primitives": "6.0.0"
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Configuration.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
},
"Microsoft.Extensions.Configuration.Abstractions/6.0.0": {
"dependencies": {
"Microsoft.Extensions.Primitives": "6.0.0"
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Configuration.Abstractions.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
},
"Microsoft.Extensions.Configuration.CommandLine/6.0.0": {
"dependencies": {
"Microsoft.Extensions.Configuration": "6.0.0",
"Microsoft.Extensions.Configuration.Abstractions": "6.0.0"
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Configuration.CommandLine.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
},
"Microsoft.Extensions.Primitives/6.0.0": {
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
},
"runtime": {
"lib/net6.0/Microsoft.Extensions.Primitives.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
},
"System.Runtime.CompilerServices.Unsafe/6.0.0": {}
}
},
"libraries": {
"Installer/1.2.0": {
"Installer/1.3.0": {
"type": "project",
"serviceable": false,
"sha512": ""
Expand All @@ -36,6 +85,41 @@
"sha512": "sha512-OpfXP8piJFx8hEG+z2Gw2/VWvj96RkzDvtjfAxJnZRuREDasW8Is9kjwm/E8oXmyq6TjSStBzkSwdAJLlqG3Dg==",
"path": "kurukuru/1.4.2",
"hashPath": "kurukuru.1.4.2.nupkg.sha512"
},
"Microsoft.Extensions.Configuration/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-tq2wXyh3fL17EMF2bXgRhU7JrbO3on93MRKYxzz4JzzvuGSA1l0W3GI9/tl8EO89TH+KWEymP7bcFway6z9fXg==",
"path": "microsoft.extensions.configuration/6.0.0",
"hashPath": "microsoft.extensions.configuration.6.0.0.nupkg.sha512"
},
"Microsoft.Extensions.Configuration.Abstractions/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-qWzV9o+ZRWq+pGm+1dF+R7qTgTYoXvbyowRoBxQJGfqTpqDun2eteerjRQhq5PQ/14S+lqto3Ft4gYaRyl4rdQ==",
"path": "microsoft.extensions.configuration.abstractions/6.0.0",
"hashPath": "microsoft.extensions.configuration.abstractions.6.0.0.nupkg.sha512"
},
"Microsoft.Extensions.Configuration.CommandLine/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-3nL1qCkZ1Oxx14ZTzgo4MmlO7tso7F+TtMZAY2jUAtTLyAcDp+EDjk3RqafoKiNaePyPvvlleEcBxh3b2Hzl1g==",
"path": "microsoft.extensions.configuration.commandline/6.0.0",
"hashPath": "microsoft.extensions.configuration.commandline.6.0.0.nupkg.sha512"
},
"Microsoft.Extensions.Primitives/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-9+PnzmQFfEFNR9J2aDTfJGGupShHjOuGw4VUv+JB044biSHrnmCIMD+mJHmb2H7YryrfBEXDurxQ47gJZdCKNQ==",
"path": "microsoft.extensions.primitives/6.0.0",
"hashPath": "microsoft.extensions.primitives.6.0.0.nupkg.sha512"
},
"System.Runtime.CompilerServices.Unsafe/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==",
"path": "system.runtime.compilerservices.unsafe/6.0.0",
"hashPath": "system.runtime.compilerservices.unsafe.6.0.0.nupkg.sha512"
}
}
}
Binary file modified installer/Installer.dll
Binary file not shown.
Binary file modified installer/Installer.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added installer/Microsoft.Extensions.Configuration.dll
Binary file not shown.
Binary file added installer/Microsoft.Extensions.Primitives.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/Installer/Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<ItemGroup>
<PackageReference Include="Kurukuru" Version="1.4.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 24 additions & 1 deletion src/main/Installer/InstallerHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Diagnostics;
using Microsoft.Extensions.Configuration;

namespace Installer;

Expand Down Expand Up @@ -43,4 +44,26 @@ public static Task MakeOacliExecutable(string path)

return oacliExecutable!.WaitForExitAsync();
}

public static string GetAppPath(IConfiguration configuration)
{
var path = configuration["path"];
if (!string.IsNullOrEmpty(path)) return path;

var installerPath = Directory.GetCurrentDirectory();
var rootFolder = Directory.GetParent(installerPath)?.FullName;
ArgumentNullException.ThrowIfNull(rootFolder, nameof(rootFolder));

var appPath = Path.Combine(rootFolder, "app");

return appPath;
}

public static string GetOutputPath(IConfiguration configuration)
{
var path = configuration["output"];
if (!string.IsNullOrEmpty(path)) return path;

return "app";
}
}
13 changes: 8 additions & 5 deletions src/main/Installer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
using System.Runtime.InteropServices;
using Installer;
using Kurukuru;
using Microsoft.Extensions.Configuration;

Console.WriteLine("Installing okta-aws-cli...\n");

var installerPath = Directory.GetCurrentDirectory();
var rootFolder = Directory.GetParent(installerPath)?.FullName;
ArgumentNullException.ThrowIfNull(rootFolder, nameof(rootFolder));
var configuration = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();

var appPath = Path.Combine(rootFolder, "app");

var appPath = InstallerHelper.GetAppPath(configuration);
var output = InstallerHelper.GetOutputPath(configuration);

await Spinner.StartAsync("Installing...", async spinner =>
{
Expand All @@ -21,7 +24,7 @@ await Spinner.StartAsync("Installing...", async spinner =>
FileName = "dotnet",
WorkingDirectory = "../",
Arguments =
"publish --output app --source https://api.nuget.org/v3/index.json --configuration Release --verbosity quiet"
$"publish --output {output} --source https://api.nuget.org/v3/index.json --configuration Release --verbosity quiet"
});
await process!.WaitForExitAsync();
Expand Down
7 changes: 7 additions & 0 deletions src/main/Installer/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"profiles": {
"Installer": {
"commandName": "Project"
}
}
}
14 changes: 14 additions & 0 deletions src/main/Okta.Aws.Cli/Abstractions/ArnMappings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Okta.Aws.Cli.Abstractions;

public class ArnMappingsWrapper
{
public List<ArnMapping> ArnMappings { get; }

public ArnMappingsWrapper(List<ArnMapping> arnMappings) => ArnMappings = arnMappings;
}

public class ArnMapping
{
public string Key { get; set; }
public string Value { get; set; }
}
17 changes: 17 additions & 0 deletions src/main/Okta.Aws.Cli/Abstractions/OktaAwsCliProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Okta.Aws.Cli.Abstractions;

public class OktaAwsCliProfile
{
public string Key { get; set; }
public string AccessKeyId { get; set; }
public string SecretAccessKey { get; set; }
public string Token { get; set; }
public string Region { get; set; }
}

public class OktaAwsCliProfileWrapper
{
public IEnumerable<OktaAwsCliProfile> Profiles { get; }

public OktaAwsCliProfileWrapper(IEnumerable<OktaAwsCliProfile> profiles) => Profiles = profiles;
}
45 changes: 45 additions & 0 deletions src/main/Okta.Aws.Cli/Aws/ArnMappings/ArnMappingsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Okta.Aws.Cli.Abstractions;
using Okta.Aws.Cli.Helpers;

namespace Okta.Aws.Cli.Aws.ArnMappings;

public class ArnMappingsService : IArnMappingsService
{
private readonly IConfiguration _configuration;
private readonly Dictionary<string, string> _arnMappings;

public ArnMappingsService(IConfiguration configuration)
{
_configuration = configuration;

var rawArnMappings = _configuration.GetSection("ArnMappings").Get<List<ArnMapping>>();
if (rawArnMappings == null)
{
_arnMappings = new Dictionary<string, string>();
}
else
{
_arnMappings = rawArnMappings.ToDictionary(x => x.Key, x => x.Value);
}
}

public Task UpdateArnMappingsFile(CancellationToken cancellationToken)
{
var mappings = _arnMappings.Select(m => new ArnMapping { Key = m.Key, Value = m.Value }).ToList();

var userSettingsFolder = FileHelper.GetUserSettingsFolder(_configuration);
var userSettingsFile = FileHelper.GetArnMappingsFile(_configuration);

if (!Directory.Exists(userSettingsFolder)) Directory.CreateDirectory(userSettingsFolder);

var payload = JsonConvert.SerializeObject(new ArnMappingsWrapper(mappings));
return File.WriteAllTextAsync(userSettingsFile, payload, cancellationToken);
}

public Dictionary<string, string> GetArnMappings()
{
return _arnMappings;
}
}
7 changes: 7 additions & 0 deletions src/main/Okta.Aws.Cli/Aws/ArnMappings/IArnMappingsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Okta.Aws.Cli.Aws.ArnMappings;

public interface IArnMappingsService
{
Task UpdateArnMappingsFile(CancellationToken cancellationToken);
Dictionary<string, string> GetArnMappings();
}
Loading

0 comments on commit c52db11

Please sign in to comment.