conjur-asset-pubkeys-api 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 113507366c688741679bb35ecfe61b499e6ec922
4
+ data.tar.gz: 0274a2d928b3a1a27aa92ca638d2aacdc1f846f4
5
+ SHA512:
6
+ metadata.gz: 39f3b08117bd3b4d7337c0ba78983727cc52190010119a9c625a46e871c4bae49dd4ddf6ba3b8abd1af7d667376c9e5e688e4e3f61de2d75ff7313235ef3a315
7
+ data.tar.gz: 579c1b14124e6d26a22a2f0b0de3417a1491e8c13f86cddb916ab009ccde4c0ccdc35fcfcd71ebbd819fe6738afe707872dfd9998e61465db6bc706267d4a3f9
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
19
+
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>conjur-asset-pubkeys</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>com.aptana.ruby.core.rubynature</nature>
16
+ <nature>com.aptana.projects.webnature</nature>
17
+ </natures>
18
+ </projectDescription>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in conjur-asset-pubkeys.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kevin Gilpin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,94 @@
1
+ # Conjur Pubkeys Asset
2
+
3
+ API and CLI for storing public keys for terminal login.
4
+
5
+ The pubkeys service stores public keys using conjur. It provides
6
+ methods to fetch keys or key names, and to add and remove keys.
7
+
8
+ ## Key Format
9
+
10
+ Public keys are added and fetched in the openssh format:
11
+
12
+ `<algorithm> <key> <name>`
13
+
14
+ #### Example:
15
+ ```
16
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDNLVA3D1VpH/yVST0v\
17
+ 4Mj+eAGM5dMNTpv5i/PyvUEGc3r2I8DZNq/icyCoZJlAeR10b13OGHTn2\
18
+ ubu3OeJz5vAJSbZr6QT6V1wKoX8b2g0DR8RcShUWJ8cPeY6wI9eh9F778\
19
+ aY0gkF2YpU62YWRri4K2kQwROQznhfNsgUAj4F2hs8C1T8MElaz2Ux8eg\
20
+ o7Lc2V6sHxsLpz8a08rEjGXm5vRgaVlKY1vzBUDtkQrYvm+cPfW/dVwiB\
21
+ Ujl73T0vrbcgy7u7AlMqenMjQzoJXzY5kRnPUQOhHpZZ/9gw8YG2PutVy\
22
+ AufTXIGibGoGdBLzYltJEfQAEEPTovwZdBWNFT5 bob@example.com
23
+ ```
24
+
25
+ When storing public keys, the name field from the public key data
26
+ is used to uniquely identify the key among a user's keys.
27
+
28
+ ## CLI Usage
29
+
30
+ The `pubkeys:add` command can be used to upload public keys. It accepts the
31
+ key data in the following forms:
32
+
33
+ * `conjur pubkeys:add username "key data string"` - Use the contents of the
34
+ second argument as the key.
35
+ * `conjur pubkeys:add username @key_file_name.pub` - Use the contents of the
36
+ given file.
37
+ * `conjur pubkeys:add username` - Read the key from the standard input.
38
+
39
+ To delete a public key, use the `pubkeys:delete` command:
40
+
41
+ ```
42
+ conjur pubkeys:delete username key-name
43
+ ```
44
+
45
+ To dump all of a user's public keys, one per line, use `pubkeys:show`:
46
+
47
+ ```
48
+ conjur pubkeys:show username
49
+ ```
50
+
51
+ To show only the names of public keys for a user, use `pubkeys:names`:
52
+
53
+ ```
54
+ conjur pubkeys:names username
55
+ ```
56
+
57
+ Note that the `pubkeys:show` command can be acheived using `curl` as well,
58
+ which is often preferable, since you don't need to be logged in to conjur to
59
+ show a user's public keys (they're public, after all!).
60
+
61
+ ```
62
+ curl https://pubkeys.example.com/public_keys/username
63
+ ```
64
+
65
+ ## Permissions
66
+
67
+ To add or remove keys, you must have permission to `update` the
68
+ resource representing the pubkeys service.
69
+
70
+ ## Installation
71
+
72
+ Add this line to your application's Gemfile:
73
+
74
+ gem 'conjur-asset-pubkeys'
75
+
76
+ And then execute:
77
+
78
+ $ bundle
79
+
80
+ Or install it yourself as:
81
+
82
+ $ gem install conjur-asset-pubkeys
83
+
84
+ ## Usage
85
+
86
+ TODO: Write usage instructions here
87
+
88
+ ## Contributing
89
+
90
+ 1. Fork it
91
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
92
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
93
+ 4. Push to the branch (`git push origin my-new-feature`)
94
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'conjur-asset-pubkeys-version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "conjur-asset-pubkeys-api"
8
+ spec.version = Conjur::Asset::Pubkeys::VERSION
9
+ spec.authors = ["Jon Mason"]
10
+ spec.email = ["jon@conjur.net"]
11
+ spec.homepage = "http://conjur.net"
12
+ spec.summary = "Conjur asset plugin for a public key store."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "conjur-api"
22
+
23
+ spec.add_development_dependency "conjur-cli"
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "spork"
29
+ spec.add_development_dependency "ci_reporter"
30
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ module Conjur
22
+ module Asset
23
+ module Pubkeys
24
+ VERSION = "0.1.2"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'conjur-asset-pubkeys-version'
22
+ require 'conjur/api'
23
+ require 'conjur/pubkeys-api'
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+
22
+ module Conjur
23
+ class API
24
+ # Return all of a user's public keys, as a newline delimited string
25
+ # (the format expected by authorized-keys)
26
+ def public_keys username
27
+ public_keys_resource(username).get
28
+ end
29
+
30
+ # Return a specific public key for a given user and key name
31
+ def public_key username, keyname
32
+ public_keys_resource(username, keyname).get
33
+ end
34
+
35
+ # Add a public key for the given user
36
+ def add_public_key username, key
37
+ public_keys_resource(username).post key
38
+ end
39
+
40
+ # Delete a public key for the given user and key name
41
+ def delete_public_key username, keyname
42
+ public_keys_resource(username, keyname).delete
43
+ end
44
+
45
+ protected
46
+ def public_keys_resource *path
47
+ RestClient::Resource.new(Conjur::API.pubkeys_asset_host, credentials)[public_keys_path *path]
48
+ end
49
+
50
+ def public_keys_path *args
51
+ args.map{|a| fully_escape(a)}.join('/')
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,75 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+
22
+ require 'conjur/cli'
23
+
24
+ class Conjur::Command::Pubkeys < Conjur::Command
25
+ self.prefix = :pubkeys
26
+
27
+ desc "List public keys for the given user"
28
+ arg_name "username"
29
+ command :show do |c|
30
+ c.action do |global_options, options, args|
31
+ username = require_arg args, "username"
32
+ puts api.public_keys(username)
33
+ end
34
+ end
35
+
36
+ desc "List the names of a user's public keys"
37
+ arg_name "username"
38
+ command :names do |c|
39
+ c.action do |global_options, options, args|
40
+ username = require_arg args, "username"
41
+ api.public_keys(username)
42
+ .split("\n")
43
+ .map{|k| k.split(' ').last}
44
+ .sort.each{|n| puts n}
45
+ end
46
+ end
47
+
48
+ desc "Add a public key for a user"
49
+ arg_name "username key"
50
+ command :add do |c|
51
+ c.action do |global_options, options, args|
52
+ username = require_arg args, "username"
53
+ if key = args.shift
54
+ if /^@(.+)$/ =~ key
55
+ key = File.read($1)
56
+ end
57
+ else
58
+ key = STDIN.read.strip
59
+ end
60
+ api.add_public_key username, key
61
+ puts "Public key '#{key.split(' ').last}' added"
62
+ end
63
+ end
64
+
65
+ desc "Removes a public key for a user"
66
+ arg_name "username keyname"
67
+ command :delete do |c|
68
+ c.action do |global_options, options, args|
69
+ username = require_arg args, "username"
70
+ keyname = require_arg args, "keyname"
71
+ api.delete_public_key username, keyname
72
+ puts "Public key '#{keyname}' deleted"
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'conjur/api'
22
+ require 'conjur/configuration'
23
+
24
+ class Conjur::Configuration
25
+ add_option :pubkeys_url do
26
+ account_service_url 'pubkeys', 400
27
+ end
28
+ end
29
+
30
+ class Conjur::API
31
+ class << self
32
+ def pubkeys_asset_host
33
+ Conjur.configuration.pubkeys_url
34
+ end
35
+ end
36
+ end
37
+
38
+ require 'conjur/api/pubkeys'
@@ -0,0 +1,72 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'spec_helper'
22
+ require 'conjur/command/pubkeys'
23
+
24
+ describe Conjur::Command::Pubkeys, logged_in: true do
25
+ describe_command "pubkeys:show alice" do
26
+ it "calls api.public_keys('alice') and prints the result" do
27
+ described_class.api.should_receive(:public_keys).with('alice').and_return "a public key"
28
+ expect{ invoke }.to write("a public key")
29
+ end
30
+ end
31
+
32
+ describe_command "pubkeys:names alice" do
33
+ let(:keys){ ["x y foo", "x y bar"].join("\n") }
34
+ let(:names){ "bar\nfoo" }
35
+ it "calls api.public_keys('alice') and prints the names" do
36
+ described_class.api.should_receive(:public_keys).with('alice').and_return keys
37
+ expect{ invoke }.to write(names)
38
+ end
39
+ end
40
+
41
+ describe_command "pubkeys:add alice data" do
42
+ it "calls api.add_public_key('alice', 'data') and prints the key name" do
43
+ described_class.api.should_receive(:add_public_key).with('alice', 'data')
44
+ expect{ invoke }.to write("Public key 'data' added")
45
+ end
46
+ end
47
+
48
+ describe_command "pubkeys:add alice @id_rsa.pub" do
49
+ let(:file_contents){ "ssh-rsa blahblah keyname" }
50
+ it "calls api.add_public_key('alice', data) and prints the key name" do
51
+ File.should_receive(:read).with("id_rsa.pub").and_return(file_contents)
52
+ described_class.api.should_receive(:add_public_key).with('alice', file_contents)
53
+ expect{ invoke }.to write("Public key 'keyname' added")
54
+ end
55
+ end
56
+
57
+ describe_command "pubkeys:add alice" do
58
+ let(:stdin_contents){ "ssh-rsa blahblah keyname" }
59
+ it "calls api.add_public_key('alice', stdin) and prints the key name" do
60
+ STDIN.should_receive(:read).and_return(stdin_contents)
61
+ described_class.api.should_receive(:add_public_key).with('alice', stdin_contents)
62
+ expect{ invoke }.to write("Public key 'keyname' added")
63
+ end
64
+ end
65
+
66
+ describe_command "pubkeys:delete alice keyname" do
67
+ it "calls api.delete_public_key('alice', 'keyname')" do
68
+ described_class.api.should_receive(:delete_public_key).with("alice", "keyname")
69
+ expect{ invoke }.to write("Public key 'keyname' deleted")
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,66 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'spec_helper'
22
+
23
+ describe Conjur::API, api: :dummy do
24
+ let(:pubkeys_url){ "http://pubkeys.example.com/api/pubkeys" }
25
+ def pubkeys_url_for *path
26
+ [pubkeys_url, path.map{|p| CGI.escape(p)} ].join("/")
27
+ end
28
+
29
+ before do
30
+ Conjur::API.stub(pubkeys_asset_host: pubkeys_url)
31
+ end
32
+
33
+ describe "#public_keys" do
34
+ it "GETs /:username" do
35
+ RestClient::Request.should_receive(:execute).with(
36
+ url: pubkeys_url_for("bob"),
37
+ method: :get,
38
+ headers: {}
39
+ ).and_return "key key key"
40
+ expect(api.public_keys("bob")).to eq("key key key")
41
+ end
42
+ end
43
+
44
+ describe "#add_public_key" do
45
+ it "POSTs /:username with the data" do
46
+ RestClient::Request.should_receive(:execute).with(
47
+ url: pubkeys_url_for("bob"),
48
+ method: :post,
49
+ headers: {},
50
+ payload: "key data"
51
+ )
52
+ api.add_public_key("bob", "key data")
53
+ end
54
+ end
55
+
56
+ describe "#delete_public_key" do
57
+ it "DELETEs /:username/:keyname" do
58
+ RestClient::Request.should_receive(:execute).with(
59
+ url: pubkeys_url_for("bob", "bob-key"),
60
+ method: :delete,
61
+ headers: {}
62
+ )
63
+ api.delete_public_key("bob", "bob-key")
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,102 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'simplecov'
22
+ SimpleCov.start do
23
+ add_filter "/spec/"
24
+ end
25
+
26
+ require 'rubygems'
27
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
28
+ $:.unshift File.join(File.dirname(__FILE__), "lib")
29
+ require 'spork'
30
+
31
+ require 'conjur/command/rspec/helpers'
32
+
33
+ Spork.prefork do
34
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
35
+ # from the project root directory.
36
+ ENV["CONJUR_ENV"] ||= 'test'
37
+
38
+ # Allows loading of an environment config based on the environment
39
+ require 'rspec'
40
+ require 'securerandom'
41
+ require 'conjur-asset-pubkeys'
42
+
43
+ # Uncomment the next line to use webrat's matchers
44
+ #require 'webrat/integrations/rspec-rails'
45
+
46
+ RSpec.configure do |config|
47
+ # If you're not using ActiveRecord you should remove these
48
+ # lines, delete config/database.yml and disable :active_record
49
+ # in your config/boot.rb
50
+ #config.use_transactional_fixtures = true
51
+ #config.use_instantiated_fixtures = false
52
+ #config.fixture_path = File.join(redmine_root, 'test', 'fixtures')
53
+
54
+ # == Fixtures
55
+ #
56
+ # You can declare fixtures for each example_group like this:
57
+ # describe "...." do
58
+ # fixtures :table_a, :table_b
59
+ #
60
+ # Alternatively, if you prefer to declare them only once, you can
61
+ # do so right here. Just uncomment the next line and replace the fixture
62
+ # names with your fixtures.
63
+ #
64
+ #
65
+ # If you declare global fixtures, be aware that they will be declared
66
+ # for all of your examples, even those that don't use them.
67
+ #
68
+ # You can also declare which fixtures to use (for example fixtures for test/fixtures):
69
+ #
70
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
71
+ #
72
+ # == Mock Framework
73
+ #
74
+ # RSpec uses its own mocking framework by default. If you prefer to
75
+ # use mocha, flexmock or RR, uncomment the appropriate line:
76
+ #
77
+ # config.mock_with :mocha
78
+ # config.mock_with :flexmock
79
+ # config.mock_with :rr
80
+ #
81
+ # == Notes
82
+ #
83
+ # For more information take a look at Spec::Runner::Configuration and Spec::Runner
84
+ end
85
+ end
86
+
87
+ Spork.each_run do
88
+ # This code will be run each time you run your specs.
89
+
90
+ # Requires supporting files with custom matchers and macros, etc,
91
+ # in ./support/ and its subdirectories.
92
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
93
+ end
94
+
95
+ # I feel like this exists somewhere else but I can't find it...
96
+ shared_context api: :dummy do
97
+ let(:api){ Conjur::API.new_from_key 'username', 'key' }
98
+ let(:credentials){ {} }
99
+ before do
100
+ api.stub(credentials: credentials)
101
+ end
102
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conjur-asset-pubkeys-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Jon Mason
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: conjur-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: conjur-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: spork
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: ci_reporter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - jon@conjur.net
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .project
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - conjur-asset-pubkeys.gemspec
139
+ - lib/conjur-asset-pubkeys-version.rb
140
+ - lib/conjur-asset-pubkeys.rb
141
+ - lib/conjur/api/pubkeys.rb
142
+ - lib/conjur/command/pubkeys.rb
143
+ - lib/conjur/pubkeys-api.rb
144
+ - spec/command_spec.rb
145
+ - spec/pubkeys_spec.rb
146
+ - spec/spec_helper.rb
147
+ homepage: ''
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.0.3
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Conjur asset plugin for a public key store.
171
+ test_files:
172
+ - spec/command_spec.rb
173
+ - spec/pubkeys_spec.rb
174
+ - spec/spec_helper.rb
175
+ has_rdoc: