cloudpassage 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.pryrc +1 -1
- data/README.md +12 -0
- data/lib/cloudpassage/api.rb +13 -1
- data/lib/cloudpassage/base.rb +10 -1
- data/lib/cloudpassage/cloudpassage.rb +6 -4
- data/lib/cloudpassage/collection.rb +3 -3
- data/lib/cloudpassage/events.rb +2 -0
- data/lib/cloudpassage/file_integrity_baselines.rb +1 -0
- data/lib/cloudpassage/fim_policies.rb +1 -0
- data/lib/cloudpassage/firewall_interfaces.rb +2 -0
- data/lib/cloudpassage/firewall_policies.rb +2 -0
- data/lib/cloudpassage/firewall_rules.rb +2 -0
- data/lib/cloudpassage/firewall_services.rb +2 -0
- data/lib/cloudpassage/firewall_zones.rb +2 -0
- data/lib/cloudpassage/groups.rb +2 -0
- data/lib/cloudpassage/policies.rb +2 -0
- data/lib/cloudpassage/pry.rb +7 -6
- data/lib/cloudpassage/servers.rb +22 -1
- data/lib/cloudpassage/single.rb +6 -0
- data/lib/cloudpassage/users.rb +1 -0
- data/lib/cloudpassage/version.rb +2 -1
- data/spec/api_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f885d2347066b179712e43dae23e79c82f8a2f5
|
4
|
+
data.tar.gz: b0259a907cc18cdcfce0233ee452fb1465a2ad4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abd4ddf4ef561a50d17ca25fb4cf62e84edff52f95066313585c9c92a62460edcd20ba46a7dfd6d478a52e1c2286c031cce42b6a1f5a906d2a014ca4bbde7319
|
7
|
+
data.tar.gz: 167df14e02f8736cd0d58023c0372ec3d5d0a579c9f46dbcd3a8950de805ee476f0c1ab1017dd10c107c98262bc6add2289cc7081c309c15ca5c68831bcc7a56
|
data/.gitignore
CHANGED
data/.pryrc
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'cloudpassage/pry'
|
2
|
-
|
2
|
+
extend Cloudpassage::Pry
|
data/README.md
CHANGED
@@ -49,6 +49,18 @@ Or install it yourself as:
|
|
49
49
|
puts api.servers.all[0].accounts.all
|
50
50
|
puts api.servers.all[0].issues.all
|
51
51
|
puts api.server_groups.all[0].groups.all
|
52
|
+
|
53
|
+
# Add/move a server to a group (groups are case-sensitive)
|
54
|
+
api.servers.get('some_id').group='some_group_id'
|
55
|
+
|
56
|
+
# List servers by passing in state (missing, deactivated, active)
|
57
|
+
api.servers.filter(:state=>'missing')
|
58
|
+
|
59
|
+
# Delete a server permanently
|
60
|
+
api.servers.get('id').destroy
|
61
|
+
|
62
|
+
# Retire a 'inactive' server
|
63
|
+
api.servers.get('id').retire
|
52
64
|
|
53
65
|
# Get specific things.
|
54
66
|
puts api.file_integrity_policies.get('file_integrity_policy_id').data.to_json
|
data/lib/cloudpassage/api.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module Cloudpassage
|
2
2
|
|
3
|
-
BASE_URL='https://api.cloudpassage.com/v1/'
|
3
|
+
BASE_URL = 'https://api.cloudpassage.com/v1/'
|
4
4
|
|
5
|
+
# Obtains a new API object by generating a token using id + secret.
|
5
6
|
def self.api(id, secret)
|
6
7
|
Api.new(self.token(id, secret))
|
7
8
|
end
|
8
9
|
|
10
|
+
# Interface to all cloudpassage stuff
|
9
11
|
class Api
|
10
12
|
attr_reader :token, :base_resource
|
11
13
|
|
@@ -14,42 +16,52 @@ module Cloudpassage
|
|
14
16
|
@base_resource = RestClient::Resource.new(BASE_URL)
|
15
17
|
end
|
16
18
|
|
19
|
+
# Configuration policies
|
17
20
|
def configuration_policies
|
18
21
|
Policies.new(token, base_resource['policies'])
|
19
22
|
end
|
20
23
|
|
24
|
+
# Events
|
21
25
|
def events
|
22
26
|
Events.new(token, base_resource['events'])
|
23
27
|
end
|
24
28
|
|
29
|
+
# File integrity policies
|
25
30
|
def file_integrity_policies
|
26
31
|
FimPolicies.new(token, base_resource['fim_policies'])
|
27
32
|
end
|
28
33
|
|
34
|
+
# Firewall interfaces
|
29
35
|
def firewall_interfaces
|
30
36
|
FirewallInterfaces.new(token, base_resource['firewall_interfaces'])
|
31
37
|
end
|
32
38
|
|
39
|
+
# Firewall policies
|
33
40
|
def firewall_policies
|
34
41
|
FirewallPolicies.new(token, base_resource['firewall_policies'])
|
35
42
|
end
|
36
43
|
|
44
|
+
# Firewall services
|
37
45
|
def firewall_services
|
38
46
|
FirewallServices.new(token, base_resource['firewall_services'])
|
39
47
|
end
|
40
48
|
|
49
|
+
# Firewall zones
|
41
50
|
def firewall_zones
|
42
51
|
FirewallZones.new(token, base_resource['firewall_zones'])
|
43
52
|
end
|
44
53
|
|
54
|
+
# Servers
|
45
55
|
def servers
|
46
56
|
Servers.new(token, base_resource['servers'])
|
47
57
|
end
|
48
58
|
|
59
|
+
# Groups
|
49
60
|
def server_groups
|
50
61
|
Groups.new(token, base_resource['groups'])
|
51
62
|
end
|
52
63
|
|
64
|
+
# Users
|
53
65
|
def users
|
54
66
|
Users.new(token, base_resource['users'])
|
55
67
|
end
|
data/lib/cloudpassage/base.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'wait'
|
2
2
|
|
3
3
|
module Cloudpassage
|
4
|
+
|
5
|
+
# Default options to use when waiting.
|
4
6
|
def self.wait_options
|
5
7
|
{
|
6
8
|
:attempts => 50000,
|
@@ -10,6 +12,7 @@ module Cloudpassage
|
|
10
12
|
}
|
11
13
|
end
|
12
14
|
|
15
|
+
# Base class representing cloudpassage objects.
|
13
16
|
class Base
|
14
17
|
def initialize(token, base_resource, data=nil)
|
15
18
|
@token = token
|
@@ -17,6 +20,8 @@ module Cloudpassage
|
|
17
20
|
@data = data
|
18
21
|
end
|
19
22
|
|
23
|
+
# Return data from sending http GET to underlying resource.
|
24
|
+
# Uses cached value if resource has been retrieved already.
|
20
25
|
def data
|
21
26
|
if @data.nil?
|
22
27
|
@data = JSON.parse(@base_resource.get(headers), :symbolize_names=>true)[object_symbol]
|
@@ -33,6 +38,7 @@ module Cloudpassage
|
|
33
38
|
{'Authorization'=>"Bearer #{@token}"}
|
34
39
|
end
|
35
40
|
|
41
|
+
# If method is missing, try to pass through to underlying data hash.
|
36
42
|
def method_missing(sym, *args, &block)
|
37
43
|
if (data && data[sym])
|
38
44
|
data[sym]
|
@@ -58,9 +64,12 @@ module Cloudpassage
|
|
58
64
|
def object_symbol
|
59
65
|
class_name = self.class.name
|
60
66
|
index = class_name.rindex(/::/)
|
61
|
-
class_name[index+2
|
67
|
+
class_name[index + 2 .. -1].underscore.to_sym
|
62
68
|
end
|
63
69
|
|
70
|
+
# Wait for block to evaluate to true.
|
71
|
+
# If specified, options can be used to override default options.
|
72
|
+
# Options should conform to https://rubygems.org/gems/wait
|
64
73
|
def wait_for(options={}, &block)
|
65
74
|
Wait.new(Cloudpassage::wait_options.merge(options)).until do
|
66
75
|
reload
|
@@ -5,6 +5,7 @@ require 'json'
|
|
5
5
|
module Cloudpassage
|
6
6
|
RestClient.proxy = ENV['HTTPS_PROXY'] if ENV['HTTPS_PROXY'].to_s.length > 0
|
7
7
|
|
8
|
+
# Obtain an oauth token using id and secret
|
8
9
|
def self.token(client_id, client_secret)
|
9
10
|
client = OAuth2::Client.new(client_id, client_secret,
|
10
11
|
:connection_opts => { :proxy => ENV['HTTPS_PROXY'] },
|
@@ -16,11 +17,12 @@ end
|
|
16
17
|
|
17
18
|
# Add camel-to-snake-case conversion
|
18
19
|
class String
|
20
|
+
|
21
|
+
# returns camel-case representation of snake-case string.
|
19
22
|
def underscore
|
20
23
|
self.gsub(/::/, '/').
|
21
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
22
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
23
|
-
tr(
|
24
|
-
downcase
|
24
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
25
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
26
|
+
tr('-', '_').downcase
|
25
27
|
end
|
26
28
|
end
|
data/lib/cloudpassage/events.rb
CHANGED
data/lib/cloudpassage/groups.rb
CHANGED
data/lib/cloudpassage/pry.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'cloudpassage'
|
3
3
|
|
4
|
+
# Module to make it easy to use stuff from pry (or any sort of interactive debugger)
|
4
5
|
module Cloudpassage::Pry
|
5
6
|
def cloudpassage(type)
|
6
|
-
type_section = section(type)
|
7
|
+
type_section = Cloudpassage::Pry::section(type)
|
7
8
|
Cloudpassage::Api.new(Cloudpassage.token(type_section['id'], type_section['secret']))
|
8
9
|
end
|
9
10
|
|
10
|
-
def section(type)
|
11
|
-
yaml
|
11
|
+
def self.section(type)
|
12
|
+
yaml.fetch(type.to_s)
|
12
13
|
end
|
13
14
|
|
14
|
-
def yaml
|
15
|
-
|
15
|
+
def self.yaml
|
16
|
+
@yaml ||= YAML.load(File.read(config_file))
|
16
17
|
end
|
17
18
|
|
18
|
-
def config_file
|
19
|
+
def self.config_file
|
19
20
|
ENV.fetch('CLOUDPASSAGE_CONFIG_FILE', "#{ENV['HOME']}/.cloudpassagerc")
|
20
21
|
end
|
21
22
|
end
|
data/lib/cloudpassage/servers.rb
CHANGED
@@ -2,9 +2,15 @@ module Cloudpassage
|
|
2
2
|
class Servers < Base
|
3
3
|
include Collection
|
4
4
|
|
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) }
|
8
|
+
end
|
9
|
+
|
5
10
|
def singleton_class
|
6
11
|
Server
|
7
12
|
end
|
13
|
+
|
8
14
|
end
|
9
15
|
|
10
16
|
class Server < Single
|
@@ -21,6 +27,17 @@ module Cloudpassage
|
|
21
27
|
Accounts.new(self, @token, @base_resource['accounts'])
|
22
28
|
end
|
23
29
|
|
30
|
+
def retire
|
31
|
+
# retire a 'inactive' server
|
32
|
+
payload = {"server"=>{"retire"=>true}}
|
33
|
+
@base_resource.put(payload.to_json, headers.merge(:content_type => :json))
|
34
|
+
end
|
35
|
+
|
36
|
+
def group=(group_id)
|
37
|
+
# add server to group
|
38
|
+
payload = {"server"=>{"group_id"=>group_id}}
|
39
|
+
@base_resource.put(payload.to_json, headers.merge(:content_type => :json))
|
40
|
+
end
|
24
41
|
|
25
42
|
def commands
|
26
43
|
Commands.new(@token, @base_resource['commands'])
|
@@ -31,6 +48,7 @@ module Cloudpassage
|
|
31
48
|
end
|
32
49
|
end
|
33
50
|
|
51
|
+
# Accounts on a server
|
34
52
|
class Accounts < Base
|
35
53
|
include Collection
|
36
54
|
|
@@ -44,9 +62,12 @@ module Cloudpassage
|
|
44
62
|
end
|
45
63
|
|
46
64
|
def all
|
47
|
-
data.map{|i| get(i[:username], i)}
|
65
|
+
data.map { |i| get(i[:username], i) }
|
48
66
|
end
|
49
67
|
|
68
|
+
# Creates username, in the given group.
|
69
|
+
# If opts[:password] is specified, that password will be used.
|
70
|
+
# Otherwise, password will be generated.
|
50
71
|
def create(username, groups = '', opts = {})
|
51
72
|
payload = {'account' => {
|
52
73
|
:username => username,
|
data/lib/cloudpassage/single.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
module Cloudpassage
|
4
|
+
|
5
|
+
# Single objects.
|
4
6
|
class Single < Base
|
5
7
|
|
6
8
|
attr_reader :id
|
@@ -13,5 +15,9 @@ module Cloudpassage
|
|
13
15
|
def get
|
14
16
|
@base_resource.get(headers)
|
15
17
|
end
|
18
|
+
|
19
|
+
def destroy
|
20
|
+
@base_resource.delete(headers)
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
data/lib/cloudpassage/users.rb
CHANGED
data/lib/cloudpassage/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'cloudpassage')
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'cloudpassage', 'pry')
|
2
3
|
require 'rspec'
|
3
4
|
|
4
5
|
module Cloudpassage
|
@@ -6,8 +7,7 @@ module Cloudpassage
|
|
6
7
|
attr_reader :api
|
7
8
|
|
8
9
|
before :each do
|
9
|
-
|
10
|
-
@api = Cloudpassage::Api.new(token)
|
10
|
+
@api = Cloudpassage::Pry::cloudpassage(:test)
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.collections
|
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.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mshea
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|