lunanode 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +16 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.rubocop.yml +94 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/.yardopts +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +19 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/lib/lunanode.rb +12 -0
- data/lib/lunanode/action_generator.rb +105 -0
- data/lib/lunanode/api.rb +172 -0
- data/lib/lunanode/api_actions.rb +41 -0
- data/lib/lunanode/api_actions/default/dns.rb +55 -0
- data/lib/lunanode/api_actions/default/email.rb +59 -0
- data/lib/lunanode/api_actions/default/floating.rb +19 -0
- data/lib/lunanode/api_actions/default/image.rb +31 -0
- data/lib/lunanode/api_actions/default/lb.rb +35 -0
- data/lib/lunanode/api_actions/default/monitor.rb +47 -0
- data/lib/lunanode/api_actions/default/network.rb +19 -0
- data/lib/lunanode/api_actions/default/plan.rb +11 -0
- data/lib/lunanode/api_actions/default/region.rb +11 -0
- data/lib/lunanode/api_actions/default/script.rb +11 -0
- data/lib/lunanode/api_actions/default/securitygroup.rb +35 -0
- data/lib/lunanode/api_actions/default/vm.rb +99 -0
- data/lib/lunanode/api_actions/default/volume.rb +47 -0
- data/lib/lunanode/api_actions/dns.rb +10 -0
- data/lib/lunanode/api_actions/email.rb +10 -0
- data/lib/lunanode/api_actions/floating.rb +10 -0
- data/lib/lunanode/api_actions/image.rb +17 -0
- data/lib/lunanode/api_actions/lb.rb +10 -0
- data/lib/lunanode/api_actions/monitor.rb +10 -0
- data/lib/lunanode/api_actions/network.rb +10 -0
- data/lib/lunanode/api_actions/plan.rb +10 -0
- data/lib/lunanode/api_actions/region.rb +10 -0
- data/lib/lunanode/api_actions/script.rb +10 -0
- data/lib/lunanode/api_actions/securitygroup.rb +10 -0
- data/lib/lunanode/api_actions/vm.rb +10 -0
- data/lib/lunanode/api_actions/volume.rb +10 -0
- data/lib/lunanode/api_error.rb +5 -0
- data/lib/lunanode/version.rb +4 -0
- data/lunanode.gemspec +33 -0
- data/lunanode_api_def.yaml +391 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6cb25dc43d07fe6725275b15c5b10a48d4b8c0e7
|
4
|
+
data.tar.gz: df01e9542eff9498a710ec7589d5b7d7474dbf31
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e81cd909af5d0869cf64ef5892e616ca810f46ccc3d3e3ac87ece2cf325a065c3ce1ef95c689e6b617eef250e4fd4a39b244fd0c0751aaae0f595d12150324e0
|
7
|
+
data.tar.gz: 147833acf55cb3287e971dfac65b51b8ce6db2f7fb56bd85bee0b9d93821775e4b478cf8b1e5b444ae6dd410d4e48584806de15fc1bdd5927423a955e72d3718
|
data/.codeclimate.yml
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.1
|
3
|
+
DisplayCopNames: true
|
4
|
+
|
5
|
+
# Metrics
|
6
|
+
Metrics/AbcSize:
|
7
|
+
Description: >-
|
8
|
+
A calculated magnitude based on number of assignments,
|
9
|
+
branches, and conditions.
|
10
|
+
Reference: 'http://c2.com/cgi/wiki?AbcMetric'
|
11
|
+
Enabled: true
|
12
|
+
Max: 25
|
13
|
+
|
14
|
+
Metrics/BlockNesting:
|
15
|
+
Description: 'Avoid excessive block nesting'
|
16
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count'
|
17
|
+
Enabled: true
|
18
|
+
Max: 4
|
19
|
+
|
20
|
+
Metrics/ClassLength:
|
21
|
+
Description: 'Avoid classes longer than 250 lines of code.'
|
22
|
+
Enabled: true
|
23
|
+
Max: 250
|
24
|
+
|
25
|
+
Metrics/CyclomaticComplexity:
|
26
|
+
Description: >-
|
27
|
+
A complexity metric that is strongly correlated to the number
|
28
|
+
of test cases needed to validate a method.
|
29
|
+
Enabled: true
|
30
|
+
|
31
|
+
Metrics/LineLength:
|
32
|
+
Description: 'Limit lines to 80 characters.'
|
33
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
|
34
|
+
Enabled: true
|
35
|
+
Exclude:
|
36
|
+
- lib/lunanode/api_actions/default/*.rb
|
37
|
+
|
38
|
+
Metrics/MethodLength:
|
39
|
+
Description: 'Avoid methods longer than 30 lines of code.'
|
40
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods'
|
41
|
+
Enabled: true
|
42
|
+
Max: 30
|
43
|
+
|
44
|
+
Metrics/ModuleLength:
|
45
|
+
Description: 'Avoid modules longer than 250 lines of code.'
|
46
|
+
Enabled: true
|
47
|
+
Max: 250
|
48
|
+
|
49
|
+
Metrics/ParameterLists:
|
50
|
+
Description: 'Avoid parameter lists longer than three or four parameters.'
|
51
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#too-many-params'
|
52
|
+
Enabled: true
|
53
|
+
Max: 13
|
54
|
+
|
55
|
+
Metrics/PerceivedComplexity:
|
56
|
+
Description: >-
|
57
|
+
A complexity metric geared towards measuring complexity for a
|
58
|
+
human reader.
|
59
|
+
Enabled: true
|
60
|
+
|
61
|
+
# Style
|
62
|
+
Style/AsciiComments:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
Style/CollectionMethods:
|
66
|
+
Enabled: true
|
67
|
+
|
68
|
+
Style/Documentation:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
Style/FormatString:
|
72
|
+
EnforcedStyle: percent
|
73
|
+
|
74
|
+
Style/HashSyntax:
|
75
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
76
|
+
|
77
|
+
Style/MethodCalledOnDoEndBlock:
|
78
|
+
Enabled: true
|
79
|
+
|
80
|
+
Style/PercentLiteralDelimiters:
|
81
|
+
PreferredDelimiters:
|
82
|
+
'%i': '[]'
|
83
|
+
'%I': '[]'
|
84
|
+
'%w': '[]'
|
85
|
+
'%W': '[]'
|
86
|
+
|
87
|
+
Style/StringLiterals:
|
88
|
+
EnforcedStyle: double_quotes
|
89
|
+
|
90
|
+
Style/SymbolArray:
|
91
|
+
Enabled: true
|
92
|
+
|
93
|
+
Style/TrailingCommaInLiteral:
|
94
|
+
EnforcedStyleForMultiline: comma
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
lunanode
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.4.0
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--exclude lib/lunanode/action_generator.rb
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at nomoon@phoebus.ca. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Tim Bellefleur
|
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,50 @@
|
|
1
|
+
# Lunanode
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/nomoon/lunanode.svg?branch=master)](https://travis-ci.org/nomoon/lunanode)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/nomoon/lunanode/badges/gpa.svg)](https://codeclimate.com/github/nomoon/lunanode)
|
5
|
+
|
6
|
+
A basic implementation of the [Luna Node API](https://wiki.lunanode.com/index.php/API) for Ruby.
|
7
|
+
**Unofficial and unsupported by the people at [Luna Node](https://lunanode.com).**
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "lunanode"
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install lunanode
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
The class is instantiated by either passing it a JSON file containing the keys `api_id` and `api_key`, or specifying the ID and key directly:
|
28
|
+
```
|
29
|
+
api = Lunanode::API.new("credentials_file.json")
|
30
|
+
api = Lunanode::API.new(api_id: "ABCDEFG", api_key: "HIJKLMNOP")
|
31
|
+
```
|
32
|
+
|
33
|
+
Once instantiated, action methods follow the example:
|
34
|
+
|
35
|
+
```
|
36
|
+
api.vm_list # no parameters
|
37
|
+
api.vm_info(vm_id: "My-VM-ID") # required parameters
|
38
|
+
api.image_list(region: "Toronto") # optional parameters
|
39
|
+
```
|
40
|
+
|
41
|
+
More information is available in the documentation, available online at [rubydoc.info](http://www.rubydoc.info/github/nomoon/lunanode).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nomoon/lunanode. 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.
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
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,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
desc "Generates default actions modules from API spec YAML file."
|
8
|
+
task :generate_default_api_modules do
|
9
|
+
require "lunanode/action_generator"
|
10
|
+
modules = Lunanode::ActionGenerator.generate_default_modules
|
11
|
+
modules.each do |category, module_s|
|
12
|
+
filename = "lib/lunanode/api_actions/default/#{category}.rb"
|
13
|
+
raise "File already exists: #{filename}" if File.exist?(filename)
|
14
|
+
bytes = File.write(filename, module_s)
|
15
|
+
puts "File written: #{filename} (#{bytes} bytes)"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
task default: :spec
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/lunanode.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "lunanode/version"
|
4
|
+
require "lunanode/api_actions"
|
5
|
+
require "lunanode/api_error"
|
6
|
+
require "lunanode/api"
|
7
|
+
|
8
|
+
# Namespace for classes and modules in the Lunanode API gem
|
9
|
+
#
|
10
|
+
# See {Lunanode::API} for usage information.
|
11
|
+
module Lunanode
|
12
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
module Lunanode
|
6
|
+
# Helper utility to generate ruby source module/method definitions for API
|
7
|
+
# actions from a YAML file.
|
8
|
+
#
|
9
|
+
# It is not required by default and does not evaluate source. (See Rakefile.)
|
10
|
+
module ActionGenerator
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def api_data
|
14
|
+
@api_data ||= YAML.safe_load(
|
15
|
+
File.read("lunanode_api_def.yaml"),
|
16
|
+
[String, Symbol]
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_default_modules
|
21
|
+
generate_categories(api_data)
|
22
|
+
end
|
23
|
+
|
24
|
+
UNSAFE_IDENTIFIER = /.{21,}|[^A-Za-z0-9_*]/
|
25
|
+
|
26
|
+
def module_name(name)
|
27
|
+
if name.length > 3
|
28
|
+
name.capitalize
|
29
|
+
else
|
30
|
+
name.upcase
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def indent_lines(string)
|
35
|
+
string.gsub(/^(?!$)/, " ")
|
36
|
+
end
|
37
|
+
|
38
|
+
def check_safe!(identifier)
|
39
|
+
raise "Unsafe name `#{identifier}`" if identifier =~ UNSAFE_IDENTIFIER
|
40
|
+
end
|
41
|
+
|
42
|
+
def generate_categories(data)
|
43
|
+
(data.map do |category, actions|
|
44
|
+
check_safe!(category)
|
45
|
+
[category, generate_actions(category, actions)]
|
46
|
+
end).to_h
|
47
|
+
end
|
48
|
+
|
49
|
+
def generate_actions(category, actions)
|
50
|
+
actions = actions.map do |action, params|
|
51
|
+
generate_action(category, action, params)
|
52
|
+
end
|
53
|
+
|
54
|
+
category_module = "module #{module_name(category)}\n" +
|
55
|
+
actions.map { |a| indent_lines(a) }.join("\n") +
|
56
|
+
"end\n"
|
57
|
+
|
58
|
+
actions_module = "module APIActions\n" +
|
59
|
+
indent_lines(category_module) +
|
60
|
+
"end\n"
|
61
|
+
|
62
|
+
src = "module #{name.split('::')[-2]}\n" +
|
63
|
+
indent_lines(actions_module) +
|
64
|
+
"end\n"
|
65
|
+
|
66
|
+
"# frozen_string_literal: true\n\n#{src}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def generate_action(category, action, params)
|
70
|
+
check_safe!(action)
|
71
|
+
params = params.to_h
|
72
|
+
|
73
|
+
param_list_req = Array(params[:required])
|
74
|
+
param_list_opt = Array(params[:optional])
|
75
|
+
param_list = param_list_req + param_list_opt
|
76
|
+
param_list.each { |p| check_safe!(p) }
|
77
|
+
|
78
|
+
param_list_call_arr = param_list.map do |p|
|
79
|
+
p.start_with?("**") ? p : "#{p}: #{p}"
|
80
|
+
end
|
81
|
+
|
82
|
+
param_list_req_sig_arr = param_list_req.map do |p|
|
83
|
+
"#{p}:"
|
84
|
+
end
|
85
|
+
|
86
|
+
param_list_opt_sig_arr = param_list_opt.map do |p|
|
87
|
+
p.start_with?("**") ? p : "#{p}: nil"
|
88
|
+
end
|
89
|
+
param_list_sig_arr = (param_list_req_sig_arr + param_list_opt_sig_arr)
|
90
|
+
|
91
|
+
unless param_list.empty?
|
92
|
+
param_list_call = ", #{param_list_call_arr.join(', ')}"
|
93
|
+
param_list_sig = "(#{param_list_sig_arr.join(', ')})"
|
94
|
+
end
|
95
|
+
|
96
|
+
"def #{category}_#{action}#{param_list_sig}\n" \
|
97
|
+
" action(:#{category}, :#{action}#{param_list_call})\n" \
|
98
|
+
"end\n"
|
99
|
+
end
|
100
|
+
|
101
|
+
private_constant :UNSAFE_IDENTIFIER
|
102
|
+
private_class_method :check_safe!, :generate_categories, :generate_actions,
|
103
|
+
:generate_action
|
104
|
+
end
|
105
|
+
end
|