magellan-cli 0.2.19 → 0.3.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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/magellan/cli/base.rb +13 -13
- data/lib/magellan/cli/command.rb +24 -5
- data/lib/magellan/cli/file_access.rb +9 -2
- data/lib/magellan/cli/http.rb +9 -12
- data/lib/magellan/cli/login.rb +7 -0
- data/lib/magellan/cli/resources/base.rb +20 -3
- data/lib/magellan/cli/resources/client_version.rb +10 -1
- data/lib/magellan/cli/resources/cloudsql.rb +2 -2
- data/lib/magellan/cli/resources/container.rb +1 -1
- data/lib/magellan/cli/resources/deletable.rb +28 -0
- data/lib/magellan/cli/resources/image.rb +1 -1
- data/lib/magellan/cli/resources/organization.rb +1 -0
- data/lib/magellan/cli/resources/project.rb +4 -2
- data/lib/magellan/cli/resources/stage.rb +28 -18
- data/lib/magellan/cli/resources/team.rb +2 -2
- data/lib/magellan/cli/resources/transaction_router.rb +1 -1
- data/lib/magellan/cli/resources/worker.rb +6 -4
- data/lib/magellan/cli/resources.rb +14 -0
- data/lib/magellan/cli/version.rb +1 -1
- data/spec/magellan/cli/resources/client_version_spec.rb +2 -2
- data/spec/magellan/cli/resources/organization_spec.rb +1 -1
- data/spec/magellan/cli/resources/team_spec.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f56a7867635b8b04efd6c8963f2e361d5595b4c
|
4
|
+
data.tar.gz: bdcd4c0d35743f63d06893c86f19ae444cfc23c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13e9af5a5addcd0a6b6e1f9112de1547c03ca2a6593ad49e417a6707309b2162552c0ed8fad4e1d0791095b27d091f476615fa9d5b52f82375c69b290158c2d1
|
7
|
+
data.tar.gz: f8e9cadeafb898f308e78cb5f8e5bfe1f6385474c3b2f23e87f491c31e1979285ad880da76a7d28592e2a108813f22d9f1765a0964c0730f3ce34132b05ac7bd
|
data/Gemfile.lock
CHANGED
data/lib/magellan/cli/base.rb
CHANGED
@@ -29,22 +29,22 @@ module Magellan
|
|
29
29
|
opts[:verbose]
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
self.class.
|
32
|
+
def log_verbose(msg)
|
33
|
+
self.class.log_verbose(msg) if verbose?
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
self.class.
|
36
|
+
def log_info(msg)
|
37
|
+
self.class.log_info(msg)
|
38
38
|
end
|
39
|
-
def
|
40
|
-
self.class.
|
39
|
+
def log_success(msg)
|
40
|
+
self.class.log_success(msg)
|
41
41
|
end
|
42
|
-
def
|
43
|
-
self.class.
|
42
|
+
def log_error(msg)
|
43
|
+
self.class.log_error(msg)
|
44
44
|
end
|
45
45
|
|
46
46
|
def fatal(msg)
|
47
|
-
|
47
|
+
log_verbose(caller.join("\n "))
|
48
48
|
raise Cli::Error, msg
|
49
49
|
end
|
50
50
|
end
|
@@ -54,16 +54,16 @@ module Magellan
|
|
54
54
|
$stderr.puts("\e[#{color_no}m#{msg}\e[0m")
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
57
|
+
def log_verbose(msg, flag = true)
|
58
58
|
puts_with_color(34, msg) if flag
|
59
59
|
end
|
60
|
-
def
|
60
|
+
def log_info(msg)
|
61
61
|
puts_with_color(0, msg)
|
62
62
|
end
|
63
|
-
def
|
63
|
+
def log_success(msg)
|
64
64
|
puts_with_color(32, msg)
|
65
65
|
end
|
66
|
-
def
|
66
|
+
def log_error(msg)
|
67
67
|
puts_with_color(31, msg)
|
68
68
|
end
|
69
69
|
|
data/lib/magellan/cli/command.rb
CHANGED
@@ -6,22 +6,26 @@ require 'active_support/core_ext/string/inflections'
|
|
6
6
|
module Magellan
|
7
7
|
module Cli
|
8
8
|
class Command < Base
|
9
|
+
include Magellan::Cli::FileAccess
|
9
10
|
|
10
11
|
class << self
|
11
12
|
# override Thor::Base.start method
|
12
13
|
def start(given_args = ARGV, config = {})
|
13
14
|
# class_options verbose and version are defined in Magellan::Cli::Base
|
14
|
-
if ARGV
|
15
|
-
|
15
|
+
if (ARGV == ["-v"] || ARGV == ["--version"])
|
16
|
+
log_info(File.basename($0) << " " << Magellan::Cli::VERSION)
|
17
|
+
exit(0)
|
18
|
+
elsif ARGV.include?("-v") || ARGV.include?("--version")
|
19
|
+
log_info(File.basename($0) << " " << Magellan::Cli::VERSION)
|
16
20
|
end
|
17
21
|
begin
|
18
22
|
super(given_args, config)
|
19
23
|
rescue Magellan::Cli::Error => e
|
20
|
-
|
24
|
+
log_error(e.message)
|
21
25
|
exit(1)
|
22
26
|
rescue => e
|
23
|
-
|
24
|
-
|
27
|
+
log_error("[#{e.class}] #{e.message}")
|
28
|
+
log_verbose(" " << e.backtrace.join("\n "), ARGV.include?("-V") || ARGV.include?("--verbose"))
|
25
29
|
exit(1)
|
26
30
|
end
|
27
31
|
end
|
@@ -66,6 +70,21 @@ module Magellan
|
|
66
70
|
Magellan::Cli::Http.new.login!(email, password)
|
67
71
|
end
|
68
72
|
|
73
|
+
desc "info", "Show login user and selected resources"
|
74
|
+
def info
|
75
|
+
cli = Magellan::Cli::Login.new
|
76
|
+
cli.check_login_auth!
|
77
|
+
selections = load_selections || {}
|
78
|
+
d = {"user" => cli.login_auth["email"] }
|
79
|
+
Resources::MAPPING.each do |classname, name|
|
80
|
+
klass = ::Magellan::Cli::Resources.const_get(classname)
|
81
|
+
if val = selections[ klass.parameter_name ]
|
82
|
+
d[name] = val["name"] ? val["name"] : val.inspect
|
83
|
+
end
|
84
|
+
end
|
85
|
+
log_info YAML.dump(d)
|
86
|
+
end
|
87
|
+
|
69
88
|
end
|
70
89
|
end
|
71
90
|
end
|
@@ -19,10 +19,17 @@ module Magellan
|
|
19
19
|
File.readable?(SELECTION_FILENAME) ? YAML.load_file(SELECTION_FILENAME) : {}
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
# @param [Class|String] obj Resource class or resource name
|
23
|
+
def load_selection(obj)
|
24
|
+
if obj.respond_to?(:parameter_name)
|
25
|
+
name = obj.parameter_name
|
26
|
+
label = obj.name.split(/::/).last.underscore
|
27
|
+
else
|
28
|
+
name = label = obj
|
29
|
+
end
|
23
30
|
sel = load_selections
|
24
31
|
s = sel[name]
|
25
|
-
raise NotSelected, "No #{
|
32
|
+
raise NotSelected, "No #{label} selected" unless s
|
26
33
|
return s
|
27
34
|
end
|
28
35
|
|
data/lib/magellan/cli/http.rb
CHANGED
@@ -14,21 +14,18 @@ module Magellan
|
|
14
14
|
def login!(email, password)
|
15
15
|
logined = cli.api_login!(email, password)
|
16
16
|
if logined
|
17
|
-
|
17
|
+
log_success("OK")
|
18
18
|
else
|
19
|
-
|
19
|
+
log_error("Login Failure.")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def access_api
|
24
24
|
if block_given?
|
25
|
-
|
26
|
-
if auth.nil? || auth.empty?
|
27
|
-
raise Magellan::Cli::Error, "Not logined yet. type `#{File.basename($0)} login`."
|
28
|
-
end
|
25
|
+
cli.check_login_auth!
|
29
26
|
return yield(cli)
|
30
27
|
else
|
31
|
-
return
|
28
|
+
return log_success("OK")
|
32
29
|
end
|
33
30
|
end
|
34
31
|
|
@@ -36,7 +33,7 @@ module Magellan
|
|
36
33
|
case res.status
|
37
34
|
when 200...300 then
|
38
35
|
r = JSON.parse(res.body)
|
39
|
-
|
36
|
+
log_verbose(JSON.pretty_generate(r))
|
40
37
|
r
|
41
38
|
else
|
42
39
|
obj = JSON.parse(res.body) rescue nil
|
@@ -45,7 +42,7 @@ module Magellan
|
|
45
42
|
else
|
46
43
|
msg = "HTTP Error: status=#{res.status}"
|
47
44
|
msg << "\n#{res.body}" if verbose?
|
48
|
-
|
45
|
+
log_error(msg)
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
@@ -62,7 +59,7 @@ module Magellan
|
|
62
59
|
if params && !params.empty?
|
63
60
|
url << '?' << params.map{|k,v| "%s=%s" % [CGI.escape(k.to_s), CGI.escape(v.to_s)] }.join("&")
|
64
61
|
end
|
65
|
-
|
62
|
+
log_verbose("GET #{url}")
|
66
63
|
# "Unknown key: max-age = 0" というメッセージを表示させないために$stderrを一時的に上書き
|
67
64
|
$stderr, bak = StringIO.new, $stderr
|
68
65
|
res = nil
|
@@ -125,13 +122,13 @@ module Magellan
|
|
125
122
|
def delete(rel_path)
|
126
123
|
access_api do |api|
|
127
124
|
params = api.login_auth
|
128
|
-
process_res(api, :delete, rel_path, params)
|
125
|
+
process_res(api, :delete, rel_path, params.to_json, JSON_HEADER)
|
129
126
|
end
|
130
127
|
end
|
131
128
|
|
132
129
|
def process_res(api, http_method, rel_path, *args)
|
133
130
|
url = "#{api.base_url}#{rel_path}"
|
134
|
-
|
131
|
+
log_verbose("%s %s\n%s" % [http_method.to_s.upcase, url, args])
|
135
132
|
res = api.httpclient.send(http_method, url, *args)
|
136
133
|
check_response(res)
|
137
134
|
end
|
data/lib/magellan/cli/login.rb
CHANGED
@@ -56,6 +56,13 @@ module Magellan
|
|
56
56
|
@login_url ||= base_url + "/api/sign_in.json"
|
57
57
|
end
|
58
58
|
|
59
|
+
def check_login_auth!
|
60
|
+
auth = login_auth
|
61
|
+
if auth.nil? || auth.empty?
|
62
|
+
raise Magellan::Cli::Error, "Not logined yet. type `#{File.basename($0)} login`."
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
59
66
|
# magellan-apiサーバに接続してログインの検証とアクセストークンの保存を行います。
|
60
67
|
#
|
61
68
|
# @return [boolean] login成功/失敗
|
@@ -53,12 +53,16 @@ module Magellan
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
def get_first_result!(name, path, query)
|
57
|
+
results = get_json(path, query)
|
58
|
+
raise NotFound, "#{name} not found for #{query.inspect}" if results.blank? || results.first.blank?
|
59
|
+
results.first
|
60
|
+
end
|
61
|
+
|
56
62
|
DEFAULT_SELECTION_FIELDS = %w[id name].freeze
|
57
63
|
|
58
64
|
def update_first_result(name, path, query, fields = DEFAULT_SELECTION_FIELDS)
|
59
|
-
|
60
|
-
raise NotFound, "#{name} not found for #{query.inspect}" if results.blank? || results.first.blank?
|
61
|
-
r = results.first
|
65
|
+
r = get_first_result!(name, path, query)
|
62
66
|
obj = fields.each_with_object({}) do |f, d|
|
63
67
|
d[f] = r[f]
|
64
68
|
end
|
@@ -108,14 +112,17 @@ module Magellan
|
|
108
112
|
(self.class.multiline_fields || [])
|
109
113
|
|
110
114
|
fields = original_fields.dup
|
115
|
+
fields.unshift(" ")
|
111
116
|
associations = association_map(fields)
|
112
117
|
|
113
118
|
t.head = fields
|
114
119
|
t.rows = []
|
120
|
+
selected_id = (load_selections[ parameter_name ] || {})["id"]
|
115
121
|
res1.each do |r|
|
116
122
|
row = original_fields.map do |f|
|
117
123
|
association_get(associations, r, f)
|
118
124
|
end
|
125
|
+
row.unshift(r["id"] == selected_id ? "*" : " ")
|
119
126
|
t.rows << row
|
120
127
|
end
|
121
128
|
# $stdout.puts(JSON.pretty_generate(res1) << "\nTotal: #{res1.length}")
|
@@ -166,6 +173,16 @@ module Magellan
|
|
166
173
|
update_selections! do |s|
|
167
174
|
s.delete(self.class.parameter_name)
|
168
175
|
end
|
176
|
+
deselect_dependants
|
177
|
+
end
|
178
|
+
|
179
|
+
def deselect_dependants
|
180
|
+
update_selections! do |s|
|
181
|
+
classes = Resources.dependants_on(self.class)
|
182
|
+
classes.each do |klass|
|
183
|
+
s.delete(klass.parameter_name)
|
184
|
+
end
|
185
|
+
end
|
169
186
|
end
|
170
187
|
|
171
188
|
def self.inherited(klass)
|
@@ -16,7 +16,7 @@ module Magellan
|
|
16
16
|
|
17
17
|
desc "create VERSION", "Create a new #{resource_name}"
|
18
18
|
def create(version)
|
19
|
-
stage = load_selection!(
|
19
|
+
stage = load_selection!(Stage)
|
20
20
|
params = {
|
21
21
|
parameter_name => {
|
22
22
|
"stage_title_id" => stage["id"],
|
@@ -27,6 +27,15 @@ module Magellan
|
|
27
27
|
# TODO implement select method
|
28
28
|
# select(version)
|
29
29
|
end
|
30
|
+
|
31
|
+
desc "delete VERSION", "Delete the #{resource_name} specified by VERSION"
|
32
|
+
def delete(version)
|
33
|
+
q = build_query("version" => version).update(default_query)
|
34
|
+
r = get_first_result!(self.class.resource_name, "/admin/#{resource_key}.json", q)
|
35
|
+
super("/admin/#{resource_key}/#{r['id']}/delete")
|
36
|
+
log_success("OK")
|
37
|
+
end
|
38
|
+
|
30
39
|
end
|
31
40
|
|
32
41
|
end
|
@@ -7,12 +7,12 @@ module Magellan
|
|
7
7
|
|
8
8
|
class Cloudsql < Base
|
9
9
|
self.resource_key = "cloudsql~database"
|
10
|
-
self.resource_dependency = {"stage" =>
|
10
|
+
self.resource_dependency = {"stage" => Stage.parameter_name}
|
11
11
|
self.hidden_fields = %w[cloudsql_instance_id].map(&:freeze).freeze
|
12
12
|
|
13
13
|
desc "create NAME", "Create a new #{resource_name} database with NAME"
|
14
14
|
def create(name)
|
15
|
-
o = load_selection!(
|
15
|
+
o = load_selection!(Stage)
|
16
16
|
params = {
|
17
17
|
parameter_name => {
|
18
18
|
"stage_title_id" => o["id"],
|
@@ -7,7 +7,7 @@ module Magellan
|
|
7
7
|
|
8
8
|
class Container < Base
|
9
9
|
self.resource_key = "container~instance"
|
10
|
-
self.resource_dependency = {"stage" =>
|
10
|
+
self.resource_dependency = {"stage" => Stage::VERSION_PARAMETER_NAME}
|
11
11
|
self.hidden_fields = %w[created_at updated_at].map(&:freeze).freeze
|
12
12
|
self.multiline_fields = %w[docker_properties_json links_yaml publishings_yaml volumes_yaml env_yaml].map(&:freeze).freeze
|
13
13
|
self.field_associations = {
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "magellan/cli/resources"
|
3
|
+
|
4
|
+
module Magellan
|
5
|
+
module Cli
|
6
|
+
module Resources
|
7
|
+
|
8
|
+
module Deletable
|
9
|
+
|
10
|
+
def self.included(klass)
|
11
|
+
klass.module_eval do
|
12
|
+
|
13
|
+
desc "delete NAME", "Delete the #{resource_name} named by NAME"
|
14
|
+
def delete(name)
|
15
|
+
q = build_query("name" => name).update(default_query)
|
16
|
+
r = get_first_result!(self.class.resource_name, "/admin/#{resource_key}.json", q)
|
17
|
+
super("/admin/#{resource_key}/#{r['id']}/delete")
|
18
|
+
log_success("OK")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -7,7 +7,7 @@ module Magellan
|
|
7
7
|
|
8
8
|
class Image < Base
|
9
9
|
self.resource_key = "container~image"
|
10
|
-
self.resource_dependency = {"stage" =>
|
10
|
+
self.resource_dependency = {"stage" => Stage::VERSION_PARAMETER_NAME}
|
11
11
|
self.hidden_fields = %w[function_id function_type created_at updated_at].map(&:freeze).freeze
|
12
12
|
self.field_associations = {"stage_version_id" => {name: "stage", resource: "stage~version"} }
|
13
13
|
end
|
@@ -6,6 +6,8 @@ module Magellan
|
|
6
6
|
module Resources
|
7
7
|
|
8
8
|
class Project < Base
|
9
|
+
include Deletable
|
10
|
+
|
9
11
|
self.resource_key = "project"
|
10
12
|
self.resource_dependency = nil
|
11
13
|
self.hidden_fields = %w[default_nebula_id created_at updated_at].map(&:freeze).freeze
|
@@ -13,14 +15,14 @@ module Magellan
|
|
13
15
|
|
14
16
|
desc "update ATTRIBUTES", "Update the ATTRIBUTES of the selected #{resource_name}"
|
15
17
|
def update(attrs)
|
16
|
-
s = load_selection!(
|
18
|
+
s = load_selection!(self.class)
|
17
19
|
attrs = JSON.parse(File.readable?(attrs) ? File.read(attrs) : attrs)
|
18
20
|
put_json("/admin/project/#{s['id']}/edit", {"project" => attrs})
|
19
21
|
end
|
20
22
|
|
21
23
|
desc "create NAME", "Create a new #{resource_name} with NAME"
|
22
24
|
def create(name)
|
23
|
-
o = load_selection!(Organization
|
25
|
+
o = load_selection!(Organization)
|
24
26
|
params = {
|
25
27
|
parameter_name => {
|
26
28
|
"organization_id" => o["id"],
|
@@ -7,11 +7,16 @@ module Magellan
|
|
7
7
|
module Resources
|
8
8
|
|
9
9
|
class Stage < Base
|
10
|
+
include Deletable
|
11
|
+
|
10
12
|
self.resource_key = "stage~title"
|
11
|
-
self.resource_dependency = {"project" =>
|
13
|
+
self.resource_dependency = {"project" => Project.parameter_name}
|
12
14
|
self.hidden_fields = %w[nebula_id created_at updated_at].map(&:freeze).freeze
|
13
15
|
self.field_associations = {"project_id" => {name: "project", class: "Project"} }
|
14
16
|
|
17
|
+
VERSION_RESOURCE_KEY = "stage~version".freeze
|
18
|
+
VERSION_PARAMETER_NAME = "stage_version".freeze
|
19
|
+
|
15
20
|
desc "create NAME [-t development|staging|production|other]", "Create a new #{resource_name} with Name and Type"
|
16
21
|
option :t, type: :string, default: "development", desc: "-t development|staging|production. specify Stage Type"
|
17
22
|
def create(name)
|
@@ -19,7 +24,7 @@ module Magellan
|
|
19
24
|
unless %w{ development staging production other }.include?(type)
|
20
25
|
raise "Unknown Stage Type #{type}"
|
21
26
|
end
|
22
|
-
proj = load_selection!(
|
27
|
+
proj = load_selection!(Project)
|
23
28
|
params = {
|
24
29
|
parameter_name => {
|
25
30
|
"project_id" => proj["id"],
|
@@ -33,24 +38,29 @@ module Magellan
|
|
33
38
|
|
34
39
|
desc "select NAME", "Select the #{resource_name} named by NAME"
|
35
40
|
def select(name)
|
41
|
+
if selected = load_selections[parameter_name]
|
42
|
+
deselect unless selected["name"] == name
|
43
|
+
end
|
44
|
+
|
36
45
|
q = build_query("name" => name).update(default_query)
|
37
|
-
r = update_first_result(
|
46
|
+
r = update_first_result(parameter_name, "/admin/stage~title.json", q)
|
38
47
|
|
39
48
|
# # current
|
40
49
|
# q = build_query("title" => r["id"], "phase" => 2) # 2: current
|
41
|
-
# update_first_result(
|
50
|
+
# update_first_result(VERSION_PARAMETER_NAME, "/admin/stage~version.json", q, %w[id])
|
42
51
|
|
43
52
|
# # workspace
|
44
53
|
q = build_query("title" => r["id"], "phase" => 1) # 1: workspace
|
45
|
-
update_first_result(
|
54
|
+
update_first_result(VERSION_PARAMETER_NAME, "/admin/stage~version.json", q, %w[id])
|
46
55
|
end
|
47
56
|
|
48
57
|
desc "deselect", "Deselect the #{resource_name}"
|
49
58
|
def deselect
|
50
59
|
update_selections! do |s|
|
51
|
-
s.delete(
|
52
|
-
s.delete(
|
60
|
+
s.delete(parameter_name)
|
61
|
+
s.delete(VERSION_PARAMETER_NAME)
|
53
62
|
end
|
63
|
+
deselect_dependants
|
54
64
|
end
|
55
65
|
|
56
66
|
desc "planning", "Switch to planning to build next released version"
|
@@ -65,15 +75,15 @@ module Magellan
|
|
65
75
|
|
66
76
|
no_commands do
|
67
77
|
def switch_version(phase)
|
68
|
-
s = load_selection!(
|
78
|
+
s = load_selection!(self.class)
|
69
79
|
q = build_query("title" => s["id"], "phase" => phase) # 1: workspace, 2: current, 3: used
|
70
|
-
update_first_result(
|
80
|
+
update_first_result(VERSION_PARAMETER_NAME, "/admin/stage~version.json", q, %w[id])
|
71
81
|
end
|
72
82
|
end
|
73
83
|
|
74
84
|
desc "prepare", "Prepare the #{Container.resource_name.pluralize}"
|
75
85
|
def prepare
|
76
|
-
s = load_selection!(
|
86
|
+
s = load_selection!(self.class)
|
77
87
|
id = s["id"]
|
78
88
|
r = post_json("/admin/stage~title/#{id}/simple_method_call.json", {method_name: "prepare_containers"})
|
79
89
|
Container.new.show_list(r["result"])
|
@@ -87,7 +97,7 @@ module Magellan
|
|
87
97
|
|
88
98
|
no_commands do
|
89
99
|
def call_repair
|
90
|
-
s = load_selection!(
|
100
|
+
s = load_selection!(self.class)
|
91
101
|
id = s["id"]
|
92
102
|
post_json("/admin/stage~title/#{id}/simple_method_call.json", {method_name: "repair"})
|
93
103
|
end
|
@@ -95,7 +105,7 @@ module Magellan
|
|
95
105
|
|
96
106
|
desc "update ATTRIBUTES", "Update ATTRIBUTES of the #{resource_name}"
|
97
107
|
def update(attrs)
|
98
|
-
s = load_selection!(
|
108
|
+
s = load_selection!(self.class)
|
99
109
|
attrs = JSON.parse(File.readable?(attrs) ? File.read(attrs) : attrs)
|
100
110
|
put_json("/admin/stage~title/#{s['id']}/edit", {"stage_title" => attrs})
|
101
111
|
end
|
@@ -106,7 +116,7 @@ module Magellan
|
|
106
116
|
option :t, type: :numeric, default: 600, desc: "-t timeout(seconds)"
|
107
117
|
def release_now
|
108
118
|
spacer = "\r" << (" " * 20)
|
109
|
-
stage = load_selection!(
|
119
|
+
stage = load_selection!(self.class)
|
110
120
|
print "\rrelease starting"
|
111
121
|
id = stage["id"]
|
112
122
|
res0 = post_json("/admin/stage~title/#{id}/simple_method_call.json", {method_name: "release_now"})
|
@@ -158,7 +168,7 @@ module Magellan
|
|
158
168
|
|
159
169
|
desc "logs", "Fetch the logs of the #{Worker.resource_name.pluralize}"
|
160
170
|
def logs
|
161
|
-
s = load_selection!(
|
171
|
+
s = load_selection!(self.class)
|
162
172
|
id = s["id"]
|
163
173
|
obj = get_json("/admin/stage~title/#{id}/logs.json")
|
164
174
|
if obj["value"]
|
@@ -170,15 +180,15 @@ module Magellan
|
|
170
180
|
|
171
181
|
desc "set_container_num NUM", "Set the number of #{Container.resource_name.pluralize} for the selected #{Image.resource_name}"
|
172
182
|
def set_container_num(num)
|
173
|
-
s = load_selection!(
|
174
|
-
v = load_selection!(
|
175
|
-
i = load_selection!(
|
183
|
+
s = load_selection!(self.class)
|
184
|
+
v = load_selection!(VERSION_PARAMETER_NAME)
|
185
|
+
i = load_selection!(Image)
|
176
186
|
post_json("/admin/stage~version/#{v["id"]}/set_container_num.json", { container_num: num, container_image_id: i["id"] })
|
177
187
|
end
|
178
188
|
|
179
189
|
desc "reload", "Reload the last selections"
|
180
190
|
def reload
|
181
|
-
s = load_selection!(
|
191
|
+
s = load_selection!(self.class)
|
182
192
|
select(s["name"])
|
183
193
|
[Worker, Image, Container].each do |klass|
|
184
194
|
s = (load_selections || {})[klass.parameter_name]
|
@@ -15,7 +15,7 @@ module Magellan
|
|
15
15
|
unless %w{ reader admin }.include?(role)
|
16
16
|
raise "ROLE should be 'reader' or 'admin'"
|
17
17
|
end
|
18
|
-
o = load_selection!(Organization
|
18
|
+
o = load_selection!(Organization)
|
19
19
|
params = {
|
20
20
|
parameter_name => {
|
21
21
|
"organization_id" => o["id"],
|
@@ -30,7 +30,7 @@ module Magellan
|
|
30
30
|
=begin
|
31
31
|
desc "invite EMAIL", "Invite a user to the #{Team.resource_name}"
|
32
32
|
def invite(email)
|
33
|
-
o = load_selection!(
|
33
|
+
o = load_selection!(self.class)
|
34
34
|
params = {
|
35
35
|
"email" => email
|
36
36
|
}
|
@@ -11,7 +11,7 @@ module Magellan
|
|
11
11
|
|
12
12
|
desc "create NAME", "Create a new #{resource_name} with NAME"
|
13
13
|
def create(name)
|
14
|
-
s = load_selection!(
|
14
|
+
s = load_selection!(Stage::VERSION_PARAMETER_NAME)
|
15
15
|
params = {
|
16
16
|
self.class.parameter_name => {
|
17
17
|
"stage_version_id" => s["id"],
|
@@ -6,8 +6,10 @@ module Magellan
|
|
6
6
|
module Resources
|
7
7
|
|
8
8
|
class Worker < Base
|
9
|
+
include Deletable
|
10
|
+
|
9
11
|
self.resource_key = "functions~worker"
|
10
|
-
self.resource_dependency = {"stage" =>
|
12
|
+
self.resource_dependency = {"stage" => Stage::VERSION_PARAMETER_NAME}
|
11
13
|
self.hidden_fields = %w[created_at updated_at].map(&:freeze).freeze
|
12
14
|
self.multiline_fields = %w[migration_command_1 migration_command_2 run_command environment_vars_yaml].map(&:freeze).freeze
|
13
15
|
self.field_associations = {"stage_version_id" => {name: "stage", resource: "stage~version"} }
|
@@ -15,7 +17,7 @@ module Magellan
|
|
15
17
|
desc "create NAME, IMAGE", "Create a new #{resource_name} with NAME and IMAGE"
|
16
18
|
method_option :attributes_yaml, aliases: "-A", desc: "path to YAML file which defines attributes"
|
17
19
|
def create(name, image_name)
|
18
|
-
s = load_selection!(
|
20
|
+
s = load_selection!(Stage::VERSION_PARAMETER_NAME)
|
19
21
|
attrs =
|
20
22
|
if path = options[:attributes_yaml]
|
21
23
|
YAML.load_file(path)
|
@@ -41,7 +43,7 @@ module Magellan
|
|
41
43
|
else
|
42
44
|
attrs = JSON.parse(attrs)
|
43
45
|
end
|
44
|
-
w = load_selection!(
|
46
|
+
w = load_selection!(self.class)
|
45
47
|
self.class.hidden_fields.each do |f| attrs.delete(f) end
|
46
48
|
self.class.field_associations.keys.each do |f| attrs.delete(f) end
|
47
49
|
params = {
|
@@ -52,7 +54,7 @@ module Magellan
|
|
52
54
|
|
53
55
|
desc "prepare_images", "Prepare the #{Image.resource_name.pluralize} for the selected #{Worker.resource_name}"
|
54
56
|
def prepare_images
|
55
|
-
s = load_selection!(
|
57
|
+
s = load_selection!(Worker)
|
56
58
|
id = s["id"]
|
57
59
|
r = post_json("/admin/functions~worker/#{id}/simple_method_call.json", {method_name: "prepare_images"})
|
58
60
|
Image.new.show_list(r["result"])
|
@@ -24,6 +24,8 @@ module Magellan
|
|
24
24
|
|
25
25
|
autoload :Cloudsql, "magellan/cli/resources/cloudsql"
|
26
26
|
|
27
|
+
autoload :Deletable, "magellan/cli/resources/deletable"
|
28
|
+
|
27
29
|
|
28
30
|
MAPPING =\
|
29
31
|
{
|
@@ -39,6 +41,18 @@ module Magellan
|
|
39
41
|
"Cloudsql" => "cloudsql",
|
40
42
|
}
|
41
43
|
|
44
|
+
class << self
|
45
|
+
def concrete_classes
|
46
|
+
@concrete_classes ||= MAPPING.keys.map{|c| self.const_get(c) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def dependants_on(klass)
|
50
|
+
name = klass.name.split(/::/).last
|
51
|
+
res_name = MAPPING[name] or raise "unknown class named #{klass.name}"
|
52
|
+
concrete_classes.select{|c| c.resource_dependency && !!c.resource_dependency[res_name] }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
42
56
|
end
|
43
57
|
end
|
44
58
|
end
|
data/lib/magellan/cli/version.rb
CHANGED
@@ -5,7 +5,7 @@ describe Magellan::Cli::Resources::ClientVersion do
|
|
5
5
|
|
6
6
|
let(:cmd){ Magellan::Cli::Resources::ClientVersion.new }
|
7
7
|
|
8
|
-
let(:cli){ double(:cli,
|
8
|
+
let(:cli){ double(:cli, :check_login_auth! => nil) }
|
9
9
|
before{ allow(cmd).to receive(:cli).and_return(cli) }
|
10
10
|
|
11
11
|
describe :list do
|
@@ -22,7 +22,7 @@ describe Magellan::Cli::Resources::ClientVersion do
|
|
22
22
|
describe :success do
|
23
23
|
let(:client_version_list_response) { [ { "id" => 1, "version" => "1.1.0" } ] }
|
24
24
|
before do
|
25
|
-
allow(cmd).to receive(:load_selections).and_return({
|
25
|
+
allow(cmd).to receive(:load_selections).and_return({Magellan::Cli::Resources::Project.parameter_name => {"id" => 1, "name" => "ProjectA"}, Magellan::Cli::Resources::Stage.parameter_name => {"id" => 1, "name" => "StageA"} })
|
26
26
|
expect(cmd).to receive(:post_json).with("/admin/client_version/new.json", { "client_version" => { "stage_title_id" => 1, "version" => "1.1.0" } })
|
27
27
|
# TODO: stub in details
|
28
28
|
# expect(cmd).to receive(:get_json).with(any_args).and_return(client_version_list_response)
|
@@ -5,7 +5,7 @@ describe Magellan::Cli::Resources::Organization do
|
|
5
5
|
|
6
6
|
let(:cmd){ Magellan::Cli::Resources::Organization.new }
|
7
7
|
|
8
|
-
let(:cli){ double(:cli,
|
8
|
+
let(:cli){ double(:cli, :check_login_auth! => nil) }
|
9
9
|
before{ allow(cmd).to receive(:cli).and_return(cli) }
|
10
10
|
|
11
11
|
describe :list do
|
@@ -5,7 +5,7 @@ describe Magellan::Cli::Resources::Team do
|
|
5
5
|
|
6
6
|
let(:cmd){ Magellan::Cli::Resources::Team.new }
|
7
7
|
|
8
|
-
let(:cli){ double(:cli,
|
8
|
+
let(:cli){ double(:cli, :check_login_auth! => nil) }
|
9
9
|
before{ allow(cmd).to receive(:cli).and_return(cli) }
|
10
10
|
|
11
11
|
describe :list do
|
@@ -22,7 +22,7 @@ describe Magellan::Cli::Resources::Team do
|
|
22
22
|
describe :success do
|
23
23
|
let(:team_list_response) { [{"id" => 1, "name" => "team1"}] }
|
24
24
|
before do
|
25
|
-
allow(cmd).to receive(:load_selections).and_return({
|
25
|
+
allow(cmd).to receive(:load_selections).and_return({ Magellan::Cli::Resources::Organization.parameter_name => {"id" => 1, "name" => "org1"}})
|
26
26
|
expect(cmd).to receive(:post_json).with("/admin/magellan~auth~team/new.json", { "magellan_auth_team" => { "organization_id" => 1, "name" => "team1", "role" => role } })
|
27
27
|
# TODO: stub in details...
|
28
28
|
allow(cmd).to receive(:get_json).with(any_args).and_return(team_list_response)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magellan-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akm2000
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- lib/magellan/cli/resources/client_version.rb
|
155
155
|
- lib/magellan/cli/resources/cloudsql.rb
|
156
156
|
- lib/magellan/cli/resources/container.rb
|
157
|
+
- lib/magellan/cli/resources/deletable.rb
|
157
158
|
- lib/magellan/cli/resources/image.rb
|
158
159
|
- lib/magellan/cli/resources/organization.rb
|
159
160
|
- lib/magellan/cli/resources/project.rb
|