duse 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +35 -0
- data/.rspec +2 -0
- data/.travis.yml +13 -0
- data/Gemfile +13 -0
- data/LICENSE +22 -0
- data/README.md +89 -0
- data/Rakefile +11 -0
- data/bin/duse +8 -0
- data/duse.gemspec +22 -0
- data/lib/duse.rb +10 -0
- data/lib/duse/cli.rb +104 -0
- data/lib/duse/cli/account.rb +20 -0
- data/lib/duse/cli/account_confirm.rb +22 -0
- data/lib/duse/cli/account_info.rb +18 -0
- data/lib/duse/cli/account_password.rb +14 -0
- data/lib/duse/cli/account_password_change.rb +30 -0
- data/lib/duse/cli/account_password_reset.rb +20 -0
- data/lib/duse/cli/account_resend_confirmation.rb +20 -0
- data/lib/duse/cli/account_update.rb +25 -0
- data/lib/duse/cli/api_command.rb +33 -0
- data/lib/duse/cli/cli_config.rb +54 -0
- data/lib/duse/cli/command.rb +202 -0
- data/lib/duse/cli/config.rb +16 -0
- data/lib/duse/cli/help.rb +23 -0
- data/lib/duse/cli/key_helper.rb +84 -0
- data/lib/duse/cli/login.rb +27 -0
- data/lib/duse/cli/meta_command.rb +12 -0
- data/lib/duse/cli/parser.rb +43 -0
- data/lib/duse/cli/password_helper.rb +17 -0
- data/lib/duse/cli/register.rb +45 -0
- data/lib/duse/cli/secret.rb +19 -0
- data/lib/duse/cli/secret_add.rb +38 -0
- data/lib/duse/cli/secret_generator.rb +10 -0
- data/lib/duse/cli/secret_get.rb +40 -0
- data/lib/duse/cli/secret_list.rb +20 -0
- data/lib/duse/cli/secret_remove.rb +19 -0
- data/lib/duse/cli/secret_update.rb +44 -0
- data/lib/duse/cli/share_with_user.rb +53 -0
- data/lib/duse/cli/version.rb +12 -0
- data/lib/duse/client/config.rb +36 -0
- data/lib/duse/client/entity.rb +87 -0
- data/lib/duse/client/namespace.rb +112 -0
- data/lib/duse/client/secret.rb +69 -0
- data/lib/duse/client/session.rb +128 -0
- data/lib/duse/client/user.rb +23 -0
- data/lib/duse/encryption.rb +39 -0
- data/lib/duse/version.rb +3 -0
- data/spec/cli/cli_config_spec.rb +49 -0
- data/spec/cli/commands/account_spec.rb +45 -0
- data/spec/cli/commands/config_spec.rb +17 -0
- data/spec/cli/commands/login_spec.rb +51 -0
- data/spec/cli/commands/register_spec.rb +38 -0
- data/spec/cli/commands/secret_spec.rb +142 -0
- data/spec/client/secret_marshaller_spec.rb +32 -0
- data/spec/client/secret_spec.rb +96 -0
- data/spec/client/user_spec.rb +105 -0
- data/spec/spec_helper.rb +70 -0
- data/spec/support/helpers.rb +43 -0
- data/spec/support/mock_api.rb +142 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MGYyYjA4MDNiY2ZjMDRiN2ViNjNiNDIzZDY5YmM5MjdkMGQ2NzdjMw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWFjY2ZmZDBlODY3ZDU5NWU4YWFjMjVhZDI1NmUyZDc3ODNmMTFjYQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzBkYTk5MzRlMzBmMWNjNzAxNjhhNjU0N2MzNjMyOGNhMDBhMTA3NDA4MWUy
|
10
|
+
ZjVkNDE5MmMzY2ViZTFjYWJlYjcxMWExZmIyZWRhMDA3MjYwYTQ4ZjllZmJi
|
11
|
+
YmJiMzcxMGQ3MjhkMDYzMzA3NTQwNWExNzc5YTViMzc2OTUxNWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Y2Q2MjEzY2YzYTJhOWY5NzNjMDM3ODliNmRkMTc2NmI3MzMyY2UwOGJhMTkw
|
14
|
+
NzRiOWUxYzI5OTYwZTRiMzc2OGY2MTgzNjUxMjRhODI2ZjUwZmQyNGFhMTM4
|
15
|
+
NTBjYWJjNWZkNzMwMjI1NjIyMDFlZDUwYjViOTQxNjAyZTFmNDA=
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
Gemfile.lock
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalisation:
|
25
|
+
/.bundle/
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2.2
|
4
|
+
sudo: false
|
5
|
+
cache: bundler
|
6
|
+
deploy:
|
7
|
+
provider: rubygems
|
8
|
+
api_key:
|
9
|
+
secure: bdKrctjfSWJ5bhPOVL2Amr2/hbCa6J0QGhIsl7ZbWSitSP17sW8wN8E2TSECGHAouymzZ9SmFKCJpTrjpdd6lA3ATHoMcRl2c5qHVcL0IyZ1Q89sVxnhCt/nXzoCOG1FzLyyHfiGq4/RbB3e04xG2ZWPkuLZMGJnFqChNciNPB0=
|
10
|
+
gem: duse
|
11
|
+
on:
|
12
|
+
tags: true
|
13
|
+
repo: duse-io/duse.rb
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2014 duse
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
[](https://travis-ci.org/duse-io/duse.rb)
|
2
|
+
[](https://coveralls.io/r/duse-io/duse.rb?branch=master)
|
3
|
+
[](https://codeclimate.com/github/duse-io/duse.rb)
|
4
|
+
|
5
|
+
Duse Client & Client Library
|
6
|
+
============================
|
7
|
+
|
8
|
+
Duse is a cryptographic server client application created to securely share
|
9
|
+
secrets among signed up users. It is meant to be used for secrets such as
|
10
|
+
passwords and ssh-keys, but it can very well be used to encrypt and share
|
11
|
+
anything.
|
12
|
+
|
13
|
+
This is a CLI for consuming the [duse api](https://github.com/duse-io/api),
|
14
|
+
written in ruby.
|
15
|
+
|
16
|
+
This implementation was heavily inspired by [travis-ci/travis.rb](https://github.com/travis-ci/travis.rb)
|
17
|
+
|
18
|
+
The Client
|
19
|
+
==========
|
20
|
+
|
21
|
+
To install the client simply install its ruby gem.
|
22
|
+
|
23
|
+
$ gem install duse
|
24
|
+
|
25
|
+
Then you can explore the client with its help texts
|
26
|
+
|
27
|
+
$ duse help
|
28
|
+
Usage: duse COMMAND ...
|
29
|
+
|
30
|
+
Available commands:
|
31
|
+
|
32
|
+
config Configure the client
|
33
|
+
help Displays help messages, such as this one
|
34
|
+
login login to access and save secrets
|
35
|
+
register Register a new account
|
36
|
+
secret Save, retrieve and delete secrets
|
37
|
+
|
38
|
+
run `duse help COMMAND` for more infos
|
39
|
+
|
40
|
+
When you want to see the help texts for subcommands of e.g. secrets
|
41
|
+
|
42
|
+
$ duse help secret
|
43
|
+
|
44
|
+
Save, retrieve and delete secrets
|
45
|
+
|
46
|
+
Usage: duse secret COMMAND ...
|
47
|
+
|
48
|
+
Available commands:
|
49
|
+
|
50
|
+
save Save a new secret
|
51
|
+
get Retrieve a secret
|
52
|
+
list List all secrets you have access to
|
53
|
+
delete Delete a secret
|
54
|
+
|
55
|
+
run `duse help secret COMMAND` for more infos
|
56
|
+
|
57
|
+
Generally the cli will tell you if an action on your side is required. For
|
58
|
+
example when it needs to be configured and you are trying to login.
|
59
|
+
|
60
|
+
$ duse login
|
61
|
+
client not configured, run `duse config`
|
62
|
+
|
63
|
+
The Library
|
64
|
+
===========
|
65
|
+
|
66
|
+
Installation
|
67
|
+
------------
|
68
|
+
|
69
|
+
Add this line to your application's Gemfile:
|
70
|
+
|
71
|
+
gem 'duse'
|
72
|
+
|
73
|
+
And then execute:
|
74
|
+
|
75
|
+
$ bundle
|
76
|
+
|
77
|
+
Or install it yourself as:
|
78
|
+
|
79
|
+
$ gem install duse
|
80
|
+
|
81
|
+
Usage
|
82
|
+
-----
|
83
|
+
|
84
|
+
require 'duse'
|
85
|
+
Duse.uri = 'https://example.org/'
|
86
|
+
Duse.token = 'token'
|
87
|
+
user = Duse::User.get 'me'
|
88
|
+
p user
|
89
|
+
=> #<Duse::Client::User:0x0000000140acd0 @attributes={"id"=>2, "username"=>"flower-pot", "public_key"=>"-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtaAORZpFJ037AN1Drm88TLYyZ\ny+vLyVZr9XKPfMUF/KCHEsT1gJfQYFRI7t/gHjL3VouKM10671f/g8s5t1hWHF6Y\nOvaFTd3yDXAkf86x5jrPBrIH6M3M5WOwwqwW9aRF22CFzlBoCoV4GQt4KhRzqrG2\nkRJULsBuT9TiHCKEPwIDAQAB\n-----END PUBLIC KEY-----\n"}, @curry=#<Duse::Client::Namespace::Curry:0x0000000149fbf0>>
|
data/Rakefile
ADDED
data/bin/duse
ADDED
data/duse.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'duse/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'duse'
|
8
|
+
s.version = Duse::VERSION
|
9
|
+
s.description = 'CLI and Ruby client library for duse'
|
10
|
+
s.homepage = 'https://github.com/duse-io/duse.rb'
|
11
|
+
s.summary = 'Duse client'
|
12
|
+
s.license = 'MIT'
|
13
|
+
s.executables = ['duse']
|
14
|
+
s.authors = 'Frederic Branczyk'
|
15
|
+
s.email = 'fbranczyk@gmail.com'
|
16
|
+
s.files = `git ls-files -z`.split("\x0")
|
17
|
+
|
18
|
+
s.add_runtime_dependency 'highline'
|
19
|
+
s.add_runtime_dependency 'secret_sharing'
|
20
|
+
s.add_runtime_dependency 'faraday'
|
21
|
+
s.add_runtime_dependency 'faraday_middleware'
|
22
|
+
end
|
data/lib/duse.rb
ADDED
data/lib/duse/cli.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require 'duse'
|
3
|
+
require 'duse/cli/cli_config'
|
4
|
+
|
5
|
+
module Duse
|
6
|
+
module CLI
|
7
|
+
autoload :Command, 'duse/cli/command'
|
8
|
+
autoload :ApiCommand, 'duse/cli/api_command'
|
9
|
+
autoload :Help, 'duse/cli/help'
|
10
|
+
autoload :Config, 'duse/cli/config'
|
11
|
+
autoload :Login, 'duse/cli/login'
|
12
|
+
autoload :MetaCommand,'duse/cli/meta_command'
|
13
|
+
autoload :Register, 'duse/cli/register'
|
14
|
+
autoload :Secret, 'duse/cli/secret'
|
15
|
+
autoload :Account, 'duse/cli/account'
|
16
|
+
autoload :Version, 'duse/cli/version'
|
17
|
+
|
18
|
+
extend self
|
19
|
+
|
20
|
+
def run(*args)
|
21
|
+
args, opts = preparse(args)
|
22
|
+
command_class = command(args)
|
23
|
+
command = command_class.new(opts)
|
24
|
+
command.parse(args)
|
25
|
+
command.execute
|
26
|
+
end
|
27
|
+
|
28
|
+
def command(args)
|
29
|
+
name = args.shift unless args.empty?
|
30
|
+
const_name = command_name(name)
|
31
|
+
constant = CLI.const_get(const_name) if const_name =~ /^[A-Z][A-Za-z]+$/ and const_defined? const_name
|
32
|
+
if command? constant
|
33
|
+
command = constant
|
34
|
+
return deep_subcommand(command, args)
|
35
|
+
end
|
36
|
+
$stderr.puts "unknown command #{name}"
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
def deep_subcommand(command, args)
|
41
|
+
loop do
|
42
|
+
return command unless command.subcommand args.first
|
43
|
+
command = command.subcommand args.shift
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def commands
|
48
|
+
CLI.constants.map { |n| try_const_get(n) }.select { |c| command? c }
|
49
|
+
end
|
50
|
+
|
51
|
+
def silent
|
52
|
+
stderr, $stderr = $stderr, dummy_io
|
53
|
+
stdout, $stdout = $stdout, dummy_io
|
54
|
+
yield
|
55
|
+
ensure
|
56
|
+
$stderr = stderr if stderr
|
57
|
+
$stdout = stdout if stdout
|
58
|
+
end
|
59
|
+
|
60
|
+
def config
|
61
|
+
Duse.config ||= CLIConfig.new(CLIConfig.load)
|
62
|
+
end
|
63
|
+
|
64
|
+
def config=(config)
|
65
|
+
Duse.config = config
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def try_const_get(name)
|
71
|
+
CLI.const_get(name)
|
72
|
+
rescue Exception
|
73
|
+
puts name
|
74
|
+
end
|
75
|
+
|
76
|
+
def dummy_io
|
77
|
+
return StringIO.new unless defined? IO::NULL and IO::NULL
|
78
|
+
File.open(IO::NULL, 'w')
|
79
|
+
end
|
80
|
+
|
81
|
+
def command?(constant)
|
82
|
+
constant.is_a? Class and constant < Command and not constant.abstract?
|
83
|
+
end
|
84
|
+
|
85
|
+
def command_name(name)
|
86
|
+
case name
|
87
|
+
when nil, '-h', '-?' then 'Help'
|
88
|
+
when '-v' then 'Version'
|
89
|
+
when /^--/ then command_name(name[2..-1])
|
90
|
+
else name.split('-').map(&:capitalize).join
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# can't use flatten as it will flatten hashes
|
95
|
+
def preparse(unparsed, args = [], opts = {})
|
96
|
+
case unparsed
|
97
|
+
when Hash then opts.merge! unparsed
|
98
|
+
when Array then unparsed.each { |e| preparse(e, args, opts) }
|
99
|
+
else args << unparsed.to_s
|
100
|
+
end
|
101
|
+
[args, opts]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'duse/cli/account_confirm'
|
2
|
+
require 'duse/cli/account_resend_confirmation'
|
3
|
+
require 'duse/cli/account_info'
|
4
|
+
require 'duse/cli/account_update'
|
5
|
+
require 'duse/cli/account_password'
|
6
|
+
|
7
|
+
module Duse
|
8
|
+
module CLI
|
9
|
+
class Account < MetaCommand
|
10
|
+
subcommand AccountConfirm
|
11
|
+
subcommand AccountResendConfirmation
|
12
|
+
subcommand AccountInfo
|
13
|
+
subcommand AccountUpdate
|
14
|
+
subcommand AccountPassword
|
15
|
+
|
16
|
+
description 'Manage your account'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'duse/cli'
|
2
|
+
|
3
|
+
module Duse
|
4
|
+
module CLI
|
5
|
+
class AccountConfirm < ApiCommand
|
6
|
+
description 'confirm your account'
|
7
|
+
|
8
|
+
skip :authenticate
|
9
|
+
|
10
|
+
on('-t', '--token [TOKEN]', 'The token to use for confirming')
|
11
|
+
|
12
|
+
def run
|
13
|
+
self.token ||= terminal.ask("A confirmation email has been sent. A confirmation token was mentioned in it, please provide that token below.\n\ntoken: ")
|
14
|
+
Duse::User.confirm(self.token)
|
15
|
+
success 'Account successfully confirmed.'
|
16
|
+
rescue Duse::Client::NotFound
|
17
|
+
error 'Token is either not valid or has already been used.'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'duse/cli'
|
2
|
+
|
3
|
+
module Duse
|
4
|
+
module CLI
|
5
|
+
class AccountInfo < ApiCommand
|
6
|
+
description 'view your account information'
|
7
|
+
|
8
|
+
def run
|
9
|
+
user = Duse::User.current
|
10
|
+
say "
|
11
|
+
Username: #{user.username}
|
12
|
+
Email: #{user.email}
|
13
|
+
".gsub(/^( |\t)+/, "")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'duse/cli/account_password_change.rb'
|
2
|
+
require 'duse/cli/account_password_reset.rb'
|
3
|
+
|
4
|
+
module Duse
|
5
|
+
module CLI
|
6
|
+
class AccountPassword < MetaCommand
|
7
|
+
subcommand AccountPasswordChange
|
8
|
+
subcommand AccountPasswordReset
|
9
|
+
|
10
|
+
description 'Manage your password'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|