lita-atlantic-net 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d8d217362af760c2396f654298eed8fa3044a4e
4
+ data.tar.gz: fb2906a227b2e4c6b97e18f85078bc243b97e3b4
5
+ SHA512:
6
+ metadata.gz: eaacc7635cb006f23b71307c7251f2e5f6b4d834a2cdd21f163fc2d4a7b25cf217656bfa1eff0c98c9bffc7d13209b72a57eff9615c0417f8ac0a9780673e523
7
+ data.tar.gz: cb609f8e630710262f1014710ba6d97505c8c456a1f5bb2ed7e29ea84711f122ad53058d4ab7004c9ed6eb6c4c105bef9a128fde06a20724f67d4f86e71d9bf5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ - gem install bundler
8
+ services:
9
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 Jamie Starke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # lita-atlantic-net
2
+
3
+ [![Build Status](https://travis-ci.org/jrstarke/lita-atlantic-net.png?branch=master)](https://travis-ci.org/jrstarke/lita-atlantic-net)
4
+ [![Coverage Status](https://coveralls.io/repos/jrstarke/lita-atlantic-net/badge.png)](https://coveralls.io/r/jrstarke/lita-atlantic-net)
5
+ [![Gem Version](https://badge.fury.io/rb/lita-atlantic-net.svg)](https://badge.fury.io/rb/lita-atlantic-net)
6
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/jrstarke/lita-atlantic-net/master/LICENSE)
7
+
8
+
9
+ **lita-atlantic-net** is a handler plugin for [Lita](https://www.lita.io/) that interacts with [Atlantic.net](https://www.atlantic.net/).
10
+
11
+ ## Installation
12
+
13
+ Add lita-atlantic-net to your Lita instance's Gemfile:
14
+
15
+ ``` ruby
16
+ gem "lita-atlantic-net"
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ ### Required attributes
22
+
23
+ * `access_key` (String) - The access key for your Atlantic.net acccount.
24
+ * `private_key` (String) - The private key for your Atlantic.net acccount.
25
+
26
+ ### Example
27
+
28
+ ``` ruby
29
+ Lita.configure do |config|
30
+ config.handlers.atlantic_net.access_key = "<your atlantic.net access key>"
31
+ config.handlers.atlantic_net.private_key = "<your atlantic.net private key>"
32
+ end
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ In order to use the Atlantic.net handler commands, you must ensure that the user running the commands is in the :atlantic_net_admins group.
38
+
39
+
40
+ ### List Instances
41
+
42
+ To list the instances associated with your atlantic.net account:
43
+
44
+ ```
45
+ Lita: atlantic instances
46
+ ```
47
+
48
+ ### Reboot Instance
49
+
50
+ To reboot an instance associated with your atlantic.net account:
51
+
52
+ ```
53
+ Lita: atlantic reboot INSTANCE_ID
54
+ ```
55
+
56
+ ## License
57
+
58
+ [MIT](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
@@ -0,0 +1,40 @@
1
+ require "atlantic_net"
2
+
3
+ module Lita
4
+ module Handlers
5
+ class AtlanticNet < Handler
6
+ config :access_key, required: true
7
+ config :private_key, required: true
8
+
9
+ route(/^atlantic\s+instances$/i, :list_instances, command: true, restrict_to: [:atlantic_net_admins], help: {
10
+ t("help.list_instances_key") => t("help.list_instances_value")
11
+ })
12
+
13
+ route(/^atlantic\s+reboot\s+(?<instance_id>[0-9]+)$/, :reboot_instance, command: true, restrict_to: [:atlantic_net_admins], help: {
14
+ t("help.reboot_instance_key") => t("help.reboot_instance_value")
15
+ })
16
+
17
+ def client
18
+ @client ||= ::AtlanticNet.new(config.access_key, config.private_key)
19
+ end
20
+
21
+ def list_instances(response)
22
+ instances = client.list_instances
23
+ if instances and instances.any?
24
+ messages = instances.map { |instance| t("instances.list.detail", Hash[instance.map { |k, v| [k.to_sym, v] }])}
25
+ response.reply(*messages)
26
+ else
27
+ response.reply(t("instances.list.none"))
28
+ end
29
+ end
30
+
31
+ def reboot_instance(response)
32
+ instance_id = response.match_data['instance_id']
33
+ response_message = client.reboot_instance(instance_id)
34
+ response.reply(response_message["Message"])
35
+ end
36
+
37
+ Lita.register_handler(self)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/atlantic_net"
8
+
9
+ Lita::Handlers::AtlanticNet.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-atlantic-net"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Jamie Starke"]
5
+ spec.email = ["git@jamiestarke.com"]
6
+ spec.description = "A Lita handler for interacting with Atlantic.net"
7
+ spec.summary = "A Lita handler for interacting with Atlantic.net"
8
+ spec.homepage = "https://github.com/jrstarke/lita-atlantic-net"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.7"
18
+ spec.add_runtime_dependency "atlantic_net", ">= 0.1.3"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "pry-byebug"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rack-test"
24
+ spec.add_development_dependency "rspec", ">= 3.0.0"
25
+ spec.add_development_dependency "simplecov"
26
+ spec.add_development_dependency "coveralls"
27
+ spec.add_development_dependency "pry"
28
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,13 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ atlantic_net:
5
+ instances:
6
+ list:
7
+ detail: "ID: %{InstanceId}, Description: %{vm_description}, IP: %{vm_ip_address}, Plan: %{vm_plan_name}, Status: %{vm_status}"
8
+ none: "No instances on your account."
9
+ help:
10
+ list_instances_key: atlantic instances
11
+ list_instances_value: Displays the list of instances for your Atlantic.net account.
12
+ reboot_instance_key: atlantic reboot SERVER_ID
13
+ reboot_instance_value: Reboots a server with the given ID
@@ -0,0 +1,85 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::AtlanticNet, lita_handler: true do
4
+
5
+ # Chat routes
6
+ it {
7
+ is_expected.to route_command("atlantic instances").with_authorization_for(:atlantic_net_admins).to(:list_instances)
8
+ is_expected.to route_command("atlantic reboot 1").with_authorization_for(:atlantic_net_admins).to(:reboot_instance)
9
+ }
10
+
11
+ let(:client) { instance_double("::AtlanticNet") }
12
+
13
+
14
+ before do
15
+ Lita.config.handlers.atlantic_net.access_key = 'foo'
16
+ Lita.config.handlers.atlantic_net.private_key = 'bar'
17
+
18
+ robot.auth.add_user_to_group!(user, :atlantic_net_admins)
19
+
20
+ allow(::AtlanticNet).to receive(:new).and_return(client)
21
+ end
22
+
23
+ describe "#list instances" do
24
+ context "There are instances" do
25
+ let(:instances) {
26
+ [
27
+ {
28
+ "InstanceId" => "145607",
29
+ "vm_description" => "New",
30
+ "vm_ip_address" => "209.208.65.177",
31
+ "vm_plan_name" => "S",
32
+ "vm_status" => "RUNNING"
33
+ },
34
+ {
35
+ "InstanceId" => "153979",
36
+ "vm_description" => "apitestserver",
37
+ "vm_ip_address" => "45.58.35.251",
38
+ "vm_plan_name" => "L",
39
+ "vm_status" => "RUNNING"
40
+ }
41
+ ]
42
+ }
43
+
44
+ it "lists all instances" do
45
+ allow(client).to receive(:list_instances).and_return(instances)
46
+ send_command("atlantic instances")
47
+ expect(replies).to eq [
48
+ "ID: 145607, Description: New, IP: 209.208.65.177, Plan: S, Status: RUNNING",
49
+ "ID: 153979, Description: apitestserver, IP: 45.58.35.251, Plan: L, Status: RUNNING",
50
+ ]
51
+ end
52
+ end
53
+
54
+ context "No instances" do
55
+ let(:instances) {
56
+ []
57
+ }
58
+
59
+ it "responds with no instances" do
60
+ allow(client).to receive(:list_instances).and_return(instances)
61
+ send_command("atlantic instances")
62
+ expect(replies).to eq [
63
+ "No instances on your account."
64
+ ]
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "#reboot instance" do
70
+ let(:response) {
71
+ {
72
+ "Message" => "Successfully queued for reboot",
73
+ "value" => "true"
74
+ }
75
+ }
76
+
77
+ it "reboots the server" do
78
+ allow(client).to receive(:reboot_instance).and_return(response)
79
+ send_command("atlantic reboot 12")
80
+ expect(replies).to eq [
81
+ "Successfully queued for reboot"
82
+ ]
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,14 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-atlantic-net"
10
+ require "lita/rspec"
11
+
12
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
13
+ # was generated with Lita 4, the compatibility mode should be left disabled.
14
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-atlantic-net
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Starke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '4.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: atlantic_net
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
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
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: A Lita handler for interacting with Atlantic.net
154
+ email:
155
+ - git@jamiestarke.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - .gitignore
161
+ - .travis.yml
162
+ - Gemfile
163
+ - LICENSE
164
+ - README.md
165
+ - Rakefile
166
+ - lib/lita-atlantic-net.rb
167
+ - lib/lita/handlers/atlantic_net.rb
168
+ - lita-atlantic-net.gemspec
169
+ - locales/en.yml
170
+ - spec/lita/handlers/atlantic_net_spec.rb
171
+ - spec/spec_helper.rb
172
+ - templates/.gitkeep
173
+ homepage: https://github.com/jrstarke/lita-atlantic-net
174
+ licenses:
175
+ - MIT
176
+ metadata:
177
+ lita_plugin_type: handler
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.4.6
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: A Lita handler for interacting with Atlantic.net
198
+ test_files:
199
+ - spec/lita/handlers/atlantic_net_spec.rb
200
+ - spec/spec_helper.rb