ancor-cli 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +1 -0
- data/bin/ancor +6 -0
- data/lib/ancor/cli/base.rb +19 -0
- data/lib/ancor/cli/client.rb +104 -0
- data/lib/ancor/cli/environment.rb +38 -0
- data/lib/ancor/cli/front.rb +26 -0
- data/lib/ancor/cli/goal.rb +11 -0
- data/lib/ancor/cli/instance.rb +34 -0
- data/lib/ancor/cli/role.rb +11 -0
- data/lib/ancor/cli/task.rb +11 -0
- data/lib/ancor/cli/version.rb +5 -0
- data/lib/ancor/cli.rb +24 -0
- data/lib/ancor-cli.rb +1 -0
- data/spec/spec_helper.rb +0 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 296ba1bb431c97d213f3673cd9c2432eb77d542b
|
4
|
+
data.tar.gz: e45af8aca082b8aa3cfce93ff7d47d6bd063bd6b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ddaba75b2ea078de637b53496814ac1e810754142cc0385a0d1e24264a823fa18dd299f81520a8b64e11530235bc31a8b83dd6c6b85b154a16a6bb87527d86f1
|
7
|
+
data.tar.gz: 5bdf4446984d95dc1bd194dcf59b278955b05c2311daab44e55182dc3a37857f3722bf5d9421d0c815cc7c23299e78822b52765a5522d9baf78bbfb43fda1261
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2013-2014 Argus Cybersecurity Lab, Kansas State University
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/bin/ancor
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Ancor
|
2
|
+
module CLI
|
3
|
+
class Base < Thor
|
4
|
+
class_option :debug, type: :boolean, default: false
|
5
|
+
class_option :host, type: :string, default: 'localhost'
|
6
|
+
class_option :port, type: :numeric, default: 3000
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def connection
|
11
|
+
@connection ||= Client.new({
|
12
|
+
debug: options[:debug],
|
13
|
+
host: options[:host],
|
14
|
+
port: options[:port]
|
15
|
+
})
|
16
|
+
end
|
17
|
+
end # Base
|
18
|
+
end # CLI
|
19
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Ancor
|
2
|
+
module CLI
|
3
|
+
class Client
|
4
|
+
CONTENT_TYPE_JSON = 'application/json'
|
5
|
+
CONTENT_TYPE_YAML = 'application/yaml'
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
host = options.fetch(:host)
|
9
|
+
port = options.fetch(:port)
|
10
|
+
|
11
|
+
url = "http://#{host}:#{port}/v1/"
|
12
|
+
|
13
|
+
@connection = Faraday.new(url: url) do |faraday|
|
14
|
+
faraday.response :logger if options[:debug]
|
15
|
+
faraday.adapter Faraday.default_adapter
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def version
|
20
|
+
get ''
|
21
|
+
end
|
22
|
+
|
23
|
+
def commit(slug)
|
24
|
+
request_body = { commit: true }
|
25
|
+
put "environments/#{slug}", CONTENT_TYPE_JSON, request_body.to_json
|
26
|
+
end
|
27
|
+
|
28
|
+
def plan(slug, arml_spec)
|
29
|
+
post "environments/#{slug}/plan", CONTENT_TYPE_YAML, arml_spec
|
30
|
+
end
|
31
|
+
|
32
|
+
def list_goals
|
33
|
+
get 'goals'
|
34
|
+
end
|
35
|
+
|
36
|
+
def list_envs
|
37
|
+
get 'environments'
|
38
|
+
end
|
39
|
+
|
40
|
+
def list_roles
|
41
|
+
get 'roles'
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_tasks
|
45
|
+
get 'tasks'
|
46
|
+
end
|
47
|
+
|
48
|
+
def list_instances
|
49
|
+
get 'instances'
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_instance(role_slug)
|
53
|
+
request_body = { role: role_slug }
|
54
|
+
post 'instances', CONTENT_TYPE_JSON, request_body.to_json
|
55
|
+
end
|
56
|
+
|
57
|
+
def remove_instance(old_id)
|
58
|
+
@connection.delete "instances/#{old_id}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def replace_instance(old_id)
|
62
|
+
request_body = { replace: true }
|
63
|
+
post "instances/#{old_id}", CONTENT_TYPE_JSON, request_body.to_json
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_env(slug)
|
67
|
+
request_body = { slug: slug }
|
68
|
+
post 'environments', CONTENT_TYPE_JSON, request_body.to_json
|
69
|
+
end
|
70
|
+
|
71
|
+
def remove_env(slug)
|
72
|
+
@connection.delete "environments/#{slug}"
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# @param [String] url
|
78
|
+
# @return [Faraday::Response]
|
79
|
+
def get(url)
|
80
|
+
@connection.get url
|
81
|
+
end
|
82
|
+
|
83
|
+
# @param [String] url
|
84
|
+
# @param [String] content_type
|
85
|
+
# @param [String] body
|
86
|
+
# @return [Faraday::Response]
|
87
|
+
def post(url, content_type, body)
|
88
|
+
@connection.post do |req|
|
89
|
+
req.url url
|
90
|
+
req.headers['Content-Type'] = content_type
|
91
|
+
req.body = body
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def put(url, content_type, body)
|
96
|
+
@connection.put do |req|
|
97
|
+
req.url url
|
98
|
+
req.headers['Content-Type'] = content_type
|
99
|
+
req.body = body
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end # Client
|
103
|
+
end # CLI
|
104
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Ancor
|
2
|
+
module CLI
|
3
|
+
class Environment < Base
|
4
|
+
desc 'list', 'Lists all environments'
|
5
|
+
def list
|
6
|
+
parsed = JSON.parse(connection.list_envs.body)
|
7
|
+
Formatador.display_table(parsed, ['id', 'slug', 'name','locked'])
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'add <environment slug>', 'Adds an environment with the given name'
|
11
|
+
def add(slug)
|
12
|
+
connection.add_env(slug)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'remove <environment slug>', 'Removes an environment'
|
16
|
+
def remove(slug)
|
17
|
+
connection.remove_env(slug)
|
18
|
+
end
|
19
|
+
|
20
|
+
option :environment, default: 'production'
|
21
|
+
desc 'plan <path to arml file>', 'Imports an ARML specification and plans a deployment'
|
22
|
+
def plan(path_to_file)
|
23
|
+
begin
|
24
|
+
spec = File.read(path_to_file)
|
25
|
+
connection.plan(options[:environment], path_to_file)
|
26
|
+
rescue IOError, Errno::ENOENT
|
27
|
+
puts 'Could not read specification, make sure file path is correct'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
option :environment, default: 'production'
|
32
|
+
desc 'commit', 'Commits any planned deployments for the given environment'
|
33
|
+
def commit
|
34
|
+
connection.commit(options[:environment])
|
35
|
+
end
|
36
|
+
end # Environment
|
37
|
+
end # CLI
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Ancor
|
2
|
+
module CLI
|
3
|
+
class Front < Base
|
4
|
+
desc 'version', 'Displays the version of the ANCOR server'
|
5
|
+
def version
|
6
|
+
parsed = JSON.parse(connection.version.body)
|
7
|
+
puts 'ANCOR version ' + parsed['version']
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'goal <subcommand>', 'Manage goals'
|
11
|
+
subcommand 'goal', Goal
|
12
|
+
|
13
|
+
desc 'environment <subcommand>', 'Manage environments'
|
14
|
+
subcommand 'environment', Environment
|
15
|
+
|
16
|
+
desc 'role <subcommand>', 'Manage roles'
|
17
|
+
subcommand 'role', Role
|
18
|
+
|
19
|
+
desc 'task <subcommand>', 'Manage tasks'
|
20
|
+
subcommand 'task', Task
|
21
|
+
|
22
|
+
desc 'instance <subcommand>', 'Manage instances'
|
23
|
+
subcommand 'instance', Instance
|
24
|
+
end # Front
|
25
|
+
end # CLI
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Ancor
|
2
|
+
module CLI
|
3
|
+
class Instance < Base
|
4
|
+
desc 'list', 'Lists all instances'
|
5
|
+
def list
|
6
|
+
parsed = JSON.parse(connection.list_instances.body)
|
7
|
+
parsed.each do |instance|
|
8
|
+
instance['internal_ip'] = instance['interfaces'].map { |interface|
|
9
|
+
interface['ip_address']
|
10
|
+
}.join(', ')
|
11
|
+
if instance['public_ip']
|
12
|
+
instance['public_ip'] = instance['public_ip']['ip_address']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
Formatador.display_table(parsed, ['id', 'name', 'stage', 'planned_stage', 'internal_ip', 'public_ip'])
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'add <role slug>', 'Adds a new instance with the given role'
|
19
|
+
def add(role_slug)
|
20
|
+
connection.add_instance(role_slug)
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'remove <instance id>', 'Removes the given instance'
|
24
|
+
def remove(old_id)
|
25
|
+
connection.remove_instance(old_id)
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'replace <instance id>', 'Replaces the given instance with a new instance of the same role'
|
29
|
+
def replace(old_id)
|
30
|
+
connection.replace_instance(old_id)
|
31
|
+
end
|
32
|
+
end # Instance
|
33
|
+
end # CLI
|
34
|
+
end
|
data/lib/ancor/cli.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'formatador'
|
3
|
+
require 'json'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
require 'ancor/cli/version'
|
7
|
+
|
8
|
+
require 'ancor/cli/base'
|
9
|
+
require 'ancor/cli/client'
|
10
|
+
require 'ancor/cli/environment'
|
11
|
+
require 'ancor/cli/goal'
|
12
|
+
require 'ancor/cli/instance'
|
13
|
+
require 'ancor/cli/role'
|
14
|
+
require 'ancor/cli/task'
|
15
|
+
|
16
|
+
require 'ancor/cli/front'
|
17
|
+
|
18
|
+
module Ancor
|
19
|
+
module CLI
|
20
|
+
def self.start
|
21
|
+
Front.start(ARGV)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/ancor-cli.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ancor/cli'
|
data/spec/spec_helper.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ancor-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ian Unruh
|
8
|
+
- Alex Bardas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.9'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.9'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: formatador
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.2'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.2'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: thor
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0.18'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.18'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.14'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.14'
|
70
|
+
description: CLI used to interact with the ANCOR server API
|
71
|
+
email:
|
72
|
+
- iunruh@ksu.edu
|
73
|
+
- bardasag@ksu.edu
|
74
|
+
executables:
|
75
|
+
- ancor
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- bin/ancor
|
82
|
+
- lib/ancor-cli.rb
|
83
|
+
- lib/ancor/cli.rb
|
84
|
+
- lib/ancor/cli/base.rb
|
85
|
+
- lib/ancor/cli/client.rb
|
86
|
+
- lib/ancor/cli/environment.rb
|
87
|
+
- lib/ancor/cli/front.rb
|
88
|
+
- lib/ancor/cli/goal.rb
|
89
|
+
- lib/ancor/cli/instance.rb
|
90
|
+
- lib/ancor/cli/role.rb
|
91
|
+
- lib/ancor/cli/task.rb
|
92
|
+
- lib/ancor/cli/version.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
homepage: https://github.com/arguslab/ancor-cli
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.2.2
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: CLI used to interact with the ANCOR server API
|
118
|
+
test_files:
|
119
|
+
- spec/spec_helper.rb
|