train-digitalocean 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +13 -0
- data/README.md +69 -0
- data/lib/train-digitalocean.rb +7 -0
- data/lib/train-digitalocean/connection.rb +44 -0
- data/lib/train-digitalocean/platform.rb +8 -0
- data/lib/train-digitalocean/transport.rb +13 -0
- data/lib/train-digitalocean/version.rb +5 -0
- data/train-digitalocean.gemspec +22 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e05cb718b32c0df695a406df5e36b7e44d03f3c1
|
4
|
+
data.tar.gz: 4ae64fe0705e82d9eb5e1bd339bcba0b41e79b83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75ab53e959b99382ebd54141bcfe3ba73369bc33af73587c24d81d92b137f0ffc74c2e0145df841aeba7076540d7671e8959cb4bc1c2712b843815764183bf79
|
7
|
+
data.tar.gz: 49b597f3965293a1d51faac2ecc17032249f604e5b86cebe26036cf59de6a6b7de828aaa27419a3cc39bd751e5992bec16f2aa92fd7ebd07a7b5eff7675c922a
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
source 'https://rubygems.org'
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
# Remaining group is only used for development.
|
6
|
+
group :development do
|
7
|
+
gem 'bundler'
|
8
|
+
gem 'byebug'
|
9
|
+
gem 'inspec', '>= 2.2.112' # We need InSpec for the test harness while developing.
|
10
|
+
gem 'minitest'
|
11
|
+
gem 'rake'
|
12
|
+
gem 'rubocop', '= 0.49.1' # Need to keep in sync with main InSpec project, so config files will work
|
13
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Digitalocean transport plugin for Train
|
2
|
+
|
3
|
+
This plugin allows applications that rely on Train to communicate with the Digitalocean API. For example, InSpec uses this to perform compliance checks against Digitalocean infrastructure. Train plugins are managed by InSpec CLI.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
When used in combination with the [InSpec Digitalocean resource pack](https://github.com/chris-rock/inspec-digitalocean) you can e.g. verify droplets:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
describe digitalocean_droplet(id: '123456') do
|
11
|
+
it { should exist }
|
12
|
+
its('name') { should eq 'nginx-web-ams3' }
|
13
|
+
its('image') { should eq 'ubuntu-16-04-x64' }
|
14
|
+
its('region') { should eq 'ams3' }
|
15
|
+
its('size') { should eq 's-1vcpu-1gb' }
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
## Preconditions
|
20
|
+
|
21
|
+
- InSpec 3 or later.
|
22
|
+
- [Digitalocean API key](https://cloud.digitalocean.com/account/api/tokens)
|
23
|
+
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Train plugins are distributed as gems. You may choose to manage the gem yourself, but if you are an InSpec user, InSPec can handle it for you.
|
28
|
+
|
29
|
+
Simply run:
|
30
|
+
|
31
|
+
```
|
32
|
+
$ inspec plugin install train-digitalocean
|
33
|
+
```
|
34
|
+
|
35
|
+
In order to use this example, you need to create a [DigitalOcean API Token](https://cloud.digitalocean.com/account/api/tokens) and export it as an environment variable.
|
36
|
+
|
37
|
+
```bash
|
38
|
+
export DIGITALOCEAN_TOKEN="Put Your Token Here"
|
39
|
+
```
|
40
|
+
|
41
|
+
Verify the plugin and the connection to Digitalocean
|
42
|
+
|
43
|
+
```
|
44
|
+
$ inspec detect -t digitalocean://
|
45
|
+
|
46
|
+
== Platform Details
|
47
|
+
|
48
|
+
Name: digitalocean
|
49
|
+
Families: cloud, api
|
50
|
+
Release: 0.1.0
|
51
|
+
```
|
52
|
+
|
53
|
+
## Authenticating to Digitalocean
|
54
|
+
|
55
|
+
You need to set the `DIGITALOCEAN_TOKEN` environment variable with your credentials.
|
56
|
+
|
57
|
+
## Reporting Issues
|
58
|
+
|
59
|
+
Bugs, typos, limitations, and frustrations are welcome to be reported through the [GitHub issues page for the train-digitalocean project](https://github.com/chris-rock/train-digitalocean/issues).
|
60
|
+
|
61
|
+
You may also ask questions in the #inspec channel of the CHef Community Slack team. However, for an issue to get traction, please report it as a github issue.
|
62
|
+
|
63
|
+
### Development Process
|
64
|
+
|
65
|
+
If you wish to contribute to this plugin, please use the usual fork-branch-push-PR cycle. All functional changes need new tests, and bugfixes are expected to include a new test that demonstrates the bug.
|
66
|
+
|
67
|
+
### Reference Information
|
68
|
+
|
69
|
+
[Plugin Development](https://github.com/inspec/train/blob/master/docs/dev/plugins.md) is documented on the `train` project on GitHub.
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'droplet_kit'
|
2
|
+
require 'train-digitalocean/platform'
|
3
|
+
|
4
|
+
module TrainPlugins
|
5
|
+
module Digitalocean
|
6
|
+
class Connection < Train::Plugins::Transport::BaseConnection
|
7
|
+
include TrainPlugins::Digitalocean::Platform
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
msg = 'You need to set the Digitalocean access token via \'export DIGITALOCEAN_TOKEN=.\''
|
11
|
+
if options.nil? || options[:access_token].nil?
|
12
|
+
raise Train::TransportError, msg
|
13
|
+
end
|
14
|
+
|
15
|
+
super(options)
|
16
|
+
|
17
|
+
# check account to verify authentication
|
18
|
+
begin
|
19
|
+
@uuid = droplet_client.account.info.uuid
|
20
|
+
rescue DropletKit::Error
|
21
|
+
raise Train::TransportError, msg
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def local?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
def uri
|
30
|
+
"digitalocean://"
|
31
|
+
end
|
32
|
+
|
33
|
+
def droplet_client
|
34
|
+
klass = ::DropletKit::Client
|
35
|
+
return klass.new(access_token: @options[:access_token]) unless cache_enabled?(:api_call)
|
36
|
+
@cache[:api_call][klass.to_s.to_sym] ||= klass.new(access_token: @options[:access_token])
|
37
|
+
end
|
38
|
+
|
39
|
+
def unique_identifier
|
40
|
+
@uuid
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'train-digitalocean/connection'
|
2
|
+
|
3
|
+
module TrainPlugins
|
4
|
+
module Digitalocean
|
5
|
+
class Transport < Train.plugin(1)
|
6
|
+
name 'digitalocean'
|
7
|
+
option :access_token, default: ENV['DIGITALOCEAN_TOKEN']
|
8
|
+
def connection(_instance_opts = nil)
|
9
|
+
@connection ||= TrainPlugins::Digitalocean::Connection.new(@options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'train-digitalocean/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'train-digitalocean'
|
7
|
+
spec.version = TrainPlugins::Digitalocean::VERSION
|
8
|
+
spec.authors = ['Christoph Hartmann']
|
9
|
+
spec.email = ['chris@lollyrock.com']
|
10
|
+
spec.summary = "Digitalocean plugin for InSpec's Backend"
|
11
|
+
spec.description = 'This plugin provides the backend handling for InSpec to talk to digitalocean'
|
12
|
+
spec.homepage = 'https://github.com/chris-rock/train-digitaloceann'
|
13
|
+
spec.license = 'Apache-2.0'
|
14
|
+
spec.files = %w{
|
15
|
+
README.md train-digitalocean.gemspec Gemfile
|
16
|
+
} + Dir.glob(
|
17
|
+
'lib/**/*', File::FNM_DOTMATCH
|
18
|
+
).reject { |f| File.directory?(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
spec.add_dependency 'droplet_kit', '~> 2.4'
|
21
|
+
spec.add_dependency 'train', '~> 1.4'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: train-digitalocean
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christoph Hartmann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: droplet_kit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: train
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
description: This plugin provides the backend handling for InSpec to talk to digitalocean
|
42
|
+
email:
|
43
|
+
- chris@lollyrock.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- README.md
|
50
|
+
- lib/train-digitalocean.rb
|
51
|
+
- lib/train-digitalocean/connection.rb
|
52
|
+
- lib/train-digitalocean/platform.rb
|
53
|
+
- lib/train-digitalocean/transport.rb
|
54
|
+
- lib/train-digitalocean/version.rb
|
55
|
+
- train-digitalocean.gemspec
|
56
|
+
homepage: https://github.com/chris-rock/train-digitaloceann
|
57
|
+
licenses:
|
58
|
+
- Apache-2.0
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.5.2.3
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Digitalocean plugin for InSpec's Backend
|
80
|
+
test_files: []
|