Skip to content

Commit e56d7d8

Browse files
committed
Initial commit of SSHClientKeyAPI
1 parent 675f254 commit e56d7d8

File tree

9 files changed

+553
-3
lines changed

9 files changed

+553
-3
lines changed

.credo.exs

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# This file contains the configuration for Credo and you are probably reading
2+
# this after creating it with `mix credo.gen.config`.
3+
#
4+
# If you find anything wrong or unclear in this file, please report an
5+
# issue on GitHub: https://github.com/rrrene/credo/issues
6+
#
7+
%{
8+
#
9+
# You can have as many configs as you like in the `configs:` field.
10+
configs: [
11+
%{
12+
#
13+
# Run any config using `mix credo -C <name>`. If no config name is given
14+
# "default" is used.
15+
name: "default",
16+
#
17+
# These are the files included in the analysis:
18+
files: %{
19+
#
20+
# You can give explicit globs or simply directories.
21+
# In the latter case `**/*.{ex,exs}` will be used.
22+
included: ["lib/"],
23+
excluded: [~r"/_build/", ~r"/deps/"]
24+
},
25+
#
26+
# If you create your own checks, you must specify the source files for
27+
# them here, so they can be loaded by Credo before running the analysis.
28+
requires: [],
29+
#
30+
# Credo automatically checks for updates, like e.g. Hex does.
31+
# You can disable this behaviour below:
32+
check_for_updates: true,
33+
#
34+
# If you want to enforce a style guide and need a more traditional linting
35+
# experience, you can change `strict` to `true` below:
36+
strict: true,
37+
#
38+
# If you want to use uncolored output by default, you can change `color`
39+
# to `false` below:
40+
color: true,
41+
#
42+
# You can customize the parameters of any check by adding a second element
43+
# to the tuple.
44+
#
45+
# To disable a check put `false` as second element:
46+
#
47+
# {Credo.Check.Design.DuplicatedCode, false}
48+
#
49+
checks: [
50+
{Credo.Check.Consistency.ExceptionNames},
51+
{Credo.Check.Consistency.LineEndings},
52+
{Credo.Check.Consistency.MultiAliasImportRequireUse},
53+
{Credo.Check.Consistency.ParameterPatternMatching},
54+
{Credo.Check.Consistency.SpaceAroundOperators},
55+
{Credo.Check.Consistency.SpaceInParentheses},
56+
{Credo.Check.Consistency.TabsOrSpaces},
57+
58+
# For some checks, like AliasUsage, you can only customize the priority
59+
# Priority values are: `low, normal, high, higher`
60+
{Credo.Check.Design.AliasUsage, priority: :low},
61+
62+
# For others you can set parameters
63+
64+
# If you don't want the `setup` and `test` macro calls in ExUnit tests
65+
# or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
66+
# set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
67+
{Credo.Check.Design.DuplicatedCode, excluded_macros: []},
68+
69+
# You can also customize the exit_status of each check.
70+
# If you don't want TODO comments to cause `mix credo` to fail, just
71+
# set this value to 0 (zero).
72+
{Credo.Check.Design.TagTODO, exit_status: 2},
73+
{Credo.Check.Design.TagFIXME},
74+
75+
{Credo.Check.Readability.FunctionNames},
76+
{Credo.Check.Readability.LargeNumbers},
77+
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 100},
78+
{Credo.Check.Readability.ModuleAttributeNames},
79+
{Credo.Check.Readability.ModuleDoc},
80+
{Credo.Check.Readability.ModuleNames},
81+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
82+
{Credo.Check.Readability.ParenthesesInCondition},
83+
{Credo.Check.Readability.PredicateFunctionNames},
84+
{Credo.Check.Readability.PreferImplicitTry},
85+
{Credo.Check.Readability.RedundantBlankLines},
86+
{Credo.Check.Readability.StringSigils},
87+
{Credo.Check.Readability.TrailingBlankLine},
88+
{Credo.Check.Readability.TrailingWhiteSpace},
89+
{Credo.Check.Readability.VariableNames},
90+
{Credo.Check.Readability.Semicolons},
91+
{Credo.Check.Readability.SpaceAfterCommas},
92+
93+
{Credo.Check.Refactor.DoubleBooleanNegation},
94+
{Credo.Check.Refactor.CondStatements},
95+
{Credo.Check.Refactor.CyclomaticComplexity},
96+
{Credo.Check.Refactor.FunctionArity},
97+
{Credo.Check.Refactor.MatchInCondition},
98+
{Credo.Check.Refactor.NegatedConditionsInUnless},
99+
{Credo.Check.Refactor.NegatedConditionsWithElse},
100+
{Credo.Check.Refactor.Nesting},
101+
{Credo.Check.Refactor.PipeChainStart},
102+
{Credo.Check.Refactor.UnlessWithElse},
103+
104+
{Credo.Check.Warning.BoolOperationOnSameValues},
105+
{Credo.Check.Warning.IExPry},
106+
{Credo.Check.Warning.IoInspect},
107+
{Credo.Check.Warning.LazyLogging},
108+
{Credo.Check.Warning.OperationOnSameValues},
109+
{Credo.Check.Warning.OperationWithConstantResult},
110+
{Credo.Check.Warning.UnusedEnumOperation},
111+
{Credo.Check.Warning.UnusedFileOperation},
112+
{Credo.Check.Warning.UnusedKeywordOperation},
113+
{Credo.Check.Warning.UnusedListOperation},
114+
{Credo.Check.Warning.UnusedPathOperation},
115+
{Credo.Check.Warning.UnusedRegexOperation},
116+
{Credo.Check.Warning.UnusedStringOperation},
117+
{Credo.Check.Warning.UnusedTupleOperation},
118+
119+
# Controversial and experimental checks (opt-in, just remove `, false`)
120+
#
121+
{Credo.Check.Refactor.ABCSize, false},
122+
{Credo.Check.Refactor.AppendSingleItem, false},
123+
{Credo.Check.Refactor.VariableRebinding, false},
124+
{Credo.Check.Warning.MapGetUnsafePass, false},
125+
126+
# Deprecated checks (these will be deleted after a grace period)
127+
{Credo.Check.Readability.Specs, false},
128+
{Credo.Check.Warning.NameRedeclarationByAssignment, false},
129+
{Credo.Check.Warning.NameRedeclarationByCase, false},
130+
{Credo.Check.Warning.NameRedeclarationByDef, false},
131+
{Credo.Check.Warning.NameRedeclarationByFn, false},
132+
133+
# Custom checks can be created using `mix credo.gen.check`.
134+
#
135+
]
136+
}
137+
]
138+
}

.gitignore

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
# The directory Mix will write compiled artifacts to.
12
/_build
3+
4+
# If you run "mix test --cover", coverage assets end up here.
25
/cover
6+
7+
# The directory Mix downloads your dependencies sources to.
38
/deps
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
417
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
520
*.ez
6-
*.beam

README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# ssh_client_key_api
2-
An Elixir implementation of the Erlang `ssh_client_key_api` behavior.
1+
# SSHClientKeyApi
2+
3+
Simple Elixir implementation for the Erlang `ssh_client_key_api` behavior, to
4+
make it easier to specify SSH keys and `known_hosts` files independently of
5+
any particular user's home directory.
6+
7+
By itself, `ssh_client_key_api` does not provide SSH functionality, it only adds
8+
a way to send private key information to an ssh connection. It is meant to be
9+
used alongside an SSH library such as `:ssh`, `SSHex`, `SSHKit` or the like.
10+
11+
## Installation
12+
13+
The package can be installed by adding `ssh_client_key_api` to your list of
14+
dependencies in `mix.exs`:
15+
16+
```elixir
17+
def deps do
18+
[{:ssh_client_key_api, "~> 0.0.1"}]
19+
end
20+
```
21+
22+
## Using SSHClientKeyApi
23+
24+
Options
25+
26+
* `identity`: `IO.device` providing the ssh private key (required)
27+
* `known_hosts`: `IO.device` providing the known hosts list. If providing a File IO, it should have been opened in `:write` mode (required)
28+
* `accept_hosts`: `boolean` silently accept and add new hosts to the known hosts. By default only known hosts will be accepted.
29+
30+
`SSHClientKeyApi` is meant to primarily be used via the convenience function
31+
`with_config`:
32+
33+
```elixir
34+
key = File.open!("path/to/keyfile.pub")
35+
known_hosts = File.open!("path/to/known_hosts")
36+
cb = SSHClientKeyAPI.with_options(identity: key, known_hosts: known_hosts, accept_hosts: false)
37+
```
38+
39+
The result can then be passed as an option when creating an SSH connection.
40+
41+
### SSHKit
42+
43+
```
44+
connection = SSHKit.SSH.connect("example.com", key_cb: cb)
45+
# or with a SSHKit.Context:
46+
context = SSHKit.context("example.com", key_cb: cb)
47+
```
48+
49+
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
50+
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
51+
be found at [https://hexdocs.pm/ssh_client_key_api](https://hexdocs.pm/ssh_client_key_api).
52+

config/config.exs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Mix.Config module.
3+
use Mix.Config
4+
5+
# This configuration is loaded before any dependency and is restricted
6+
# to this project. If another project depends on this project, this
7+
# file won't be loaded nor affect the parent project. For this reason,
8+
# if you want to provide default values for your application for
9+
# 3rd-party users, it should be done in your "mix.exs" file.
10+
11+
# You can configure for your application as:
12+
#
13+
# config :sshkit, key: :value
14+
#
15+
# And access this configuration in your application as:
16+
#
17+
# Application.get_env(:sshkit, :key)
18+
#
19+
# Or configure a 3rd-party app:
20+
#
21+
# config :logger, level: :info
22+
#
23+
24+
# It is also possible to import configuration files, relative to this
25+
# directory. For example, you can emulate configuration per environment
26+
# by uncommenting the line below and defining dev.exs, test.exs and such.
27+
# Configuration from the imported file will override the ones defined
28+
# here (which is why it is important to import them last).
29+
#
30+
# import_config "#{Mix.env}.exs"

0 commit comments

Comments
 (0)