fastlyctl 1.0.17 → 1.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fastlyctl.rb +1 -3
- data/lib/fastlyctl/commands/login.rb +8 -10
- data/lib/fastlyctl/commands/token.rb +13 -11
- data/lib/fastlyctl/commands/watch.rb +1 -1
- data/lib/fastlyctl/fetcher.rb +23 -65
- data/lib/fastlyctl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6d98fb4345d1cbfc02e52a6ab8565af95f7fb6db2c607ae204ef100735fde6e
|
4
|
+
data.tar.gz: b27abed6021946a60d7adc5473696eae49047813f02424d56ed459c38a9ccd01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c72072eeb95cabce04393ca9c060c00d353d6a94fbcbf2c4e1a2206c9d2c51c0e23af643ab8189d8736d00bb6827c2b98932175f63d92cb184848135b275cc8
|
7
|
+
data.tar.gz: 57560a7c0a4e8c7a73daf08f4d14ba107378eb26c9e70dae9709e900920b460067127df3d1c1767b2bd4c7da36b64937ebfd6528fa6e17bb7d2e3e929dab7ddf
|
data/lib/fastlyctl.rb
CHANGED
@@ -18,13 +18,11 @@ require "fastlyctl/cli"
|
|
18
18
|
include ERB::Util
|
19
19
|
|
20
20
|
module FastlyCTL
|
21
|
-
COOKIE_JAR = ENV['HOME'] + "/.fastlyctl_cookie_jar"
|
22
21
|
TOKEN_FILE = ENV['HOME'] + "/.fastlyctl_token"
|
23
22
|
FASTLY_API = "https://api.fastly.com"
|
24
|
-
|
23
|
+
FASTLY_RT_API = "https://rt.fastly.com"
|
25
24
|
TANGO_PATH = "/configure/services/"
|
26
25
|
|
27
|
-
Cookies = File.exist?(FastlyCTL::COOKIE_JAR) ? JSON.parse(File.read(FastlyCTL::COOKIE_JAR)) : {}
|
28
26
|
# Don't allow header splitting with the key
|
29
27
|
Token = File.exist?(FastlyCTL::TOKEN_FILE) ? File.read(FastlyCTL::TOKEN_FILE) : (ENV['FASTLYCLI_TOKEN'] ? ENV['FASTLYCLI_TOKEN'] : false)
|
30
28
|
end
|
@@ -13,23 +13,21 @@ module FastlyCTL
|
|
13
13
|
|
14
14
|
say("Proceeding with username/password login...")
|
15
15
|
|
16
|
-
|
16
|
+
username = ask("Username: ")
|
17
|
+
password = ask("Password: ", :echo => false)
|
18
|
+
say("")
|
17
19
|
|
18
|
-
|
19
|
-
File.chmod(0600, FastlyCTL::COOKIE_JAR)
|
20
|
-
|
21
|
-
say("Creating root scoped token...")
|
22
|
-
|
23
|
-
if login_results[:user].include?("@fastly.com") && !login_results[:user].include?("+")
|
20
|
+
if username.include?("@fastly.com") && !username.include?("+")
|
24
21
|
scope = "root"
|
25
22
|
else
|
26
23
|
scope = "global"
|
27
24
|
end
|
28
25
|
|
26
|
+
say("Creating #{scope} scope token...")
|
27
|
+
|
29
28
|
o = {
|
30
|
-
|
31
|
-
|
32
|
-
code: login_results[:code],
|
29
|
+
username: username,
|
30
|
+
password: password,
|
33
31
|
scope: scope,
|
34
32
|
name: "fastlyctl_token"
|
35
33
|
}
|
@@ -20,25 +20,27 @@ module FastlyCTL
|
|
20
20
|
scope = options[:scope]
|
21
21
|
scope ||= "global"
|
22
22
|
|
23
|
-
say("You must
|
23
|
+
say("You must authenticate again to create tokens.")
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
username = ask("Username: ")
|
26
|
+
password = ask("Password: ", :echo => false)
|
27
|
+
say("")
|
28
28
|
|
29
|
+
name = ask("What would you like to name your token? (enter here):")
|
29
30
|
o = {
|
30
|
-
|
31
|
-
|
32
|
-
code: login_results[:code],
|
31
|
+
username: username,
|
32
|
+
password: password,
|
33
33
|
scope: scope,
|
34
|
-
name: name
|
35
|
-
}
|
36
|
-
|
37
|
-
o[:services] = options[:services].split(",") if options[:services]
|
34
|
+
name: name || "fastlyctl_token"
|
35
|
+
}.compare_by_identity
|
38
36
|
|
37
|
+
options[:services].split(",").each do |v|
|
38
|
+
o["services[]"] = v
|
39
|
+
end if options[:services]
|
39
40
|
o[:customer] = options[:customer] if options[:customer]
|
40
41
|
|
41
42
|
resp = FastlyCTL::Fetcher.create_token(o)
|
43
|
+
say("token: #{resp["access_token"]}")
|
42
44
|
|
43
45
|
when "delete"
|
44
46
|
id = ask("What is the ID of the token you'd like to delete?")
|
@@ -13,7 +13,7 @@ module FastlyCTL
|
|
13
13
|
pop = pop.upcase if pop
|
14
14
|
|
15
15
|
while true
|
16
|
-
data = FastlyCTL::Fetcher.api_request(:get,"/rt/v1/channel/#{service}/ts/#{ts ? ts : 'h/limit/120'}", :endpoint => :
|
16
|
+
data = FastlyCTL::Fetcher.api_request(:get,"/rt/v1/channel/#{service}/ts/#{ts ? ts : 'h/limit/120'}", :endpoint => :rt)
|
17
17
|
|
18
18
|
unless data["Data"].length > 0
|
19
19
|
say("No data to display!")
|
data/lib/fastlyctl/fetcher.rb
CHANGED
@@ -5,7 +5,7 @@ module FastlyCTL
|
|
5
5
|
options[:params] ||= {}
|
6
6
|
options[:headers] ||= {}
|
7
7
|
options[:body] ||= nil
|
8
|
-
options[:
|
8
|
+
options[:disable_token] ||= false
|
9
9
|
options[:expected_responses] ||= [200]
|
10
10
|
options[:use_vnd] ||= false
|
11
11
|
|
@@ -13,17 +13,11 @@ module FastlyCTL
|
|
13
13
|
|
14
14
|
if options[:endpoint] == :app
|
15
15
|
headers["Referer"] = FastlyCTL::FASTLY_APP
|
16
|
-
headers["X-CSRF-Token"] = FastlyCTL::Cookies["fastly.csrf"] if FastlyCTL::Cookies["fastly.csrf"]
|
17
16
|
headers["Fastly-API-Request"] = "true"
|
18
17
|
end
|
19
18
|
|
20
|
-
if FastlyCTL::Token && !options[:
|
19
|
+
if FastlyCTL::Token && !options[:disable_token]
|
21
20
|
headers["Fastly-Key"] = FastlyCTL::Token
|
22
|
-
else
|
23
|
-
headers["Cookie"] = "" if FastlyCTL::Cookies.length > 0
|
24
|
-
FastlyCTL::Cookies.each do |k,v|
|
25
|
-
headers["Cookie"] << "#{k}=#{v};"
|
26
|
-
end
|
27
21
|
end
|
28
22
|
|
29
23
|
headers["Content-Type"] = "application/x-www-form-urlencoded" if (method == :post || method == :put)
|
@@ -44,7 +38,7 @@ module FastlyCTL
|
|
44
38
|
headers[k] = v.gsub(/\r|\n/,'')
|
45
39
|
end
|
46
40
|
|
47
|
-
url = "#{options[:endpoint] == :api ? FastlyCTL::FASTLY_API : FastlyCTL::
|
41
|
+
url = "#{options[:endpoint] == :api ? FastlyCTL::FASTLY_API : FastlyCTL::FASTLY_RT_API}#{path}"
|
48
42
|
|
49
43
|
response = Typhoeus::Request.new(
|
50
44
|
url,
|
@@ -54,15 +48,7 @@ module FastlyCTL
|
|
54
48
|
body: options[:body]
|
55
49
|
).run
|
56
50
|
|
57
|
-
if options[:expected_responses].include?(response.response_code)
|
58
|
-
if response.headers["Set-Cookie"]
|
59
|
-
response.headers["Set-Cookie"] = [response.headers["Set-Cookie"]] if response.headers["Set-Cookie"].is_a? String
|
60
|
-
response.headers["Set-Cookie"].each do |c|
|
61
|
-
name, value = c.match(/^([^=]*)=([^;]*).*/i).captures
|
62
|
-
FastlyCTL::Cookies[name] = value
|
63
|
-
end
|
64
|
-
end
|
65
|
-
else
|
51
|
+
if !options[:expected_responses].include?(response.response_code)
|
66
52
|
case response.response_code
|
67
53
|
when 400
|
68
54
|
error = "400: Bad API request--something was wrong with the request made by FastlyCTL."
|
@@ -212,61 +198,33 @@ module FastlyCTL
|
|
212
198
|
end
|
213
199
|
end
|
214
200
|
|
215
|
-
def self.login
|
216
|
-
thor = Thor::Shell::Basic.new
|
217
|
-
|
218
|
-
user = thor.ask("Username: ")
|
219
|
-
pass = thor.ask("Password: ", :echo => false)
|
220
|
-
|
221
|
-
resp = FastlyCTL::Fetcher.api_request(:post, "/login", { :endpoint => :app, params: { user: user, password: pass}})
|
222
|
-
|
223
|
-
if resp["needs_two_factor_auth"]
|
224
|
-
two_factor = true
|
225
|
-
|
226
|
-
thor.say("\nTwo factor auth enabled on account, second factor needed.")
|
227
|
-
code = thor.ask('Please enter verification code:', echo: false)
|
228
|
-
|
229
|
-
resp = FastlyCTL::Fetcher.api_request(:post, "/two_factor_auth/verify", {force_session: true, :endpoint => :app, params: { token: code }} )
|
230
|
-
else
|
231
|
-
thor.say("\nTwo factor auth is NOT enabled. You should go do that immediately.")
|
232
|
-
end
|
233
|
-
|
234
|
-
thor.say("Login successful!")
|
235
|
-
|
236
|
-
return { user: user, pass: pass, two_factor: two_factor, code: code }
|
237
|
-
end
|
238
|
-
|
239
201
|
def self.create_token(options)
|
240
202
|
thor = Thor::Shell::Basic.new
|
241
203
|
|
242
204
|
headers = {}
|
243
|
-
|
244
|
-
|
245
|
-
FastlyCTL::Fetcher.api_request(:post, "/sudo", {
|
246
|
-
force_session: true,
|
205
|
+
resp = FastlyCTL::Fetcher.api_request(:post, "/tokens", {
|
206
|
+
disable_token: true,
|
247
207
|
endpoint: :api,
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
},
|
252
|
-
headers: headers
|
208
|
+
body: options,
|
209
|
+
headers: headers,
|
210
|
+
expected_responses: [200,400]
|
253
211
|
})
|
254
212
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
user: options[:user],
|
259
|
-
password: options[:pass]
|
260
|
-
}
|
261
|
-
|
262
|
-
params[:services] = options[:services] if options[:services]
|
213
|
+
if resp.has_key?("msg") && resp["msg"] == "2fa.verify"
|
214
|
+
thor.say("\nTwo factor auth enabled on account, second factor needed.")
|
215
|
+
code = thor.ask('Please enter verification code:', echo: false)
|
263
216
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
217
|
+
headers = {}
|
218
|
+
headers["Fastly-OTP"] = code
|
219
|
+
resp = FastlyCTL::Fetcher.api_request(:post, "/tokens", {
|
220
|
+
disable_token: true,
|
221
|
+
endpoint: :api,
|
222
|
+
body: options,
|
223
|
+
headers: headers
|
224
|
+
})
|
225
|
+
elsif resp.has_key?("msg")
|
226
|
+
abort "ERROR: #{resp}"
|
227
|
+
end
|
270
228
|
|
271
229
|
thor.say("\n#{resp["id"]} created.")
|
272
230
|
|
data/lib/fastlyctl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastlyctl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Basile
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|