adminix 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/.byebug_history +145 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/adminix.gemspec +40 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/adminix +5 -0
- data/lib/adminix/.config.rb.swp +0 -0
- data/lib/adminix/.entrypoint.rb.swp +0 -0
- data/lib/adminix/.service.rb.swo +0 -0
- data/lib/adminix/.service.rb.swp +0 -0
- data/lib/adminix/config.rb +131 -0
- data/lib/adminix/entrypoint.rb +67 -0
- data/lib/adminix/service.rb +84 -0
- data/lib/adminix/version.rb +3 -0
- data/lib/adminix/watcher.rb +45 -0
- data/lib/adminix.rb +5 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4bc03129c190fc9a8f82cf475e67c18d7a27e616
|
4
|
+
data.tar.gz: aa4f21197f0d737ba87954b7a22f931cb6a69c68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e8cdcc3daba881283c327adc5bcc69ab330b0da74aba4f9866517a27b1fe2f56de75a0ab71ca7645479e81ec69565c3a2e05abd16a89c6f94f3b93ce2133c4db
|
7
|
+
data.tar.gz: b59bf555366bb1a130cf71a2958fff980584d1e0e15b4552b6ceb02dba94a972a4651898d55b6d0487c06933f297d6700e76a9394642789e4c7182d1303af35d
|
data/.byebug_history
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
q
|
2
|
+
service.options_to_envs
|
3
|
+
service.options_to_env
|
4
|
+
service.id = 1
|
5
|
+
service.sync
|
6
|
+
`curl http://localhost:5000`
|
7
|
+
service.sync
|
8
|
+
service.id = nil
|
9
|
+
service.id
|
10
|
+
service.cid
|
11
|
+
service.config.service_id
|
12
|
+
service.config
|
13
|
+
service.config.secret_key = 'ca046c7358d638977285ea4e'
|
14
|
+
service = Adminix::Service.new
|
15
|
+
service.config.secret_key = 'ca046c7358d638977285ea4e'
|
16
|
+
`curl #{config.host}`
|
17
|
+
config.host
|
18
|
+
config
|
19
|
+
continue
|
20
|
+
service.options_to_envs
|
21
|
+
service.config.secret_key = '31cfa5148cb438b552798bb9'
|
22
|
+
service.id = 1
|
23
|
+
service = Adminix::Service.new
|
24
|
+
q
|
25
|
+
'google'.upcase
|
26
|
+
service.options_to_envs['result'].first
|
27
|
+
service.options_to_envs['service'].first
|
28
|
+
service.options_to_envs[1]
|
29
|
+
service.options_to_envs.first
|
30
|
+
service.options_to_envs
|
31
|
+
service = Service.create(name: "test2", user: User.first)
|
32
|
+
service.config.options.first
|
33
|
+
require 'awesome_print'
|
34
|
+
service.config.options
|
35
|
+
service.options_to_envs
|
36
|
+
service.sync
|
37
|
+
service.config.secret_key = '31cfa5148cb438b552798bb9'
|
38
|
+
service.id = 1
|
39
|
+
service = Adminix::Service.new
|
40
|
+
q
|
41
|
+
service.options_to_envs
|
42
|
+
service.sync
|
43
|
+
service.id = 1
|
44
|
+
service.config.secret_key = '31cfa5148cb438b552798bb9'
|
45
|
+
service = Adminix::Service.new
|
46
|
+
q
|
47
|
+
service.sync
|
48
|
+
service.options_to_envs
|
49
|
+
service.sync
|
50
|
+
service.config.secret_key = '31cfa5148cb438b552798bb9'
|
51
|
+
service.id = 1
|
52
|
+
service = Adminix::Service.new
|
53
|
+
q
|
54
|
+
service.options_to_envs
|
55
|
+
service.sync
|
56
|
+
service.config.secret_key
|
57
|
+
service.options_to_envs
|
58
|
+
service.sync
|
59
|
+
service.id = 1
|
60
|
+
service.config.secret_key = '31cfa5148cb438b552798bb9'
|
61
|
+
service = Adminix::Service.new
|
62
|
+
q
|
63
|
+
service.sync
|
64
|
+
service.config.secret_key = '31cfa5148cb438b552798bb9'
|
65
|
+
service.config.secret_key
|
66
|
+
service.sync
|
67
|
+
service.config.secret_key
|
68
|
+
service.sync
|
69
|
+
service.config.secret_key = '82ff6a89e7e0f398ca1f5893'
|
70
|
+
service.id = 1
|
71
|
+
service = Adminix::Service.new
|
72
|
+
q
|
73
|
+
service.sync
|
74
|
+
service.id = 1
|
75
|
+
service.config.secret_key = '82ff6a89e7e0f398ca1f5893'
|
76
|
+
service = Adminix::Service.new
|
77
|
+
service.id = 1
|
78
|
+
service.config.secret_key = '82ff6a89e7e0f398ca1f5893'
|
79
|
+
q
|
80
|
+
service.id
|
81
|
+
service.sync
|
82
|
+
service.config.secret_key = '82ff6a89e7e0f398ca1f5893'
|
83
|
+
service.config.secret_key
|
84
|
+
service.config
|
85
|
+
service.id = 1
|
86
|
+
service.id
|
87
|
+
service.name
|
88
|
+
service = Adminix::Service.new
|
89
|
+
q
|
90
|
+
service = Adminix::Service.new
|
91
|
+
servic
|
92
|
+
service = Adminix::Service.first
|
93
|
+
service = Service.first
|
94
|
+
Adminix::Config.instance
|
95
|
+
Config.instance
|
96
|
+
q
|
97
|
+
expect(config.errors.count).to eq(0)
|
98
|
+
expect(config.valid?).to eq(true)
|
99
|
+
config = Adminix::Config.instance
|
100
|
+
Adminix::Config.instance.valid?
|
101
|
+
Adminix::Config.instance.errors
|
102
|
+
Adminix::Config.instance
|
103
|
+
q
|
104
|
+
Adminix::Config.instance.errors
|
105
|
+
Adminix::Config.instance.valid?
|
106
|
+
Adminix::Config.instance
|
107
|
+
q
|
108
|
+
service_id
|
109
|
+
service_name
|
110
|
+
q
|
111
|
+
service_name
|
112
|
+
self.service_name = hs['service_name']
|
113
|
+
self.service_name
|
114
|
+
hs
|
115
|
+
q
|
116
|
+
hs['service_name']
|
117
|
+
hs = JSON.parse(content)
|
118
|
+
q
|
119
|
+
generate_fake_config_file
|
120
|
+
q
|
121
|
+
generate_fake_config_file
|
122
|
+
q
|
123
|
+
rand(1..10000)
|
124
|
+
1..10000.rand
|
125
|
+
(1..10000).rand
|
126
|
+
Faker::Internet.email(name)
|
127
|
+
name.sub
|
128
|
+
name.join('.')
|
129
|
+
name = Faker::Name.name
|
130
|
+
name = Faker::Name.namename = Faker::Name.name
|
131
|
+
name = Faker::Name.name
|
132
|
+
Faker::Internet.email('chris')
|
133
|
+
Faker::Internet.email
|
134
|
+
q
|
135
|
+
require 'faker'
|
136
|
+
Faker
|
137
|
+
q
|
138
|
+
require 'faker'
|
139
|
+
generate_config_file
|
140
|
+
q
|
141
|
+
File.open('tmp/spec/adminix.json', 'w') { |file| file.write(hs.to_json) }
|
142
|
+
@config_file_path = 'tmp/spec/adminix.json'
|
143
|
+
File.open('adminix.json', 'w') { |file| file.write(hs.to_json) }
|
144
|
+
hs.to_json
|
145
|
+
JSON
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
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 TODO: Write your email address. 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 TODO: Write your name
|
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,41 @@
|
|
1
|
+
# Adminix
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/adminix`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'adminix'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install adminix
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/adminix. 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.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/adminix.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'adminix/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "adminix"
|
8
|
+
spec.version = Adminix::VERSION
|
9
|
+
spec.authors = ["Christian Dyl"]
|
10
|
+
spec.email = ["christian.dyl@outlook.com"]
|
11
|
+
|
12
|
+
spec.summary = "Adminix"
|
13
|
+
spec.description = "Adminix"
|
14
|
+
spec.homepage = "http://adminix.io"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
#if spec.respond_to?(:metadata)
|
20
|
+
#spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
#else
|
22
|
+
#raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
#"public gem pushes."
|
24
|
+
#end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "action_cable_client", "~> 1.3", ">= 1.3.4"
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
spec.add_development_dependency "byebug", "~> 9.0.6"
|
39
|
+
spec.add_development_dependency "faker", "~> 1.7.2"
|
40
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "adminix"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/adminix
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Adminix
|
5
|
+
class Config
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
DEFAULT_HOST = 'http://api.adminix.io'.freeze
|
9
|
+
|
10
|
+
attr_accessor(
|
11
|
+
:service_name,
|
12
|
+
:service_id,
|
13
|
+
:host,
|
14
|
+
:secret_key,
|
15
|
+
:monitor_logs_paths,
|
16
|
+
:options,
|
17
|
+
:commands
|
18
|
+
)
|
19
|
+
|
20
|
+
def self.setup(opts)
|
21
|
+
conf = self.instance
|
22
|
+
|
23
|
+
conf.service_id = opts[:service_id]
|
24
|
+
conf.service_name = opts[:service_name]
|
25
|
+
conf.secret_key = opts[:secret_key]
|
26
|
+
|
27
|
+
conf.export
|
28
|
+
end
|
29
|
+
|
30
|
+
def attributes
|
31
|
+
{
|
32
|
+
service_name: service_name,
|
33
|
+
service_id: service_id,
|
34
|
+
secret_key: secret_key,
|
35
|
+
options: options || [],
|
36
|
+
commands: commands || []
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def file_exists?
|
41
|
+
File.exists?("#{ENV['HOME']}/.adminix.json")
|
42
|
+
end
|
43
|
+
|
44
|
+
def export(path=nil)
|
45
|
+
file_path = path || "#{ENV['HOME']}/.adminix.json"
|
46
|
+
file_content = JSON.pretty_generate(attributes)
|
47
|
+
File.delete(file_path) if File.exists?(file_path)
|
48
|
+
File.open(file_path, 'w') { |file| file.write(file_content) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def import
|
52
|
+
content = File.read(config_file_path)
|
53
|
+
hs = JSON.parse(content)
|
54
|
+
|
55
|
+
self.service_name = hs['service_name']
|
56
|
+
self.service_id = hs['service_id']
|
57
|
+
self.secret_key = hs['secret_key']
|
58
|
+
self.host = hs['host'] || ENV['ADMINIX_CONFIG_HOST'] || DEFAULT_HOST
|
59
|
+
self.options = hs['options'] || []
|
60
|
+
self.commands = hs['commands'] || []
|
61
|
+
|
62
|
+
valid?
|
63
|
+
end
|
64
|
+
|
65
|
+
def config_file_path
|
66
|
+
return @config_path unless @config_path.nil?
|
67
|
+
|
68
|
+
paths = [
|
69
|
+
"#{ENV['HOME']}/.adminix.json",
|
70
|
+
'.adminix.json'
|
71
|
+
]
|
72
|
+
paths << ENV['ADMINIX_CONFIG_PATH'] if !ENV['ADMINIX_CONFIG_PATH'].nil?
|
73
|
+
|
74
|
+
config_path = nil
|
75
|
+
|
76
|
+
paths.reverse.each do |path|
|
77
|
+
if File.exists?(path)
|
78
|
+
@config_path = path
|
79
|
+
break
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
@config_path or raise "adminix.json doesn't exists"
|
84
|
+
end
|
85
|
+
|
86
|
+
def valid?
|
87
|
+
errors = {}
|
88
|
+
|
89
|
+
if service_name.nil?
|
90
|
+
errors[:service_name] ||= []
|
91
|
+
errors[:service_name] << "should't be blank"
|
92
|
+
end
|
93
|
+
|
94
|
+
if service_id.nil?
|
95
|
+
errors[:service_id] ||= []
|
96
|
+
errors[:service_id] << "should't be blank"
|
97
|
+
end
|
98
|
+
|
99
|
+
if secret_key.nil?
|
100
|
+
errors[:secret_key] ||= []
|
101
|
+
errors[:secret_key] << "should't be blank"
|
102
|
+
end
|
103
|
+
|
104
|
+
unless monitor_logs_paths.nil?
|
105
|
+
unless monitor_logs_paths.is_a? Array
|
106
|
+
errors[:monitor_logs_paths] << "should be array"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
unless options.nil?
|
111
|
+
unless options.is_a? Array
|
112
|
+
errors[:options] << "should be array"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
unless commands.nil?
|
117
|
+
unless commands.is_a? Array
|
118
|
+
errors[:commands] << "should be array"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
@errors = errors
|
123
|
+
|
124
|
+
errors.count == 0
|
125
|
+
end
|
126
|
+
|
127
|
+
def errors
|
128
|
+
@errors
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Adminix
|
2
|
+
class Entrypoint
|
3
|
+
def self.execute_action(args)
|
4
|
+
action = args[0]
|
5
|
+
case action
|
6
|
+
when 'help' then action_help
|
7
|
+
when 'setup' then action_setup
|
8
|
+
when 'env' then action_env
|
9
|
+
when 'watcher' then action_watcher
|
10
|
+
when 'version' then action_version
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.action_help
|
15
|
+
puts "Usage: adminix COMMAND\n\n" +
|
16
|
+
"Create and manage Adminix services\n\n" +
|
17
|
+
"Version: #{VERSION}\n\n" +
|
18
|
+
"Author:\n" +
|
19
|
+
" Christian Dyl\n\n" +
|
20
|
+
"Commands:\n" +
|
21
|
+
" env Display the commands to define ENV variables\n" +
|
22
|
+
" watcher Launch Adminix watcher\n" +
|
23
|
+
" setup Generage adminix.json\n" +
|
24
|
+
" version Show the Adminix version"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.action_setup
|
28
|
+
if Config.instance.file_exists?
|
29
|
+
puts "File \"#{ENV['HOME']}/.adminix.json\" already exists, overwrite config (yes/no):"
|
30
|
+
return unless ['yes', 'y'].include?($stdin.gets.chomp)
|
31
|
+
end
|
32
|
+
|
33
|
+
puts "Enter secret key:"
|
34
|
+
secret_key = $stdin.gets.chomp
|
35
|
+
|
36
|
+
puts "Enter service id (empty to create a new service)"
|
37
|
+
service_id = $stdin.gets.chomp
|
38
|
+
|
39
|
+
service_name = ''
|
40
|
+
if service_id == ''
|
41
|
+
puts "Enter service name"
|
42
|
+
service_name = $stdin.gets.chomp
|
43
|
+
end
|
44
|
+
|
45
|
+
Config.setup(
|
46
|
+
secret_key: secret_key,
|
47
|
+
service_id: service_id,
|
48
|
+
service_name: service_name
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.action_env
|
53
|
+
Service.instance.options_to_envs
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.action_watcher
|
57
|
+
watcher = Watcher.new
|
58
|
+
watcher.start
|
59
|
+
|
60
|
+
watcher
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.action_version
|
64
|
+
puts "The current version is #{VERSION}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Adminix
|
5
|
+
class Service
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_accessor :id, :process_id, :name, :address
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.id = config.service_id
|
12
|
+
self.name = config.service_name
|
13
|
+
self.address = nil
|
14
|
+
|
15
|
+
config.import
|
16
|
+
end
|
17
|
+
|
18
|
+
# Send info about container
|
19
|
+
def sync
|
20
|
+
uri = URI.parse("#{config.host}/v1/services/sync")
|
21
|
+
request = Net::HTTP::Post.new(uri)
|
22
|
+
request.content_type = "application/json"
|
23
|
+
request["Authorization"] = "Bearer #{config.secret_key}"
|
24
|
+
|
25
|
+
payload = {
|
26
|
+
service: {
|
27
|
+
name: name,
|
28
|
+
options: config_payload,
|
29
|
+
#commands: [],
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
payload[:service][:id] = id unless id.nil?
|
34
|
+
|
35
|
+
request.body = payload.to_json
|
36
|
+
|
37
|
+
req_options = {}
|
38
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
39
|
+
http.request(request)
|
40
|
+
end
|
41
|
+
data = JSON.parse(response.body)
|
42
|
+
end
|
43
|
+
|
44
|
+
def config
|
45
|
+
Config.instance
|
46
|
+
end
|
47
|
+
|
48
|
+
def config_payload
|
49
|
+
config.options.map do |o|
|
50
|
+
{
|
51
|
+
key: o['key'],
|
52
|
+
name: o['name'],
|
53
|
+
description: o['description'],
|
54
|
+
value_type: o['type'],
|
55
|
+
options: o['options'],
|
56
|
+
validations: o['validations'],
|
57
|
+
default_value: o['default_value']
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def execute_command
|
63
|
+
end
|
64
|
+
|
65
|
+
def options_to_envs
|
66
|
+
uri = URI.parse("#{config.host}/v1/services/#{id}/options")
|
67
|
+
request = Net::HTTP::Get.new(uri)
|
68
|
+
request["Authorization"] = "Bearer #{config.secret_key}"
|
69
|
+
|
70
|
+
response = Net::HTTP.start(uri.hostname, uri.port, {}) do |http|
|
71
|
+
http.request(request)
|
72
|
+
end
|
73
|
+
|
74
|
+
data = JSON.parse(response.body)
|
75
|
+
data['result'].each do |o|
|
76
|
+
puts "export #{o['key'].upcase}=#{o['value']}"
|
77
|
+
end
|
78
|
+
|
79
|
+
puts "# Run this command to configure your shell:\n" +
|
80
|
+
"# eval $(adminix env)"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Adminix
|
2
|
+
module Handler
|
3
|
+
def file_modified
|
4
|
+
puts "#{path} modified"
|
5
|
+
end
|
6
|
+
|
7
|
+
def file_moved
|
8
|
+
puts "#{path} moved"
|
9
|
+
end
|
10
|
+
|
11
|
+
def file_deleted
|
12
|
+
puts "#{path} deleted"
|
13
|
+
end
|
14
|
+
|
15
|
+
def unbind
|
16
|
+
puts "#{path} monitoring ceased"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Watcher
|
21
|
+
CABLE_URL = 'ws://localhost:28080/cable'.freeze
|
22
|
+
|
23
|
+
def start
|
24
|
+
puts 'Starting watcher'
|
25
|
+
@em = EventMachine.run do
|
26
|
+
client = ActionCableClient.new(CABLE_URL, 'MessagesChannel')
|
27
|
+
# the connected callback is required, as it triggers
|
28
|
+
# the actual subscribing to the channel but it can just be
|
29
|
+
# client.connected {}
|
30
|
+
client.connected { puts 'successfully connected.' }
|
31
|
+
|
32
|
+
# called whenever a message is received from the server
|
33
|
+
client.received do |message|
|
34
|
+
puts message
|
35
|
+
end
|
36
|
+
|
37
|
+
# adds to a queue that is purged upon receiving of
|
38
|
+
# a ping from the server
|
39
|
+
client.perform('speak', { message: 'hello from amc' })
|
40
|
+
|
41
|
+
EventMachine.watch_file("/vagrant/log", Handler)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/adminix.rb
ADDED
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adminix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Dyl
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: action_cable_client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.3.4
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.3.4
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.14'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.14'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: byebug
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 9.0.6
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 9.0.6
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: faker
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.7.2
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 1.7.2
|
103
|
+
description: Adminix
|
104
|
+
email:
|
105
|
+
- christian.dyl@outlook.com
|
106
|
+
executables:
|
107
|
+
- adminix
|
108
|
+
extensions: []
|
109
|
+
extra_rdoc_files: []
|
110
|
+
files:
|
111
|
+
- ".byebug_history"
|
112
|
+
- ".gitignore"
|
113
|
+
- ".rspec"
|
114
|
+
- ".travis.yml"
|
115
|
+
- CODE_OF_CONDUCT.md
|
116
|
+
- Gemfile
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.md
|
119
|
+
- Rakefile
|
120
|
+
- adminix.gemspec
|
121
|
+
- bin/console
|
122
|
+
- bin/setup
|
123
|
+
- exe/adminix
|
124
|
+
- lib/adminix.rb
|
125
|
+
- lib/adminix/.config.rb.swp
|
126
|
+
- lib/adminix/.entrypoint.rb.swp
|
127
|
+
- lib/adminix/.service.rb.swo
|
128
|
+
- lib/adminix/.service.rb.swp
|
129
|
+
- lib/adminix/config.rb
|
130
|
+
- lib/adminix/entrypoint.rb
|
131
|
+
- lib/adminix/service.rb
|
132
|
+
- lib/adminix/version.rb
|
133
|
+
- lib/adminix/watcher.rb
|
134
|
+
homepage: http://adminix.io
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.6.8
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Adminix
|
158
|
+
test_files: []
|