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
14 changes: 6 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# @format

on: [push, pull_request]
on: [push]

jobs:
test:
strategy:
matrix:
otp: ["27.1.2"]
elixir: ["1.18.1"]
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest]
os: [ubuntu-latest, ubuntu-24.04-arm, windows-2022]
# mac is not yet supported by setup-beam
# os: [ ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-latest, macos-13 ]

Expand All @@ -24,15 +24,15 @@ jobs:
- name: Check formatting
run: mix format --check-formatted
# skip on windows because different line endings (LF vs CRLF)
if: matrix.os != 'windows-latest'
if: matrix.os != 'windows-2022'
- run: mix test

test-test_app:
strategy:
matrix:
otp: ["27.1.2"]
elixir: ["1.18.1"]
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest]
os: [ubuntu-latest, ubuntu-24.04-arm, windows-2022]
# mac is not yet supported by setup-beam
# os: [ ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-latest, macos-13 ]

Expand Down Expand Up @@ -60,9 +60,7 @@ jobs:
choco: age.portable

- name: Generate secrets
run: mix secret_mana.gen.key && mix secret_mana.encrypt secrets.json
env:
MIX_ENV: prod
run: mix secret_mana.gen.key prod && mix secret_mana.encrypt prod secrets.json
working-directory: ./test_app

- run: mix release
Expand All @@ -72,7 +70,7 @@ jobs:

- name: Smoke Test app
# skip this on windows, cant figure out to start and curl the server, it simply never responds
if: matrix.os != 'windows-latest'
if: matrix.os != 'windows-2022'
run: |
_build/prod/rel/test_app/bin/test_app start &
curl --connect-timeout 5 --max-time 10 --retry 5 --retry-max-time 40 --retry-connrefused --fail --silent --show-error http://127.0.0.1:4000/api/healthcheck && exit 0
Expand Down
93 changes: 89 additions & 4 deletions lib/mix/tasks/secret_mana.edit.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,96 @@
defmodule Mix.Tasks.SecretMana.Edit do
use Mix.Task

@shortdoc "Edits SecretMana configuration for the given environment"

@moduledoc """
Opens the SecretMana configuration for editing for a given environment.

## Usage

mix secret_mana.edit <env>

Where `<env>` is typically one of:

* dev
* test
* prod

The task will:

* Ensure the `:secret_mana` application is started.
* Build a `SecretMana.Config` for the given environment.
* Invoke `SecretMana.edit/1` with the config.

## Examples

mix secret_mana.edit dev
mix secret_mana.edit prod

## Getting help

You can display this help with:

mix help secret_mana.edit

Or by using:

mix secret_mana.edit --help
mix secret_mana.edit -h
"""

@impl Mix.Task
def run(_) do
Application.ensure_all_started(:secret_mana)
def run(args) do
case parse_args(args) do
{:ok, env} ->
Application.ensure_all_started(:secret_mana)

SecretMana.Config.new(env)
|> SecretMana.edit()

:help ->
print_manual()

{:error, message} ->
Mix.shell().error(message)
Mix.shell().info("")
print_manual()
Mix.raise("secret_mana.edit: invalid arguments")
end
end

defp parse_args(["-h"]), do: :help
defp parse_args(["--help"]), do: :help

defp parse_args([env]) when is_binary(env) and env != "" do
{:ok, env}
end

defp parse_args([]) do
{:error, "Missing required argument: <env>"}
end

defp parse_args(_args) do
{:error, "Too many arguments were provided."}
end

defp print_manual do
Mix.shell().info("""
SecretMana Editor

Usage:
mix secret_mana.edit <env>

Arguments:
<env> The environment whose configuration to edit (e.g. dev, test, prod)

Examples:
mix secret_mana.edit dev
mix secret_mana.edit test
mix secret_mana.edit prod

SecretMana.Config.new()
|> SecretMana.edit()
For more information:
mix help secret_mana.edit
""")
end
end
112 changes: 100 additions & 12 deletions lib/mix/tasks/secret_mana.encrypt.ex
Original file line number Diff line number Diff line change
@@ -1,21 +1,109 @@
defmodule Mix.Tasks.SecretMana.Encrypt do
use Mix.Task

@shortdoc "Encrypts a file using SecretMana for the given environment"

@moduledoc """
Encrypts a file using SecretMana for the given environment.

## Usage

mix secret_mana.encrypt <env> <file>

Where:

* `<env>` is typically one of:
* dev
* test
* prod

* `<file>` is the path to the file you want to encrypt.

The task will:

* Ensure the `:secret_mana` application is started.
* Build a `SecretMana.Config` for the given environment.
* Invoke `SecretMana.encrypt/2` with the config and file path.

## Examples

mix secret_mana.encrypt dev config/secrets.yml
mix secret_mana.encrypt prod priv/secrets.txt

## Getting help

You can show this help via:

mix help secret_mana.encrypt

Or by using:

mix secret_mana.encrypt --help
mix secret_mana.encrypt -h
"""

@impl Mix.Task
def run(args) do
Application.ensure_all_started(:secret_mana)
case parse_args(args) do
{:ok, env, file} ->
Application.ensure_all_started(:secret_mana)

args
|> List.first()
|> then(fn file ->
if file do
SecretMana.Config.new()
SecretMana.Config.new(env)
|> SecretMana.encrypt(file)
else
raise """
Usage: mix secret_mana.encrypt <file>
"""
end
end)

:help ->
print_manual()

{:error, message} ->
Mix.shell().error(message)
Mix.shell().info("")
print_manual()
Mix.raise("secret_mana.encrypt: invalid arguments")
end
end

# Argument parsing

defp parse_args(["-h"]), do: :help
defp parse_args(["--help"]), do: :help

defp parse_args([env, file])
when is_binary(env) and env != "" and is_binary(file) and file != "" do
{:ok, env, file}
end

defp parse_args([_env]) do
{:error, "Missing required argument: <file>"}
end

defp parse_args([]) do
{:error, "Missing required arguments: <env> <file>"}
end

defp parse_args(_args) do
{:error, "Too many arguments were provided."}
end

# Manual / help text

defp print_manual do
Mix.shell().info("""
SecretMana Encrypt

Usage:
mix secret_mana.encrypt <env> <file>

Arguments:
<env> The environment to use (e.g. dev, test, prod)
<file> The path to the file to encrypt

Examples:
mix secret_mana.encrypt dev config/secrets.yml
mix secret_mana.encrypt test priv/credentials.txt
mix secret_mana.encrypt prod priv/secrets.env

For more information:
mix help secret_mana.encrypt
""")
end
end
51 changes: 51 additions & 0 deletions lib/mix/tasks/secret_mana.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
defmodule Mix.Tasks.SecretMana do
use Mix.Task

@shortdoc "Lists available SecretMana Mix tasks"

@moduledoc """
A small index task for the SecretMana Mix tasks.

## Usage

mix secret_mana

This will print a short overview of all available `secret_mana.*` tasks
and how to get more detailed help.

For detailed information on a specific task, use:

mix help secret_mana.install
mix help secret_mana.edit
mix help secret_mana.encrypt
mix help secret_mana.gen.key
"""

@impl Mix.Task
def run(_args) do
Mix.shell().info("""
SecretMana Mix tasks
====================

Configuration / Setup
mix secret_mana.install <env>
Installs SecretMana for the given environment.

mix secret_mana.edit <env>
Opens the SecretMana configuration for editing.

mix secret_mana.gen.key <env>
Generates a SecretMana key for the given environment.

Encryption
mix secret_mana.encrypt <env> <file>
Encrypts a file using SecretMana for the given environment.

Usage hints
• <env> is typically one of: dev, test, prod
• Use --help or -h on any task for a short usage reminder:
mix secret_mana.install --help
mix secret_mana.encrypt -h
""")
end
end
Loading