845 B · text 5af55d9
defmodule Mix.Tasks.Gitgud.Ssh.AuthorizedKeys do
@shortdoc "Regenerate the authorized_keys file from registered SSH keys."
@moduledoc """
Writes `~git/.ssh/authorized_keys` (or a path you pass on the
command line) with one `command="gitgud-ssh <id>" …` entry per
registered SSH key.
mix gitgud.ssh.authorized_keys # prints to stdout
mix gitgud.ssh.authorized_keys /path/to/file # writes file
"""
use Mix.Task
@impl Mix.Task
def run(argv) do
Mix.Task.run("app.start")
contents = GitGud.SshKeys.authorized_keys()
case argv do
[] ->
IO.write(contents)
[path | _] ->
File.mkdir_p!(Path.dirname(path))
File.write!(path, contents)
File.chmod!(path, 0o600)
IO.puts("wrote #{byte_size(contents)} bytes to #{path}")
end
end
end