flydata 0.0.2.3 → 0.0.3.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/flydata.gemspec +4 -4
- data/lib/flydata/api/base.rb +1 -1
- data/lib/flydata/api_client.rb +16 -7
- data/lib/flydata/command/login.rb +3 -11
- data/lib/flydata/command/setup.rb +81 -11
- data/lib/flydata/credentials.rb +9 -16
- metadata +7 -7
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3.rc1
|
data/flydata.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "flydata"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3.rc1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Koichi Fujikawa"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-11-14"
|
13
13
|
s.description = "FlyData Command Line Interface"
|
14
14
|
s.email = "sysadmin@flydata.co"
|
15
15
|
s.executables = ["flydata"]
|
@@ -52,7 +52,7 @@ Gem::Specification.new do |s|
|
|
52
52
|
s.homepage = "http://flydata.co/"
|
53
53
|
s.licenses = ["All right reserved."]
|
54
54
|
s.require_paths = ["lib"]
|
55
|
-
s.rubygems_version = "1.8.
|
55
|
+
s.rubygems_version = "1.8.24"
|
56
56
|
s.summary = "FlyData CLI"
|
57
57
|
|
58
58
|
if s.respond_to? :specification_version then
|
data/lib/flydata/api/base.rb
CHANGED
data/lib/flydata/api_client.rb
CHANGED
@@ -14,20 +14,20 @@ module Flydata
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# row level api
|
17
|
-
def post(path, params=nil)
|
18
|
-
uri =
|
19
|
-
resource = RestClient::Resource.new(uri, resource_opts)
|
17
|
+
def post(path, headers = nil, params=nil)
|
18
|
+
uri = generate_auth_url(path)
|
19
|
+
resource = RestClient::Resource.new(uri, resource_opts(headers))
|
20
20
|
@response = resource.post(params, :accept => :json)
|
21
21
|
handle_response response
|
22
22
|
end
|
23
23
|
def put(path, params=nil)
|
24
|
-
uri =
|
24
|
+
uri = generate_auth_url(path)
|
25
25
|
resource = RestClient::Resource.new(uri, resource_opts)
|
26
26
|
@response = resource.put(params, :accept => :json)
|
27
27
|
handle_response response
|
28
28
|
end
|
29
29
|
def get(path)
|
30
|
-
uri =
|
30
|
+
uri = generate_auth_url(path)
|
31
31
|
resource = RestClient::Resource.new(uri, resource_opts)
|
32
32
|
@response = resource.get(:accept => :json)
|
33
33
|
handle_response response
|
@@ -47,11 +47,20 @@ module Flydata
|
|
47
47
|
if json_response.class == Hash and json_response["success"] == false
|
48
48
|
err_msg = json_response['errors'] ? json_response['errors'].to_s : "Unkown error."
|
49
49
|
raise err_msg
|
50
|
+
elsif json_response.class == Hash and json_response["auth_token"]
|
51
|
+
@credentials.write_credentials(json_response["auth_token"])
|
50
52
|
end
|
51
53
|
json_response
|
52
54
|
end
|
53
|
-
def resource_opts
|
54
|
-
|
55
|
+
def resource_opts(headers=nil)
|
56
|
+
# merge headers and default parameter
|
57
|
+
parameters = {}
|
58
|
+
parameters.merge(headers) if headers
|
59
|
+
end
|
60
|
+
def generate_auth_url(path)
|
61
|
+
token = @credentials.token
|
62
|
+
token = '' unless token
|
63
|
+
"#{FLYDATA_API_HOST}#{path}?auth_token=#{token}"
|
55
64
|
end
|
56
65
|
end
|
57
66
|
end
|
@@ -20,19 +20,11 @@ module Flydata
|
|
20
20
|
false
|
21
21
|
end
|
22
22
|
def login_once
|
23
|
-
# Ask login info
|
24
23
|
email = ask("FlyData Email: ")
|
25
24
|
password = ask("FlyData password: ") {|q| q.echo = false}
|
26
|
-
flydata.
|
27
|
-
|
28
|
-
|
29
|
-
if flydata.response.code == 201 # 201: Created
|
30
|
-
say("Login succeeded!")
|
31
|
-
flydata.credentials.authenticate!
|
32
|
-
return true
|
33
|
-
end
|
34
|
-
say("Login failed!")
|
35
|
-
false
|
25
|
+
flydata.post('/users/sign_in', {:user => email, :password =>password})
|
26
|
+
puts 'Thank you for logging in'
|
27
|
+
true
|
36
28
|
end
|
37
29
|
end
|
38
30
|
end
|
@@ -15,26 +15,41 @@ module Flydata
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def run
|
18
|
-
#
|
19
|
-
|
18
|
+
# Check authentication token
|
19
|
+
begin
|
20
|
+
flydata.get('/data_entries')
|
21
|
+
rescue => e
|
22
|
+
if e.respond_to?('response') and e.response.code == 401
|
23
|
+
puts("Error logging in, Please enter login information")
|
24
|
+
Flydata::Command::Login.new.run #Check credentials for every run in case corruption
|
25
|
+
else
|
26
|
+
raise e
|
27
|
+
end
|
28
|
+
end
|
20
29
|
|
21
30
|
# choose entries
|
22
|
-
unless shown = show_registered_entries
|
31
|
+
unless (shown = show_registered_entries)
|
32
|
+
list = build_recommended_entries
|
33
|
+
print_recommended(list)
|
34
|
+
register_all(list) if ask_yes_no("Register all of these common entries?")
|
35
|
+
end
|
36
|
+
unless (shown ||= show_registered_entries) and not more_entry?
|
23
37
|
begin
|
24
38
|
show_registered_entries unless shown
|
25
39
|
shown = false
|
40
|
+
<<<<<<< HEAD
|
26
41
|
path = choose_log_path_from_examples
|
27
42
|
case path
|
28
43
|
when OTHER; ask_log_path
|
29
|
-
else; create_log_entry(path
|
44
|
+
else; create_log_entry(path)
|
30
45
|
end
|
46
|
+
=======
|
47
|
+
choose_log_selection(list)
|
48
|
+
>>>>>>> feature/auto_scan_logs
|
31
49
|
newline
|
32
50
|
end while more_entry?
|
33
51
|
end
|
34
52
|
|
35
|
-
# register cron if registered log deletion
|
36
|
-
register_crontab
|
37
|
-
|
38
53
|
# start client process
|
39
54
|
Flydata::Command::Sender.new.restart
|
40
55
|
end
|
@@ -87,7 +102,62 @@ module Flydata
|
|
87
102
|
end
|
88
103
|
newline
|
89
104
|
end
|
90
|
-
create_log_entry(path
|
105
|
+
create_log_entry(path)
|
106
|
+
<<<<<<< HEAD
|
107
|
+
=======
|
108
|
+
end
|
109
|
+
def build_recommended_entries
|
110
|
+
path_options=[]
|
111
|
+
Dir['/var/log*/**/*log'].each{|f| if (FileTest.file?(f) and
|
112
|
+
FileTest.readable?(f) and
|
113
|
+
( f =~ /apache2|httpd|syslog|mail|auth/)) and
|
114
|
+
!(@last_fetched_entries and @last_fetched_entries.any?{|e| e['log_path'] == f})
|
115
|
+
then path_options << f end}
|
116
|
+
path_options
|
117
|
+
end
|
118
|
+
def print_recommended(list, options=false)
|
119
|
+
newline
|
120
|
+
puts " Recommended list:"
|
121
|
+
list.each_with_index { |value, index|
|
122
|
+
puts " #{index+1}) #{value} "
|
123
|
+
}
|
124
|
+
if options
|
125
|
+
puts(" #{list.length+1}) Enter your own path")
|
126
|
+
end
|
127
|
+
newline
|
128
|
+
end
|
129
|
+
def register_all(list)
|
130
|
+
list.each{ |item|
|
131
|
+
create_log_entry(item)
|
132
|
+
}
|
133
|
+
list.reject!{|x| x}
|
134
|
+
end
|
135
|
+
def choose_log_selection(list)
|
136
|
+
path = nil
|
137
|
+
list = build_recommended_entries unless list
|
138
|
+
path_options = list
|
139
|
+
|
140
|
+
loop do
|
141
|
+
if path_options.empty?
|
142
|
+
ask_log_path
|
143
|
+
return
|
144
|
+
end
|
145
|
+
print_recommended(path_options, true)
|
146
|
+
choice = Readline.readline("Here are some common logs, enter the number next to the logs to add the log. Input nothing to cancel.")
|
147
|
+
return if choice.empty?
|
148
|
+
if choice.to_i==path_options.length+1
|
149
|
+
ask_log_path
|
150
|
+
return
|
151
|
+
elsif (path_options[choice.to_i-1] != nil )
|
152
|
+
path = path_options[choice.to_i-1]
|
153
|
+
path_options.delete_at(choice.to_i-1)
|
154
|
+
break
|
155
|
+
else
|
156
|
+
puts("Not a valid entry, please try again");
|
157
|
+
end
|
158
|
+
end
|
159
|
+
create_log_entry(path)
|
160
|
+
>>>>>>> feature/auto_scan_logs
|
91
161
|
end
|
92
162
|
def ask_log_deletion(path)
|
93
163
|
unless File.writable?(path)
|
@@ -103,13 +173,13 @@ module Flydata
|
|
103
173
|
say("For more details - http://docs.hapyrus.com/faq/how-log-deletion-works/")
|
104
174
|
ask_yes_no("Set auto log deletion mode?")
|
105
175
|
end
|
106
|
-
def create_log_entry(path, log_deletion)
|
176
|
+
def create_log_entry(path, log_deletion=false)
|
107
177
|
data_port = flydata.data_port.get
|
108
178
|
flydata.data_entry.create(data_port_id: data_port['id'], log_path: path, log_deletion: log_deletion)
|
109
|
-
say("Process successfuly!") if flydata.response.code == 200
|
179
|
+
say("Process added successfuly!") if flydata.response.code == 200
|
110
180
|
end
|
111
181
|
def more_entry?
|
112
|
-
ask_yes_no("Do you want to add
|
182
|
+
ask_yes_no("Do you want to add another log path?")
|
113
183
|
end
|
114
184
|
end
|
115
185
|
end
|
data/lib/flydata/credentials.rb
CHANGED
@@ -1,41 +1,34 @@
|
|
1
1
|
module Flydata
|
2
2
|
class Credentials
|
3
3
|
include Helpers
|
4
|
-
attr_reader :
|
5
|
-
def initialize
|
4
|
+
attr_reader :token
|
5
|
+
def initialize
|
6
6
|
read_credentials
|
7
|
-
if user && password
|
8
|
-
@user = user
|
9
|
-
@password = password
|
10
|
-
elsif !(@authenticated)
|
11
|
-
@user = ENV['FLYDATA_LOGIN']
|
12
|
-
@password = ENV['FLYDATA_PASSWORD']
|
13
|
-
end
|
14
7
|
end
|
15
8
|
def authenticate!
|
16
9
|
@authenticated = true
|
17
|
-
write_credentials
|
18
10
|
end
|
19
11
|
def authenticated?
|
20
12
|
@authenticated
|
21
13
|
end
|
22
|
-
def write_credentials
|
14
|
+
def write_credentials(token)
|
23
15
|
dir = File.dirname(credentials_file)
|
24
16
|
FileUtils.mkdir_p(dir)
|
25
17
|
File.delete(credentials_file) if FileTest.exists?(credentials_file)
|
26
18
|
File.open(credentials_file, 'w', 0400) do |out|
|
27
|
-
|
28
|
-
out.puts encode(@password)
|
19
|
+
out.puts token
|
29
20
|
end
|
30
21
|
FileUtils.chmod(0700, dir)
|
22
|
+
@token = token
|
31
23
|
end
|
32
24
|
def read_credentials
|
33
25
|
if FileTest.exist?(credentials_file)
|
34
26
|
File.open(credentials_file, 'r') do |f|
|
35
|
-
@
|
36
|
-
@
|
37
|
-
@authenticated = true if @user and @password
|
27
|
+
@token = f.gets.chomp
|
28
|
+
@authenticated = true if @token
|
38
29
|
end
|
30
|
+
else
|
31
|
+
@token = nil
|
39
32
|
end
|
40
33
|
end
|
41
34
|
private
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flydata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Koichi Fujikawa
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -275,16 +275,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
275
275
|
version: '0'
|
276
276
|
segments:
|
277
277
|
- 0
|
278
|
-
hash:
|
278
|
+
hash: 1831603908793813549
|
279
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
280
280
|
none: false
|
281
281
|
requirements:
|
282
|
-
- - ! '
|
282
|
+
- - ! '>'
|
283
283
|
- !ruby/object:Gem::Version
|
284
|
-
version:
|
284
|
+
version: 1.3.1
|
285
285
|
requirements: []
|
286
286
|
rubyforge_project:
|
287
|
-
rubygems_version: 1.8.
|
287
|
+
rubygems_version: 1.8.24
|
288
288
|
signing_key:
|
289
289
|
specification_version: 3
|
290
290
|
summary: FlyData CLI
|