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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 967a62f4948a70f5509ebd3909af631fddd0be60bf93a90998c4e1887c18b8d2
4
- data.tar.gz: 5b0e01256cf4f8030cf92431bcbcfb835f6b7ada479db2e79c7068c3005043b8
3
+ metadata.gz: d6d98fb4345d1cbfc02e52a6ab8565af95f7fb6db2c607ae204ef100735fde6e
4
+ data.tar.gz: b27abed6021946a60d7adc5473696eae49047813f02424d56ed459c38a9ccd01
5
5
  SHA512:
6
- metadata.gz: 71d9fc500521e22f6c1e5e1a9193c90016b4f94d11b3963496e011d08f689dacc07b7b2db01cebac7d3a18747365fa285a8b73f3c8912b07efaca80e85c50dcb
7
- data.tar.gz: b8cab659f08e68f46b83fe43d8090aaa83b7645257c715cd8b5012a6106e729ccc213adc9f1fba5f2eb8a7dfc23675eef6eea64d3f65ce086c500ff9bfe9916d
6
+ metadata.gz: 0c72072eeb95cabce04393ca9c060c00d353d6a94fbcbf2c4e1a2206c9d2c51c0e23af643ab8189d8736d00bb6827c2b98932175f63d92cb184848135b275cc8
7
+ data.tar.gz: 57560a7c0a4e8c7a73daf08f4d14ba107378eb26c9e70dae9709e900920b460067127df3d1c1767b2bd4c7da36b64937ebfd6528fa6e17bb7d2e3e929dab7ddf
@@ -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
- FASTLY_APP = "https://manage.fastly.com"
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
- login_results = FastlyCTL::Fetcher.login
16
+ username = ask("Username: ")
17
+ password = ask("Password: ", :echo => false)
18
+ say("")
17
19
 
18
- File.open(FastlyCTL::COOKIE_JAR , 'w+') {|f| f.write(JSON.dump(FastlyCTL::Cookies)) }
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
- user: login_results[:user],
31
- pass: login_results[:pass],
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 login again to create tokens.")
23
+ say("You must authenticate again to create tokens.")
24
24
 
25
- login_results = FastlyCTL::Fetcher.login
26
-
27
- name = ask("What would you like to name your token?")
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
- user: login_results[:user],
31
- pass: login_results[:pass],
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 => :app)
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!")
@@ -5,7 +5,7 @@ module FastlyCTL
5
5
  options[:params] ||= {}
6
6
  options[:headers] ||= {}
7
7
  options[:body] ||= nil
8
- options[:force_session] ||= false
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[:force_session]
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::FASTLY_APP}#{path}"
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
- headers["Fastly-OTP"] = options[:code] if options[:code]
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
- params: {
249
- user: options[:user],
250
- password: options[:pass]
251
- },
252
- headers: headers
208
+ body: options,
209
+ headers: headers,
210
+ expected_responses: [200,400]
253
211
  })
254
212
 
255
- params = {
256
- name: options[:name],
257
- scope: options[:scope],
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
- resp = FastlyCTL::Fetcher.api_request(:post, "/tokens", {
265
- force_session: true,
266
- endpoint: :api,
267
- params: params,
268
- headers: headers
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
 
@@ -1,3 +1,3 @@
1
1
  module FastlyCTL
2
- VERSION = "1.0.17"
2
+ VERSION = "1.0.18"
3
3
  end
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.17
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-03-30 00:00:00.000000000 Z
11
+ date: 2020-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus