Class: Flydata::Command::Base
Direct Known Subclasses
Conf, Crontab, Encrypt, Helper, Kill_all, Login, Restart, Routine, Sender, Setlogdel, Setup, Start, Status, Stop, Sync, Version
Instance Attribute Summary collapse
Instance Method Summary
collapse
included
#before_logging, #log_error_stderr, #log_info_stdout, #log_warn_stderr
Constructor Details
#initialize(options = Slop.new) ⇒ Base
Returns a new instance of Base.
19
20
21
22
|
# File 'lib/flydata/command/base.rb', line 19
def initialize(options = Slop.new)
@api_client = ApiClient.instance
@opts = options
end
|
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
23
24
25
|
# File 'lib/flydata/command/base.rb', line 23
def opts
@opts
end
|
Instance Method Details
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/flydata/command/base.rb', line 154
def ask_input_table_name
input = nil
loop do
log_info_stdout("Input a table name.")
say(">> ")
input = gets.strip
if input =~ /^[a-zA-Z0-9_]+$/
break
else
puts "Please enter a valid table name."
end
end
log_info(">> #{input}")
input
end
|
#ask_yes_no(message, default_yes = true) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/flydata/command/base.rb', line 115
def ask_yes_no(message, default_yes=true)
suffix = default_yes ? "(Y/n)" : "(y/n)"
prompt = "#{message} #{suffix}: "
if opts && opts.yes? log_info_stdout("#{prompt}Yes")
return true
end
loop do
ans = ask(prompt)
return true if default_yes and ans == ''
if ans.size > 0
case ans[0].downcase
when 'y'
log_info("#{prompt}Yes")
return true
when 'n'
log_info("#{prompt}No")
return false
end
end
log_warn_stderr(" ! Please answer y[es] or n[o]")
newline
end
end
|
#choose_one(message, prompt, menu_list, value_list = []) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/flydata/command/base.rb', line 140
def choose_one(message, prompt, , value_list=[])
choice = nil
value_list = unless .size == value_list.size
log_info_stdout(message) if message
choose do ||
.index = :number
.index_suffix = ") "
.select_by = :index
.prompt = prompt ? prompt : ">> "
.choices(*) {|item| choice = value_list[.index(item)]}
end
log_info_stdout(" -> #{choice}")
choice
end
|
#dashboard_url ⇒ Object
102
103
104
|
# File 'lib/flydata/command/base.rb', line 102
def dashboard_url
"#{flydata.flydata_api_host}/dashboard"
end
|
#data_entry(refresh: false) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/flydata/command/base.rb', line 58
def data_entry(refresh: false)
if @de.nil? || refresh
@de = retrieve_data_entries.first
end
unless @de
raise AgentInternalError.new(
"No data entry exists. Please set one up on the FlyData Console (#{dashboard_url})",
AgentInternalError::NO_DATA_ENTRY_ERR)
end
@de
end
|
#data_port ⇒ Object
70
71
72
73
|
# File 'lib/flydata/command/base.rb', line 70
def data_port
return @data_port if @data_port
@data_port = flydata.data_port.get
end
|
#flydata ⇒ Object
24
|
# File 'lib/flydata/command/base.rb', line 24
def flydata; @api_client end
|
#newline ⇒ Object
111
|
# File 'lib/flydata/command/base.rb', line 111
def newline; puts end
|
#redshift_cluster ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/flydata/command/base.rb', line 75
def redshift_cluster
return @redshift_cluster if @redshift_cluster
@redshift_cluster = flydata.redshift_cluster.show_default
@redshift_cluster['password'] = Flydata::Util::Encryptor.decrypt(
@redshift_cluster['encrypted_password'],
data_port['key'],
'redshift_cluster password')
@redshift_cluster
end
|
#redshift_console_url ⇒ Object
106
107
108
|
# File 'lib/flydata/command/base.rb', line 106
def redshift_console_url
"#{flydata.flydata_api_host}/redshift_clusters/query/new"
end
|
#register_crontab ⇒ Object
93
94
95
96
97
98
99
100
|
# File 'lib/flydata/command/base.rb', line 93
def register_crontab
data_entries = retrieve_data_entries
if data_entries.any?{|e| e['log_deletion']}
require 'flydata/command/crontab'
Flydata::Command::Crontab.new.run
end
end
|
#retrieve_data_entries ⇒ Object
#separator(str = "=") ⇒ Object
112
113
114
|
# File 'lib/flydata/command/base.rb', line 112
def separator(str="=")
puts str * 64
end
|
#show_purpose_name ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/flydata/command/base.rb', line 42
def show_purpose_name
begin
de = data_entry
log_info_stdout("Your current application name is '#{de['purpose_name']}'")
rescue RestClient::Unauthorized => e
log_warn_stderr("This application is deleted.")
rescue AgentInternalError => e
case e.code
when AgentInternalError::NO_DATA_ENTRY_ERR
log_warn_stderr("#{e}")
else
raise e
end
end
end
|
#source(refresh: false) ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/flydata/command/base.rb', line 85
def source(refresh: false)
if @source.nil? || refresh
@source = nil
@source = Source.create(data_entry(refresh: refresh))
end
@source
end
|