cloudpassage 0.0.6 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f885d2347066b179712e43dae23e79c82f8a2f5
4
- data.tar.gz: b0259a907cc18cdcfce0233ee452fb1465a2ad4e
3
+ metadata.gz: 3727dfd86efb6d3d5cef5c602aa690e7d553a605
4
+ data.tar.gz: 628dfedd3fd24a5aa4ed1a6527e0a0716e059dc9
5
5
  SHA512:
6
- metadata.gz: abd4ddf4ef561a50d17ca25fb4cf62e84edff52f95066313585c9c92a62460edcd20ba46a7dfd6d478a52e1c2286c031cce42b6a1f5a906d2a014ca4bbde7319
7
- data.tar.gz: 167df14e02f8736cd0d58023c0372ec3d5d0a579c9f46dbcd3a8950de805ee476f0c1ab1017dd10c107c98262bc6add2289cc7081c309c15ca5c68831bcc7a56
6
+ metadata.gz: 302bc95abceca07d03495259b28b7a6605e2e204ee081ce8a208df80e89f306a5d14084d029b4fd904d88456c8bcf3da37cd9369aebe2b14a4d5bca0553ab7c6
7
+ data.tar.gz: aa443e757687fa058a044ed5ec2e746d8adb3d1bd7dcec14b9fe8c27b382620a1997ebd9a9aed6c69928ee0f2100b66037577fe95601d50105736b12b80ed059
@@ -59,6 +59,10 @@ module Cloudpassage
59
59
  JSON.parse(@base_resource.post payload.to_json, headers)
60
60
  end
61
61
 
62
+ def put(payload)
63
+ JSON.parse(@base_resource.put payload.to_json, headers)
64
+ end
65
+
62
66
  # Convert class name to symbol.
63
67
  # eg: CloudPassage::Users --> :users
64
68
  def object_symbol
@@ -77,4 +81,4 @@ module Cloudpassage
77
81
  end
78
82
  end
79
83
  end
80
- end
84
+ end
@@ -1,3 +1,4 @@
1
+ require 'cloudpassage'
1
2
  module Cloudpassage
2
3
 
3
4
  # Policies
@@ -11,4 +12,4 @@ module Cloudpassage
11
12
 
12
13
  class Policy < Single
13
14
  end
14
- end
15
+ end
@@ -3,7 +3,7 @@ require 'cloudpassage'
3
3
 
4
4
  # Module to make it easy to use stuff from pry (or any sort of interactive debugger)
5
5
  module Cloudpassage::Pry
6
- def cloudpassage(type)
6
+ def self.cloudpassage(type)
7
7
  type_section = Cloudpassage::Pry::section(type)
8
8
  Cloudpassage::Api.new(Cloudpassage.token(type_section['id'], type_section['secret']))
9
9
  end
@@ -19,4 +19,4 @@ module Cloudpassage::Pry
19
19
  def self.config_file
20
20
  ENV.fetch('CLOUDPASSAGE_CONFIG_FILE', "#{ENV['HOME']}/.cloudpassagerc")
21
21
  end
22
- end
22
+ end
@@ -3,8 +3,8 @@ module Cloudpassage
3
3
  include Collection
4
4
 
5
5
  def filter(options={})
6
- servers = JSON.parse(@base_resource.get(headers.merge(:params=>options)), :symbolize_names=>true)[:servers]
7
- servers.map { |i| get(i[:id], i) }
6
+ servers = JSON.parse(@base_resource.get(headers.merge(:params=>options)), :symbolize_names=>true)[:servers]
7
+ servers.map { |i| get(i[:id], i) }
8
8
  end
9
9
 
10
10
  def singleton_class
@@ -68,16 +68,29 @@ module Cloudpassage
68
68
  # Creates username, in the given group.
69
69
  # If opts[:password] is specified, that password will be used.
70
70
  # Otherwise, password will be generated.
71
+ # If opts
71
72
  def create(username, groups = '', opts = {})
72
- payload = {'account' => {
73
- :username => username,
74
- :comment => '',
75
- :groups => groups,
76
- :password => password_opts.merge(opts.fetch(:password, {})),
77
- }}
73
+ payload = {
74
+ :account => {
75
+ :username => username,
76
+ :comment => '',
77
+ :groups => groups,
78
+ :password => password_opts.merge(opts.fetch(:password, {}))
79
+ }
80
+ }
78
81
  @server.commands.get(post(payload)['command']['id'])
79
82
  end
80
83
 
84
+ def set_ssh_keys(username, *keys)
85
+ keys = *keys
86
+ payload = {
87
+ :account => {
88
+ :ssh_authorized_keys => keys.map{|k|{:key=>k}}
89
+ }
90
+ }
91
+ @server.commands.get(JSON.parse(@base_resource[username].put(payload.to_json, headers))['command']['id'])
92
+ end
93
+
81
94
  def reset(username, opts = {})
82
95
  payload = {'password' => password_opts.merge(opts)}
83
96
  JSON.parse @base_resource[username]['password'].put(payload.to_json, headers)
@@ -100,6 +113,12 @@ module Cloudpassage
100
113
  :include_uppercase => true
101
114
  }
102
115
  end
116
+
117
+ def ssh_keys_opts(opts)
118
+ keys = opts.fetch(:keys, [])
119
+ keys.map{|k|{:key=>k}}
120
+ end
121
+
103
122
  end
104
123
 
105
124
  class Issues < Base
@@ -127,4 +146,5 @@ module Cloudpassage
127
146
 
128
147
  class Issue < Single;end
129
148
  class Account < Single;end
149
+
130
150
  end
@@ -1,4 +1,4 @@
1
1
  module Cloudpassage
2
2
  # Version
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.10'
4
4
  end
data/spec/api_spec.rb CHANGED
@@ -1,5 +1,6 @@
1
- require File.join(File.dirname(__FILE__), '..', 'lib', 'cloudpassage')
2
- require File.join(File.dirname(__FILE__), '..', 'lib', 'cloudpassage', 'pry')
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require'cloudpassage/pry'
3
4
  require 'rspec'
4
5
 
5
6
  module Cloudpassage
@@ -7,20 +8,23 @@ module Cloudpassage
7
8
  attr_reader :api
8
9
 
9
10
  before :each do
10
- @api = Cloudpassage::Pry::cloudpassage(:test)
11
+ Cloudpassage.stub(:token){ 'token' }
12
+ Cloudpassage::Pry.stub(:yaml){({'test'=>{'id'=>'id', 'secret'=>'secret'}})}
13
+ @api = Cloudpassage::Pry.cloudpassage(:test)
14
+ RestClient::Resource.stub(:new){resource}
11
15
  end
12
16
 
13
17
  def self.collections
14
18
  [
15
- :configuration_policies,
16
- :events,
17
- :file_integrity_policies,
18
- :firewall_interfaces,
19
- :firewall_policies,
20
- :firewall_services,
21
- :firewall_zones,
22
- :server_groups,
23
- :users
19
+ :configuration_policies,
20
+ :events,
21
+ :file_integrity_policies,
22
+ :firewall_interfaces,
23
+ :firewall_policies,
24
+ :firewall_services,
25
+ :firewall_zones,
26
+ :server_groups,
27
+ :users
24
28
  ]
25
29
  end
26
30
 
@@ -28,14 +32,12 @@ module Cloudpassage
28
32
  it "should retrieve data for #{type}" do
29
33
  api.send(type).data
30
34
  end
35
+ end
31
36
 
32
- it "should parse data for #{type} as json" do
33
- # Get the collection
34
- collection = api.send(type)
35
-
36
- # Reload a single instance of each object type.
37
- collection.all[0].reload.data
37
+ def resource
38
+ @resource ||= double('resource').tap do |r|
39
+ r.stub(:get=>'{}')
38
40
  end
39
41
  end
40
42
  end
41
- end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudpassage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - mshea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-18 00:00:00.000000000 Z
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.0.3
151
+ rubygems_version: 2.2.2
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Cloudpassage