cmd-chatops-rpc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 209d84bc7e36a9c28d598db9dfd9c936949e0f8306f22e6954cd4414137bd8d1
4
+ data.tar.gz: 0b5343aaea800d7935468bbdfbf58bef3fc2b4f908ffa86a574d6445ce9f7516
5
+ SHA512:
6
+ metadata.gz: d3c968edd2d2cc7fde2df789d9688a562a73d15d5f2c9313734aec5b7ffbca46933dfaf67ce5e3c14a42ab235f5765ca4174daea2475407e882c608be3e96c1c
7
+ data.tar.gz: 45fe307d8040faf1e23c572e6ea29d54a4689f98bfcd4afca03c59c984136d3da43bfc34c103a53ddaa1cdb70745a4cd8d227a8291855a9d34d2fc71e4a9e4f1
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'pry'
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cmd-chatops-rpc (0.0.1)
5
+ activesupport
6
+ chatops-rpc (~> 0.0.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.0.0)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.1, >= 2.1.8)
17
+ chatops-rpc (0.0.2)
18
+ activesupport
19
+ faraday
20
+ coderay (1.1.2)
21
+ concurrent-ruby (1.1.5)
22
+ diff-lcs (1.3)
23
+ faraday (0.17.0)
24
+ multipart-post (>= 1.2, < 3)
25
+ i18n (1.7.0)
26
+ concurrent-ruby (~> 1.0)
27
+ method_source (0.9.2)
28
+ minitest (5.13.0)
29
+ multipart-post (2.1.1)
30
+ pry (0.12.2)
31
+ coderay (~> 1.1.0)
32
+ method_source (~> 0.9.0)
33
+ rake (12.3.3)
34
+ rspec (3.9.0)
35
+ rspec-core (~> 3.9.0)
36
+ rspec-expectations (~> 3.9.0)
37
+ rspec-mocks (~> 3.9.0)
38
+ rspec-core (3.9.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-expectations (3.9.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-mocks (3.9.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-support (3.9.0)
47
+ thread_safe (0.3.6)
48
+ tzinfo (1.2.5)
49
+ thread_safe (~> 0.1)
50
+ zeitwerk (2.2.0)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ bundler (> 2.0.2)
57
+ cmd-chatops-rpc!
58
+ pry
59
+ rake (~> 12.0)
60
+ rspec (~> 3.9.0)
61
+
62
+ BUNDLED WITH
63
+ 2.1.0.pre.2
@@ -0,0 +1,24 @@
1
+ Cmd Chatops RPC
2
+ ===
3
+
4
+ This gem implments a simple command line interface to test chatops.
5
+
6
+
7
+ ### Setup
8
+
9
+ This gem requires a configuration file. This is a sample of what it looks like
10
+ ```yaml
11
+ user: "anglinb"
12
+ endpoints:
13
+ - endpoint: http://localhost:8889/_example
14
+ - endpoint: http://localhost:8889/_hello_world
15
+ ```
16
+
17
+ It must specify the `user` which can be any string and a series of endpoints to poll for chatops.
18
+
19
+ This gem also requires a private key to authenticate itself with the chatop endpoint.
20
+
21
+ ### Usage
22
+
23
+ `chatops -c config.yml -p private.key`
24
+
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yaml'
4
+ require 'optparse'
5
+ require 'chatops_rpc'
6
+ require 'active_support/all' # Required by ChatopsController
7
+
8
+ options = {}
9
+ parser = OptionParser.new do |opts|
10
+ opts.banner = "Usage: run.rb [options]"
11
+
12
+ opts.on("-cCONFIG", "--config=CONFIG", "Configuration file path") do |v|
13
+ options[:config_path] = v
14
+ end
15
+ opts.on("-pKEY", "--private-key=KEY", "Private key file path") do |v|
16
+ options[:private_key_path] = v
17
+ end
18
+
19
+ opts.on("-h", "--help", "Prints this help") do
20
+ puts opts
21
+ exit
22
+ end
23
+ end
24
+ parser.parse!
25
+
26
+ unless options[:private_key_path] && options[:config_path]
27
+ puts "Please specify the private key (-k) and configuration paths (-c)"
28
+ puts parser
29
+ exit
30
+ end
31
+
32
+ configuration = HashWithIndifferentAccess.new(YAML.safe_load(File.read(options[:config_path])))
33
+ private_key = File.read(options[:private_key_path])
34
+
35
+ client = ChatopsRPC::Client.new(configuration.merge({ private_key: private_key }))
36
+ puts "!! Client setup successfully! Found #{client.clients.length} prefixs: (#{client.clients.keys.join(", ")})"
37
+ puts "!! Type one of the previous prefixs to see the available chatops."
38
+ loop do
39
+ print "$ "
40
+ $stdout.flush
41
+ begin
42
+ command = gets
43
+ rescue Interrupt => e
44
+ puts "Goodbye."
45
+ exit
46
+ rescue SignalException => e
47
+ puts "Goodbye."
48
+ exit
49
+ end
50
+ if command == nil
51
+ puts "Goodbye."
52
+ exit
53
+ end
54
+ command.chomp!
55
+ begin
56
+ resp = client.chat command, configuration["user"]
57
+ rescue ChatopsRPC::Errors::NoMatchingCommandRegex => e
58
+ possible_prefixes = client.clients.keys
59
+ prefix = command.split(" ")[0]
60
+ if possible_prefixes.include?(prefix)
61
+ chatops_commands = client.clients[prefix].get_list
62
+ puts "> Couldn't find matching command"
63
+ puts chatops_commands["methods"].map {
64
+ |name, metadata| "> #{prefix} #{metadata["help"]}"
65
+ }.join("\n")
66
+ next
67
+ end
68
+
69
+ puts e.message
70
+ next
71
+ rescue ChatopsRPC::Errors::ChatopSeverOffline => e
72
+ puts e.message
73
+ next
74
+ end
75
+
76
+ if resp.success?
77
+ puts "> #{resp.message}"
78
+ else
79
+ puts "X #{resp.message}"
80
+ end
81
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "cmd-chatops-rpc"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Brian Anglin"]
9
+ spec.email = ["anglinb@github.com"]
10
+
11
+ spec.summary = %q{An implementation of the Chatops-RPC Protocol client}
12
+ spec.homepage = "https://github.com/anglinb/cmd-chatops-rpc"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "bin"
19
+ spec.executables = ["chatops"]
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "> 2.0.2"
23
+ spec.add_development_dependency "rake", "~> 12.0"
24
+ spec.add_development_dependency "rspec", "~> 3.9.0"
25
+ spec.add_runtime_dependency "chatops-rpc", "~> 0.0.2"
26
+ spec.add_runtime_dependency "activesupport"
27
+ end
@@ -0,0 +1,4 @@
1
+ user: "anglinb"
2
+ endpoints:
3
+ - endpoint: http://localhost:8889/_example
4
+ - endpoint: http://localhost:8889/_hello_world
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmd-chatops-rpc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian Anglin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.9.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.9.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: chatops-rpc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - anglinb@github.com
86
+ executables:
87
+ - chatops
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - README.md
94
+ - bin/chatops
95
+ - cmd-chatops-rpc.gemspec
96
+ - example-config.yml
97
+ homepage: https://github.com/anglinb/cmd-chatops-rpc
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.0.3
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: An implementation of the Chatops-RPC Protocol client
120
+ test_files: []