cloudimages-rundeck 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a57a627506f61d53b5b981fcb99654a1e8cf801f
4
+ data.tar.gz: 820ebabc8a9a17e75c5d41595adb01e42007b686
5
+ SHA512:
6
+ metadata.gz: ec54b452eaa88e35b9cf9a2485f17a47677d05f25ac66aa74e1682b3d5ec544ebaa1907b841c9b332e0f6f334984c7c585db52d0e6e348a0509953dde161af5a
7
+ data.tar.gz: 86ab38b34298667831adc909cb512df90a082a2bf94e72a49f39f128d616a3fa22830d1e971e24f1c2cc1f6efd8ef92ac22de1dbb56137ad69152da105911c5a
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *~
2
+ *#
3
+ .#*
4
+ \#*#
5
+ .*.sw[a-z]
6
+ *.un~
7
+ pkg/
8
+ vendor/
9
+ config.json
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,36 @@
1
+ before_script:
2
+ - ruby -v
3
+ - which ruby
4
+ - gem install bundler --no-ri --no-rdoc
5
+ - bundle install --jobs $(nproc) --path vendor/bundle
6
+
7
+ test:Ruby 2.3:
8
+ image: ruby:2.3
9
+ cache:
10
+ paths:
11
+ - .bundle
12
+ - vendor/bundle
13
+ script:
14
+ - bundle exec rubocop
15
+ tags:
16
+ - ruby
17
+ except:
18
+ - tags
19
+
20
+ release:Ruby 2.3:
21
+ image: ruby:2.3
22
+ cache:
23
+ paths:
24
+ - .bundle
25
+ - vendor/bundle
26
+ script:
27
+ - bundle exec rubocop
28
+ - bundle exec rake build
29
+ artifacts:
30
+ name: "cloudimages-rundeck-$CI_BUILD_REF_NAME"
31
+ paths:
32
+ - pkg/*.gem
33
+ tags:
34
+ - ruby
35
+ only:
36
+ - tags
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ Style/ModuleFunction:
2
+ Enabled: false
3
+
4
+ Style/WordArray:
5
+ Enabled: false
6
+
7
+ Style/FileName:
8
+ Enabled: false
9
+
10
+ AllCops:
11
+ Include:
12
+ - lib/
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'droplet_kit' # => DigitalOcean API Interaction
4
+ # => gem 'hashie' # => Data Structure
5
+ # => gem 'logify' # => Logging
6
+ gem 'mixlib-cli' # => Option Parsing
7
+ gem 'rack-cache' # => Cache Responses
8
+ gem 'sinatra' # => Web Server
9
+ gem 'sinatra-contrib' # => For namespaces
10
+
11
+ group :development do
12
+ gem 'rake'
13
+ gem 'rspec'
14
+ gem 'rubocop'
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,108 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (5.0.0.1)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (~> 0.7)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ addressable (2.3.8)
10
+ ast (2.3.0)
11
+ axiom-types (0.1.1)
12
+ descendants_tracker (~> 0.0.4)
13
+ ice_nine (~> 0.11.0)
14
+ thread_safe (~> 0.3, >= 0.3.1)
15
+ backports (3.6.8)
16
+ coercible (1.0.0)
17
+ descendants_tracker (~> 0.0.1)
18
+ concurrent-ruby (1.0.2)
19
+ descendants_tracker (0.0.4)
20
+ thread_safe (~> 0.3, >= 0.3.1)
21
+ diff-lcs (1.2.5)
22
+ droplet_kit (1.4.3)
23
+ activesupport (> 3.0, < 5.1)
24
+ faraday (~> 0.9.1)
25
+ kartograph (~> 0.2.3)
26
+ resource_kit (~> 0.1.5)
27
+ virtus (~> 1.0.3)
28
+ equalizer (0.0.11)
29
+ faraday (0.9.2)
30
+ multipart-post (>= 1.2, < 3)
31
+ i18n (0.7.0)
32
+ ice_nine (0.11.2)
33
+ kartograph (0.2.4)
34
+ minitest (5.8.3)
35
+ mixlib-cli (1.7.0)
36
+ multi_json (1.12.1)
37
+ multipart-post (2.0.0)
38
+ parser (2.3.1.2)
39
+ ast (~> 2.2)
40
+ powerpack (0.1.1)
41
+ rack (1.6.4)
42
+ rack-cache (1.6.1)
43
+ rack (>= 0.4)
44
+ rack-protection (1.5.3)
45
+ rack
46
+ rack-test (0.6.3)
47
+ rack (>= 1.0)
48
+ rainbow (2.1.0)
49
+ rake (11.2.2)
50
+ resource_kit (0.1.5)
51
+ addressable (~> 2.3.6)
52
+ rspec (3.5.0)
53
+ rspec-core (~> 3.5.0)
54
+ rspec-expectations (~> 3.5.0)
55
+ rspec-mocks (~> 3.5.0)
56
+ rspec-core (3.5.2)
57
+ rspec-support (~> 3.5.0)
58
+ rspec-expectations (3.5.0)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.5.0)
61
+ rspec-mocks (3.5.0)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.5.0)
64
+ rspec-support (3.5.0)
65
+ rubocop (0.42.0)
66
+ parser (>= 2.3.1.1, < 3.0)
67
+ powerpack (~> 0.1)
68
+ rainbow (>= 1.99.1, < 3.0)
69
+ ruby-progressbar (~> 1.7)
70
+ unicode-display_width (~> 1.0, >= 1.0.1)
71
+ ruby-progressbar (1.8.1)
72
+ sinatra (1.4.7)
73
+ rack (~> 1.5)
74
+ rack-protection (~> 1.4)
75
+ tilt (>= 1.3, < 3)
76
+ sinatra-contrib (1.4.7)
77
+ backports (>= 2.0)
78
+ multi_json
79
+ rack-protection
80
+ rack-test
81
+ sinatra (~> 1.4.0)
82
+ tilt (>= 1.3, < 3)
83
+ thread_safe (0.3.5)
84
+ tilt (2.0.5)
85
+ tzinfo (1.2.2)
86
+ thread_safe (~> 0.1)
87
+ unicode-display_width (1.1.0)
88
+ virtus (1.0.5)
89
+ axiom-types (~> 0.1)
90
+ coercible (~> 1.0)
91
+ descendants_tracker (~> 0.0, >= 0.0.3)
92
+ equalizer (~> 0.0, >= 0.0.9)
93
+
94
+ PLATFORMS
95
+ ruby
96
+
97
+ DEPENDENCIES
98
+ droplet_kit
99
+ mixlib-cli
100
+ rack-cache
101
+ rake
102
+ rspec
103
+ rubocop
104
+ sinatra
105
+ sinatra-contrib
106
+
107
+ BUNDLED WITH
108
+ 1.12.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Brian Dwyer - Intelligent Digital Services
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.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # cloudimages-rundeck
2
+ * Cloud Image Information Provider for RunDeck
3
+ * Polls Cloud Provider API's for available images
4
+
5
+ ## Supported Providers
6
+ * DigitalOcean
7
+
8
+ ## Background
9
+ This project's initial purpose is/was to retrieve a list of available base images to feed into a RunDeck job. It can be tedious to update jobs after a new image is created.
10
+ You can also pass a filter query parameter which will search (case insensitive) for matching images. You can pass multiple things to search for using commas to seperate them, e.g. ```^ubuntu,^centos```
11
+
12
+ **NOTE:** This API should **NOT** be exposed to the world unless you plan to secure it with a reverse-proxy or something. It is intended to only be bound to `localhost` on the same server as RunDeck.
13
+
14
+ ## Running as a Service
15
+ You'll likely want to run this as a service, `SystemD` or `Upstart` will likely be your friend in this regard.
16
+
17
+ ## Security
18
+ You should lock down permissions on all configuration files in this project to only the user which this runs as...
19
+
20
+ To run this project securely, **DON'T** run it as the RunDeck user.
21
+
22
+ ## Caching
23
+ This leans on `rack-cache` to serve as a caching mechanism. The objective here was to make sure we don't pummel the Chef API with redundant queries.
24
+ * Timeout can be configured via the `cache_timeout` setting. **Default:** *30 seconds*
25
+
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'cloudimages-rundeck'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install cloudimages-rundeck
42
+
43
+ ## Usage
44
+
45
+ TODO: Write usage instructions here
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bdwyertech/cloudimages-rundeck. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
56
+
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'bundler/setup'
7
+ require 'cloudimages-rundeck'
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require 'irb'
17
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+ # rubocop: disable LineLength
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'cloudimages-rundeck/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'cloudimages-rundeck'
10
+ spec.version = CloudImagesRunDeck::VERSION
11
+ spec.authors = ['Brian Dwyer']
12
+ spec.email = ['bdwyer@IEEE.org']
13
+
14
+ spec.summary = %(Cloud Image Information Provider for RunDeck)
15
+ # => spec.description = %q(TODO: Write a longer description or delete this line.)
16
+ spec.homepage = 'https://github.com/bdwyertech/cloudimages-rundeck'
17
+ spec.license = 'MIT'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
23
+ else
24
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
25
+ end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ # => Dependencies
33
+ spec.add_runtime_dependency 'droplet_kit', '~> 1.4'
34
+ spec.add_runtime_dependency 'mixlib-cli', '~> 1.6'
35
+ spec.add_runtime_dependency 'rack-cache', '~> 1.6'
36
+ spec.add_runtime_dependency 'sinatra', '~> 1.4'
37
+ spec.add_runtime_dependency 'sinatra-contrib', '~> 1.4'
38
+
39
+ # => Development Dependencies
40
+ spec.add_development_dependency 'bundler', '~> 1.12'
41
+ spec.add_development_dependency 'rake', '~> 10.0'
42
+ spec.add_development_dependency 'rspec', '~> 3.0'
43
+ spec.add_development_dependency 'rubocop'
44
+ end
@@ -0,0 +1,7 @@
1
+ {
2
+ "cache_timeout": 30,
3
+ "bind": "localhost",
4
+ "port": 9129,
5
+ "environment": "production",
6
+ "do_api_key": "abc123"
7
+ }
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # Cloud Image Information Provider for RunDeck
4
+ # Brian Dwyer - Intelligent Digital Services - 10/6/16
5
+
6
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+
9
+ # => Catch Ctrl+C's to avoid stack traces
10
+ Signal.trap('INT') { abort }
11
+
12
+ require 'cloudimages-rundeck'
13
+
14
+ CloudImagesRunDeck::CLI.run(ARGV)
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+ # rubocop: disable LineLength
3
+ # Cloud Image Information Provider for RunDeck
4
+ # Brian Dwyer - Intelligent Digital Services - 10/5/16
5
+
6
+ require 'cloudimages-rundeck/cli'
7
+ require 'cloudimages-rundeck/config'
8
+ require 'cloudimages-rundeck/util'
9
+ require 'cloudimages-rundeck/version'
10
+
11
+ # => Cloud Image Information API
12
+ module CloudImagesRunDeck
13
+ # => The Sinatra API should be Lazily-Loaded, such that the CLI arguments and/or configuration files are respected
14
+ autoload :API, 'cloudimages-rundeck/api'
15
+ end
@@ -0,0 +1,100 @@
1
+ # Encoding: UTF-8
2
+ # rubocop: disable LineLength
3
+ #
4
+ # Gem Name:: cloudimages-rundeck
5
+ # DeployInfo:: API
6
+ #
7
+ # Copyright (C) 2016 Brian Dwyer - Intelligent Digital Services
8
+ #
9
+ # All rights reserved - Do Not Redistribute
10
+ #
11
+
12
+ # => NOTE: Anything other than a STATUS 200 will trigger an error in the RunDeck plugin due to a hardcode in org.boon.HTTP
13
+
14
+ require 'sinatra/base'
15
+ require 'sinatra/namespace'
16
+ require 'json'
17
+ require 'rack/cache'
18
+ require 'cloudimages-rundeck/do'
19
+ require 'cloudimages-rundeck/config'
20
+
21
+ # => Cloud Image Information Provider for RunDeck
22
+ module CloudImagesRunDeck
23
+ # => HTTP API
24
+ class API < Sinatra::Base
25
+ #######################
26
+ # => Sinatra <= #
27
+ #######################
28
+
29
+ # => Configure Sinatra
30
+ enable :logging, :static, :raise_errors # => disable :dump_errors, :show_exceptions
31
+ set :port, Config.port || 8080
32
+ set :bind, Config.bind || 'localhost'
33
+ set :environment, Config.environment || :production
34
+
35
+ # => Enable NameSpace Support
36
+ register Sinatra::Namespace
37
+
38
+ if development?
39
+ require 'sinatra/reloader'
40
+ register Sinatra::Reloader
41
+ end
42
+
43
+ use Rack::Cache do
44
+ set :verbose, true
45
+ set :metastore, 'file:' + File.join(Dir.tmpdir, 'rack', 'meta')
46
+ set :entitystore, 'file:' + File.join(Dir.tmpdir, 'rack', 'body')
47
+ end
48
+
49
+ ########################
50
+ # => JSON API <= #
51
+ ########################
52
+
53
+ # => Current Configuration & Healthcheck Endpoint
54
+ get '/config' do
55
+ content_type 'application/json'
56
+ JSON.pretty_generate(
57
+ [
58
+ CloudImagesRunDeck.inspect + ' is up and running!',
59
+ 'Author: ' + Config.author,
60
+ 'Environment: ' + Config.environment.to_s,
61
+ 'Root: ' + Config.root.to_s,
62
+ 'Config File: ' + (Config.config_file if File.exist?(Config.config_file)).to_s,
63
+ 'Params: ' + params.inspect,
64
+ 'Cache Timeout: ' + Config.cache_timeout.to_s,
65
+ 'BRIAN IS COOooooooL',
66
+ { AppConfig: Config.options },
67
+ { 'Sinatra Info' => env }
68
+ ].compact
69
+ )
70
+ end
71
+
72
+ ########################
73
+ # => JSON API <= #
74
+ ########################
75
+
76
+ namespace '/images/v1' do
77
+ # => Define our common namespace parameters
78
+ before do
79
+ # => This is a JSON API
80
+ content_type 'application/json'
81
+
82
+ # => Make the Params Globally Accessible
83
+ Config.define_setting :query_params, params
84
+ end
85
+
86
+ # => Clean Up
87
+ after do
88
+ # => Reset the API Client to Default Values
89
+ # => Notifier.reset!
90
+ end
91
+
92
+ # => List Images
93
+ get '/list' do
94
+ cache_control :public, max_age: Config.cache_timeout
95
+
96
+ Do.list_images.to_json
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,90 @@
1
+ # Encoding: UTF-8
2
+ # rubocop: disable LineLength, MethodLength, AbcSize
3
+ #
4
+ # Gem Name:: cloudimages-rundeck
5
+ # DeployInfo:: CLI
6
+ #
7
+ # Copyright (C) 2016 Brian Dwyer - Intelligent Digital Services
8
+ #
9
+ # All rights reserved - Do Not Redistribute
10
+ #
11
+
12
+ require 'mixlib/cli'
13
+ require 'cloudimages-rundeck/config'
14
+ require 'cloudimages-rundeck/util'
15
+
16
+ module CloudImagesRunDeck
17
+ #
18
+ # => CloudImages-RunDeck Launcher
19
+ #
20
+ module CLI
21
+ extend self
22
+ #
23
+ # => Options Parser
24
+ #
25
+ class Options
26
+ # => Mix-In the CLI Option Parser
27
+ include Mixlib::CLI
28
+
29
+ option :do_api_key,
30
+ short: '-d KEY',
31
+ long: '--do-api-key KEY',
32
+ description: 'DigitalOcean API Key'
33
+
34
+ option :cache_timeout,
35
+ short: '-t CACHE_TIMEOUT',
36
+ long: '--timeout CACHE_TIMEOUT',
37
+ description: 'Sets the cache timeout in seconds for API query response data.'
38
+
39
+ option :config_file,
40
+ short: '-c CONFIG',
41
+ long: '--config CONFIG',
42
+ description: 'The configuration file to use, as opposed to command-line parameters (optional)'
43
+
44
+ option :bind,
45
+ short: '-b HOST',
46
+ long: '--bind HOST',
47
+ description: "Listen on Interface or IP (Default: #{Config.bind})"
48
+
49
+ option :port,
50
+ short: '-p PORT',
51
+ long: '--port PORT',
52
+ description: "The port to run on. (Default: #{Config.port})"
53
+
54
+ option :environment,
55
+ short: '-e ENV',
56
+ long: '--env ENV',
57
+ description: 'Sets the environment for cloudimages-rundeck to execute under. Use "development" for more logging.',
58
+ default: 'production'
59
+ end
60
+
61
+ # => Launch the Application
62
+ def run(argv = ARGV)
63
+ # => Parse CLI Configuration
64
+ cli = Options.new
65
+ cli.parse_options(argv)
66
+
67
+ # => Parse JSON Config File (If Specified and Exists)
68
+ json_config = Util.parse_json_config(cli.config[:config_file] || Config.config_file)
69
+
70
+ # => Grab the Default Values
71
+ default = Config.options
72
+
73
+ # => Merge Configuration (CLI Wins)
74
+ config = [default, json_config, cli.config].compact.reduce(:merge)
75
+
76
+ # => Apply Configuration
77
+ Config.setup do |cfg|
78
+ cfg.config_file = config[:config_file]
79
+ cfg.cache_timeout = config[:cache_timeout].to_i
80
+ cfg.bind = config[:bind]
81
+ cfg.port = config[:port]
82
+ cfg.environment = config[:environment].to_sym
83
+ cfg.do_api_key = config[:do_api_key]
84
+ end
85
+
86
+ # => Launch the API
87
+ API.run!
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,78 @@
1
+ # Encoding: UTF-8
2
+ #
3
+ # Gem Name:: cloudimages-rundeck
4
+ # DeployInfo:: Config
5
+ #
6
+ # Copyright (C) 2016 Brian Dwyer - Intelligent Digital Services
7
+ #
8
+ # All rights reserved - Do Not Redistribute
9
+ #
10
+
11
+ require 'cloudimages-rundeck/helpers/configuration'
12
+ require 'pathname'
13
+
14
+ module CloudImagesRunDeck
15
+ # => This is the Configuration module.
16
+ module Config
17
+ extend self
18
+ extend Configuration
19
+
20
+ # => Gem Root Directory
21
+ define_setting :root, Pathname.new(File.expand_path('../../../', __FILE__))
22
+
23
+ # => My Name
24
+ define_setting :author, 'Brian Dwyer - Intelligent Digital Services'
25
+
26
+ # => Application Environment
27
+ define_setting :environment, :production
28
+
29
+ # => Sinatra Configuration
30
+ define_setting :port, '9129'
31
+ define_setting :bind, 'localhost'
32
+ define_setting :cache_timeout, 30
33
+
34
+ # => Config File
35
+ define_setting :config_file, File.join(root, 'config', 'config.json')
36
+
37
+ #
38
+ # => API Configuration
39
+ #
40
+
41
+ # => DigitalOcean API Key
42
+ define_setting :do_api_key
43
+
44
+ #
45
+ # => Facilitate Dynamic Addition of Configuration Values
46
+ #
47
+ # => @return [class_variable]
48
+ #
49
+ def add(config = {})
50
+ config.each do |key, value|
51
+ define_setting key.to_sym, value
52
+ end
53
+ end
54
+
55
+ #
56
+ # => Facilitate Dynamic Removal of Configuration Values
57
+ #
58
+ # => @return nil
59
+ #
60
+ def clear(config)
61
+ Array(config).each do |setting|
62
+ delete_setting setting
63
+ end
64
+ end
65
+
66
+ #
67
+ # => List the Configurable Keys as a Hash
68
+ #
69
+ # @return [Hash]
70
+ #
71
+ def options
72
+ map = CloudImagesRunDeck::Config.class_variables.map do |key|
73
+ [key.to_s.tr('@', '').to_sym, class_variable_get(:"#{key}")]
74
+ end
75
+ Hash[map]
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,53 @@
1
+ # Encoding: UTF-8
2
+ # rubocop: disable LineLength
3
+ #
4
+ # Gem Name:: cloudimages-rundeck
5
+ # DeployInfo:: Do
6
+ #
7
+ # Copyright (C) 2016 Brian Dwyer - Intelligent Digital Services
8
+ #
9
+ # All rights reserved - Do Not Redistribute
10
+ #
11
+
12
+ require 'cloudimages-rundeck/config'
13
+ require 'droplet_kit'
14
+
15
+ module CloudImagesRunDeck
16
+ # => This is the Do Module. It interacts with DigitalOcean resources.
17
+ module Do
18
+ extend self
19
+
20
+ def do_client
21
+ # => Instantiate a new DigitalOcean Client
22
+ DropletKit::Client.new(access_token: Util.filestring(Config.do_api_key))
23
+ end
24
+
25
+ #
26
+ # => Grab the Private Images from DigitalOcean
27
+ #
28
+ def images
29
+ do_client.images.all.select do |image|
30
+ image.public == false && image.type.casecmp('snapshot').zero?
31
+ end.sort_by(&:id).reverse
32
+ rescue DropletKit::Error => e
33
+ e
34
+ end
35
+
36
+ #
37
+ # => Custom-Tailor for Resource-JSON & Optionally Filter by Image Name
38
+ #
39
+ def list_images # rubocop:disable AbcSize, MethodLength
40
+ list = images
41
+ return list.message if list.is_a?(DropletKit::Error)
42
+ list = list.collect do |image|
43
+ {
44
+ 'name' => image['name'] || image['message'],
45
+ 'value' => image['id'].to_s
46
+ }
47
+ end
48
+ filter = Util.serialize_csv(Config.query_params['filter'])
49
+ return list.select { |i| filter.any? { |f| i['name'] =~ /#{f}/i } } if filter
50
+ list
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,57 @@
1
+ # Encoding: UTF-8
2
+ #
3
+ # Gem Name:: cloudimages-rundeck
4
+ # Helper:: Configuration
5
+ #
6
+ # Author: Eli Fatsi - https://www.viget.com/articles/easy-gem-configuration-variables-with-defaults
7
+ # Contributor: Brian Dwyer - Intelligent Digital Services
8
+ #
9
+
10
+ # => Configuration Helper Module
11
+ module Configuration
12
+ #
13
+ # => Provides a method to configure an Application
14
+ # => Example:
15
+ # DeployInfo::Config.setup do |cfg|
16
+ # cfg.config_file = 'abc.json'
17
+ # cfg.app_name = 'GemBase'
18
+ # end
19
+ #
20
+ def setup
21
+ yield self
22
+ end
23
+
24
+ def define_setting(name, default = nil)
25
+ class_variable_set("@@#{name}", default)
26
+
27
+ define_class_method "#{name}=" do |value|
28
+ class_variable_set("@@#{name}", value)
29
+ end
30
+
31
+ define_class_method name do
32
+ class_variable_get("@@#{name}")
33
+ end
34
+ end
35
+
36
+ def delete_setting(name)
37
+ remove_class_variable("@@#{name}")
38
+
39
+ delete_class_method(name)
40
+ rescue NameError # => Handle Non-Existent Settings
41
+ return
42
+ end
43
+
44
+ private
45
+
46
+ def define_class_method(name, &block)
47
+ (class << self; self; end).instance_eval do
48
+ define_method name, &block
49
+ end
50
+ end
51
+
52
+ def delete_class_method(name)
53
+ (class << self; self; end).instance_eval do
54
+ undef_method name
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,71 @@
1
+ # Encoding: UTF-8
2
+ # rubocop: disable LineLength
3
+ #
4
+ # Gem Name:: cloudimages-rundeck
5
+ # DeployInfo:: Util
6
+ #
7
+ # Copyright (C) 2016 Brian Dwyer - Intelligent Digital Services
8
+ #
9
+ # All rights reserved - Do Not Redistribute
10
+ #
11
+
12
+ require 'json'
13
+
14
+ module CloudImagesRunDeck
15
+ # => Utility Methods
16
+ module Util
17
+ extend self
18
+
19
+ ########################
20
+ # => File I/O <= #
21
+ ########################
22
+
23
+ # => Define JSON Parser
24
+ def parse_json_config(file = nil, symbolize = true)
25
+ return unless file && ::File.exist?(file.to_s)
26
+ begin
27
+ ::JSON.parse(::File.read(file.to_s), symbolize_names: symbolize)
28
+ rescue JSON::ParserError
29
+ return
30
+ end
31
+ end
32
+
33
+ # => Define JSON Writer
34
+ def write_json_config(file, object)
35
+ return unless file && object
36
+ begin
37
+ File.open(file, 'w') { |f| f.write(JSON.pretty_generate(object)) }
38
+ end
39
+ end
40
+
41
+ # => Check if a string is an existing file, and return it's content
42
+ def filestring(file, size = 8192)
43
+ return unless file
44
+ return file unless file.is_a?(String) && File.file?(file) && File.size(file) <= size
45
+ File.read(file)
46
+ end
47
+
48
+ #############################
49
+ # => Serialization <= #
50
+ #############################
51
+
52
+ def serialize(response)
53
+ # => Serialize Object into JSON Array
54
+ JSON.pretty_generate(response.map(&:name).sort_by(&:downcase))
55
+ end
56
+
57
+ def serialize_csv(csv)
58
+ # => Serialize a CSV String into an Array
59
+ return unless csv && csv.is_a?(String)
60
+ csv.split(',')
61
+ end
62
+
63
+ def serialize_revisions(branches, tags)
64
+ # => Serialize Branches/Tags into JSON Array
65
+ # => Branches = String, Tags = Key/Value
66
+ branches = branches.map(&:name).sort_by(&:downcase)
67
+ tags = tags.map(&:name).sort_by(&:downcase).reverse.map { |tag| { name: "Tag: #{tag}", value: tag } }
68
+ JSON.pretty_generate(branches + tags)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module CloudImagesRunDeck
2
+ VERSION = '0.1.2'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudimages-rundeck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Brian Dwyer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-07 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: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mixlib-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-cache
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra-contrib
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - bdwyer@IEEE.org
142
+ executables:
143
+ - cloudimages-rundeck
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".gitlab-ci.yml"
149
+ - ".rubocop.yml"
150
+ - Gemfile
151
+ - Gemfile.lock
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - bin/console
156
+ - bin/setup
157
+ - cloudimages-rundeck.gemspec
158
+ - config/config.json.example.json
159
+ - exe/cloudimages-rundeck
160
+ - lib/cloudimages-rundeck.rb
161
+ - lib/cloudimages-rundeck/api.rb
162
+ - lib/cloudimages-rundeck/cli.rb
163
+ - lib/cloudimages-rundeck/config.rb
164
+ - lib/cloudimages-rundeck/do.rb
165
+ - lib/cloudimages-rundeck/helpers/configuration.rb
166
+ - lib/cloudimages-rundeck/util.rb
167
+ - lib/cloudimages-rundeck/version.rb
168
+ homepage: https://github.com/bdwyertech/cloudimages-rundeck
169
+ licenses:
170
+ - MIT
171
+ metadata:
172
+ allowed_push_host: https://rubygems.org
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.6.7
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Cloud Image Information Provider for RunDeck
193
+ test_files: []