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
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup .NET Core ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.100
dotnet-version: 9.0.203
- name: Build
run: dotnet build -c Debug

Expand All @@ -44,10 +44,10 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.100
dotnet-version: 9.0.203
- name: Build
run: |
dotnet publish ./src/Heimdallr.Cli/Heimdallr.Cli.csproj -c Release --self-contained -r ${{ matrix.rid }} -p:PublishSingleFile=true -p:PublishTrimmed=true -o ./bin/Heimdallr.Cli-${{ matrix.rid }}
dotnet publish ./src/Heimdallr.Cli/Heimdallr.Cli.csproj -c Release --self-contained -r ${{ matrix.rid }} -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false -o ./bin/Heimdallr.Cli-${{ matrix.rid }}
zip -r ${{ matrix.rid }} ./bin/Heimdallr.Cli-${{ matrix.rid }}
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
Expand Down Expand Up @@ -76,14 +76,14 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.100
dotnet-version: 9.0.203
- name: Setup NodeJs
uses: actions/setup-node@v1
with:
node-version: '14'
node-version: '20'
- name: Build
run: |
dotnet publish ./src/Heimdallr.Host/Heimdallr.Host.csproj -c Release --self-contained -r ${{ matrix.rid }} -p:PublishSingleFile=true -p:PublishTrimmed=true -o ./bin/Heimdallr.Host-${{ matrix.rid }}
dotnet publish ./src/Heimdallr.Host/Heimdallr.Host.csproj -c Release --self-contained -r ${{ matrix.rid }} -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false -o ./bin/Heimdallr.Host-${{ matrix.rid }}
zip -r ${{ matrix.rid }} ./bin/Heimdallr.Host-${{ matrix.rid }}
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ WORKDIR /src
COPY . /src
RUN echo $(git describe --tags --always 2>/dev/null) > /version

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
COPY . /build
COPY --from=version /version /build/version
WORKDIR /build
RUN apt-get update -yq ;\
apt-get install curl gnupg -yq ;\
curl -sL https://deb.nodesource.com/setup_14.x | bash - ;\
curl -sL https://deb.nodesource.com/setup_20.x | bash - ;\
apt-get install -y nodejs

RUN sed -i -e "s/<Version>0-develop<\/Version>/<Version>$(cat version | cut -c2- )<\/Version>/g" src/Heimdallr.Host/Heimdallr.Host.csproj;\
Expand All @@ -21,8 +21,9 @@ RUN sed -i -e "s/<Version>0-develop<\/Version>/<Version>$(cat version | cut -c2-


######## Heimdallr Host
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim as Heimdallr
FROM mcr.microsoft.com/dotnet/aspnet:9.0-bookworm-slim as Heimdallr
COPY --from=build /app /Heimdallr
WORKDIR /Heimdallr
EXPOSE 80
ENV ASPNETCORE_URLS=http://*:80
ENTRYPOINT ["dotnet", "Heimdallr.Host.dll"]
79 changes: 39 additions & 40 deletions src/Heimdallr.Cli/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
using CommandLine;

namespace Heimdallr.Cli
namespace Heimdallr.Cli;

/// <summary>
/// Heimdallr CLI password generate configuration
/// </summary>
public class Configuration
{
/// <summary>
/// Heimdallr CLI password generate configuration
/// </summary>
public class Configuration
{
[Option('s', "service",
Required = true,
HelpText = "Service name for which the password is generated")]
public string ServiceName { get; set; }

[Option('n',"name",
Required = true,
HelpText = "Service account or password ID")]
public string CommonName { get; set; }

[Option('p',"mpwd",
HelpText = "Master password to generate an idempotent password based on the service name and common name and the dictionary used")]
public string MasterPassword { get; set; }

[Option(Default = true,
HelpText = "Numeric dictionary for password generation")]
public bool? HasNumeric { get; set; }

[Option(Default = true,
HelpText = "Letter dictionary for password generation")]
public bool? HasLetters { get; set; }

[Option(Default = true,
HelpText = "Symbolic dictionary for password generation")]
public bool? HasSpecialSymbols { get; set; }

[Option('l', Default = 16,
HelpText = "Length of generated password")]
public int Length { get; set; }

[Option('v', Default = 1,
HelpText = "Password version (if you need a new password for the same service and account)")]
public int Version { get; set; }
}
[Option('s', "service",
Required = true,
HelpText = "Service name for which the password is generated")]
public string ServiceName { get; set; }

[Option('n',"name",
Required = true,
HelpText = "Service account or password ID")]
public string CommonName { get; set; }

[Option('p',"mpwd",
HelpText = "Master password to generate an idempotent password based on the service name and common name and the dictionary used")]
public string MasterPassword { get; set; }

[Option(Default = true,
HelpText = "Numeric dictionary for password generation")]
public bool? HasNumeric { get; set; }

[Option(Default = true,
HelpText = "Letter dictionary for password generation")]
public bool? HasLetters { get; set; }

[Option(Default = true,
HelpText = "Symbolic dictionary for password generation")]
public bool? HasSpecialSymbols { get; set; }

[Option('l', Default = 16,
HelpText = "Length of generated password")]
public int Length { get; set; }

[Option('v', Default = 1,
HelpText = "Password version (if you need a new password for the same service and account)")]
public int Version { get; set; }
}
4 changes: 2 additions & 2 deletions src/Heimdallr.Cli/Heimdallr.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Authors>Klabukov Erik</Authors>
<Product>Heimdallr</Product>
<Description>Heimdallr - password generator</Description>
Expand All @@ -16,7 +16,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
<PackageReference Include="PanoramicData.ConsoleExtensions" Version="1.0.1" />
</ItemGroup>

Expand Down
47 changes: 23 additions & 24 deletions src/Heimdallr.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,36 @@
using PanoramicData.ConsoleExtensions;
using System;

namespace Heimdallr.Cli
namespace Heimdallr.Cli;

public class Program
{
public class Program
public static void Main(string[] args)
{
public static void Main(string[] args)
{
Parser.Default.ParseArguments<Configuration>(args)
.WithParsed(Run);
}
Parser.Default.ParseArguments<Configuration>(args)
.WithParsed(Run);
}

public static void Run(Configuration config)
{
var container = ProgramExtensions.ConfigureApp(services => services.AddScryptModule());
var passwordService = container.GetPasswordService();
public static void Run(Configuration config)
{
var container = ProgramExtensions.ConfigureApp(services => services.AddScryptModule());
var passwordService = container.GetPasswordService();

if (string.IsNullOrEmpty(config.MasterPassword))
{
Console.Write("Master Password:");
config.MasterPassword = ConsolePlus.ReadPassword();
Console.WriteLine();
}
if (string.IsNullOrEmpty(config.MasterPassword))
{
Console.Write("Master Password:");
config.MasterPassword = ConsolePlus.ReadPassword();
Console.WriteLine();
}

var securityRequest = config.ToSecurityRequest();
var securityRequest = config.ToSecurityRequest();

securityRequest.Validate();
securityRequest.Validate();

var password = passwordService.Generate(securityRequest)
.GetAwaiter()
.GetResult();
var password = passwordService.Generate(securityRequest)
.GetAwaiter()
.GetResult();

Console.WriteLine(password.GeneratedPassword);
}
Console.WriteLine(password.GeneratedPassword);
}
}
63 changes: 31 additions & 32 deletions src/Heimdallr.Cli/ProgramExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,43 @@
using System;
using System.ComponentModel.DataAnnotations;

namespace Heimdallr.Cli
namespace Heimdallr.Cli;

public static class ProgramExtensions
{
public static class ProgramExtensions
public static IServiceProvider ConfigureApp(Action<IServiceCollection> buildAction)
{
public static IServiceProvider ConfigureApp(Action<IServiceCollection> buildAction)
{
var collection = new ServiceCollection();
buildAction?.Invoke(collection);
return collection.BuildServiceProvider().CreateScope().ServiceProvider;
}

public static IPasswordService GetPasswordService(this IServiceProvider provider)
{
return provider.GetService<IPasswordService>();
}
var collection = new ServiceCollection();
buildAction?.Invoke(collection);
return collection.BuildServiceProvider().CreateScope().ServiceProvider;
}

public static SecurityRequest ToSecurityRequest(this Configuration config)
{
return new SecurityRequest
{
ServiceName = config.ServiceName,
CommonName = config.CommonName,
HasLetters = config?.HasLetters ?? true,
HasNumeric = config?.HasNumeric ?? true,
HasSpecialSymbols = config?.HasSpecialSymbols ?? true,
MasterPassword = config.MasterPassword,
Length = config.Length,
Version = config.Version
};
}
public static IPasswordService GetPasswordService(this IServiceProvider provider)
{
return provider.GetService<IPasswordService>();
}

public static void Validate(this object validateObject)
public static SecurityRequest ToSecurityRequest(this Configuration config)
{
return new SecurityRequest
{
if (!(validateObject is IValidatableObject)) return;
ServiceName = config.ServiceName,
CommonName = config.CommonName,
HasLetters = config?.HasLetters ?? true,
HasNumeric = config?.HasNumeric ?? true,
HasSpecialSymbols = config?.HasSpecialSymbols ?? true,
MasterPassword = config.MasterPassword,
Length = config.Length,
Version = config.Version
};
}

var ctx = new ValidationContext(validateObject);
Validator.ValidateObject(validateObject, ctx, true);
}
public static void Validate(this object validateObject)
{
if (!(validateObject is IValidatableObject)) return;

var ctx = new ValidationContext(validateObject);
Validator.ValidateObject(validateObject, ctx, true);
}

}
Loading