fastlyctl 1.0.9 → 1.0.11

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: daf9fcc2f5ea41339d508dd96ddcfe7ddf8f6e16078d382848d9ee23ef99b0cf
4
- data.tar.gz: e8d385f3aa42874caa6ccbd96030d983a71cb6e2b45660a296163d4027120067
3
+ metadata.gz: 9c0c20fe758873efe396f68d050d11c8c3675f352918a2a9a9ba55d4a334879f
4
+ data.tar.gz: 70d29a51e74acffa02ff2a330694cb86d1a6d262cbc95d2967440a0777c61601
5
5
  SHA512:
6
- metadata.gz: 3d89e5730ec02621ff903b8fa295b65381025ee7372fd260487acac10398c0ad00db493454b6c5cb37438fccd403cd09841c3624bc697f2b25d0dfb7265cd715
7
- data.tar.gz: 82a1d997aa0ad5cf4770bbc253e593280aa609a54003e8ad87ff515c7e0889f84a1c56d657b41a9b69bf93c14f467818f2f0e5bd17d948dd6f66f3ecf795b3eb
6
+ metadata.gz: a75044ca703cb25c00b3968f2d8a59936f8bbc54af13b02480ea273b4a85b5da5cdd76bf51c828f2d73e9452c8e3538133471b79c01e3424c0fb35afcdf8df21
7
+ data.tar.gz: 1db8c990dd3cb81fec5e6bb92f6b9b2e0dd8f1a3b03d522c0e573f1fe1617d4ab17c4c006f7a188e43b8d9e38747f6f794e996d17c5b8859e64eba0bf6da5f98
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fastlyctl (1.0.9)
4
+ fastlyctl (1.0.11)
5
5
  diffy (~> 3.2.1)
6
6
  launchy (~> 2.4.3, >= 2.4.3)
7
7
  thor (~> 0.19.4)
@@ -30,4 +30,4 @@ DEPENDENCIES
30
30
  fastlyctl!
31
31
 
32
32
  BUNDLED WITH
33
- 1.17.2
33
+ 1.17.3
data/README.md CHANGED
@@ -199,6 +199,56 @@ Flags:
199
199
  * --s: The service ID to download. Current working directory is assumed.
200
200
  * --v: The version to download. The currently active version is assumed.
201
201
 
202
+ ### logging
203
+
204
+ Manage the realtime logging configuration for a service, as well as checking on the status of the logging endpoints. Logging requires a subcommand of either `status` or the name of a logging provider listed below.
205
+
206
+ ##### status
207
+
208
+ Status returns the current status of your logging configurations in JSON format. Helps in telling you whether or not the logging is working or returning an error.
209
+
210
+ Usage:
211
+ ```
212
+ fastlyctl logging status
213
+ ```
214
+
215
+ Flags:
216
+
217
+ * `--s / --service` Service ID to use
218
+
219
+ ##### BigQuery
220
+
221
+ Usage:
222
+ ```
223
+ fastlyctl logging bigquery ACTION [FLAGS]
224
+ ```
225
+
226
+ Supported ACTIONs are `create`, `update`, `show`, `delete`, `list`
227
+
228
+ Flags:
229
+
230
+ * `--s / --service` Service ID to use (required)
231
+ * `--v / --version` Version of the service to use
232
+ * `--n / --name` Current name of the logging configuration
233
+ * `--nn / --new-name` Used for the update method to rename a configuration
234
+ * `--ff / --format-file` Path to the file containing the JSON Representation of the logline, must match BigQuery schema
235
+ * `--u / --user` Google Cloud Service Account Email
236
+ * `--scf / --secret-key-file` Path to the file that contains the Google Cloud Account secret key
237
+ * `--p / --project-id` Google Cloud Project ID
238
+ * `--d / --dataset` Google BigQuery dataset
239
+ * `--t / --table` Google BigQuery table
240
+ * `--ts / --template-suffix` Google table name suffix
241
+ * `--pl / --placement` Placement of the logging call, can be none or waf_debug. Not required and no default
242
+ * `--r / --response-condition` When to execute, if empty it is always
243
+
244
+
245
+ To print the full list of the options required type the command:
246
+
247
+ ```
248
+ fastlyctl logging bigquery --help
249
+ ```
250
+
251
+
202
252
  ### login
203
253
 
204
254
  Login to the Fastly app and create an API token. This token will be stored in your home directory for the CLI to use for all requests.
data/lib/fastlyctl/cli.rb CHANGED
@@ -15,6 +15,7 @@ require "fastlyctl/commands/domain"
15
15
  require "fastlyctl/commands/snippet"
16
16
  require "fastlyctl/commands/acl"
17
17
  require "fastlyctl/commands/copy"
18
+ require "fastlyctl/commands/logging"
18
19
 
19
20
 
20
21
  module FastlyCTL
@@ -0,0 +1,133 @@
1
+ module BigQuery
2
+
3
+ def BigQuery.parse_secret_key(file)
4
+ key = File.read(file)
5
+ if key[0..26] != "-----BEGIN PRIVATE KEY-----"
6
+ abort "Error, private key file should begin with -----BEGIN PRIVATE KEY-----"
7
+ end
8
+
9
+ return key
10
+ end
11
+
12
+ def BigQuery.ensure_opts(required_opts,options)
13
+ required_opts.each { |k|
14
+ if !options.key?(k)
15
+ abort "Error, option #{k.to_s} is required for this action"
16
+ end
17
+ }
18
+ end
19
+
20
+ def BigQuery.print_configs(config)
21
+ max = {}
22
+ max["name"] = 0
23
+ max["dataset"] = 0
24
+ max["table"] = 0
25
+ max["project_id"] = 0
26
+ fields = ["name","dataset","table","project_id"]
27
+
28
+ config.each { |c|
29
+ fields.each { |f|
30
+ max[f] = c[f].length > max[f] ? c[f].length : max[f]
31
+ }
32
+ }
33
+
34
+ puts
35
+ puts "Name".ljust(max["name"]) + " | " + "Dataset".ljust(max["dataset"]) + " | " + "Table".ljust(max["table"]) + " | " + "ProjectId".ljust(max["project_id"])
36
+ puts "-" * (max["name"] + max["dataset"] + max["table"] + max["project_id"])
37
+ config.each { |c|
38
+ puts "%s | %s | %s | %s" % [c["name"].ljust(max["name"]), c["dataset"].ljust(max["dataset"]), c["table"].ljust(max["table"]), c["project_id"].ljust(max["project_id"])]
39
+ }
40
+ puts
41
+ end
42
+
43
+
44
+ def self.create(options)
45
+ puts "Creating bigquery log endpoint"
46
+ required_opts = ["name", "format_file", "user", "secret_key_file", "project_id", "dataset", "table" ]
47
+
48
+ ensure_opts(required_opts,options)
49
+
50
+ parsed_key = parse_secret_key(options[:secret_key_file])
51
+
52
+ parsed_format = File.read(options[:format_file])
53
+
54
+ params = {}
55
+
56
+ id = options[:service]
57
+ version = FastlyCTL::Fetcher.get_writable_version(id) unless options[:version]
58
+ version ||= options[:version]
59
+
60
+ params[:name] = options[:name]
61
+ params[:format] = parsed_format
62
+ params[:user] = options[:user]
63
+ params[:secret_key] = parsed_key
64
+ params[:project_id] = options[:project_id]
65
+ params[:dataset] = options[:dataset]
66
+ params[:table] = options[:table]
67
+
68
+ FastlyCTL::Fetcher.api_request(:post, "/service/#{id}/version/#{version}/logging/bigquery", body: params)
69
+ puts "BigQuery logging provider created in service id #{id} on version #{version}"
70
+ end
71
+
72
+ def self.update(options)
73
+ required_opts = ["name"]
74
+ ensure_opts(required_opts,options)
75
+
76
+ puts "Updating bigquery log endpoint #{options[:name]}"
77
+
78
+ parsed_key = parse_secret_key(options[:secret_key_file]) unless options[:secret_key_file].nil?
79
+ parsed_format = File.read(options[:format_file]) unless options[:format_file].nil?
80
+
81
+ params = {}
82
+
83
+ id = options[:service]
84
+ version = FastlyCTL::Fetcher.get_writable_version(id) unless options[:version]
85
+ version ||= options[:version]
86
+
87
+ params[:name] = options[:new_name] unless options[:new_name].nil?
88
+ params[:format] = parsed_format unless options[:format_file].nil?
89
+ params[:user] = options[:user] unless options[:user].nil?
90
+ params[:secret_key] = parsed_key unless options[:secret_key_file].nil?
91
+ params[:project_id] = options[:project_id] unless options[:project_id].nil?
92
+ params[:dataset] = options[:dataset] unless options[:dataset].nil?
93
+ params[:table] = options[:table] unless options[:table].nil?
94
+
95
+ FastlyCTL::Fetcher.api_request(:put, "/service/#{id}/version/#{version}/logging/bigquery/#{options[:name]}", body: params)
96
+ puts "BigQuery logging provider update in service id #{id} on version #{version}"
97
+ end
98
+
99
+ def self.list(options)
100
+ id = options[:service]
101
+ version = FastlyCTL::Fetcher.get_writable_version(id) unless options[:version]
102
+ version ||= options[:version]
103
+
104
+ puts "Listing all BigQuery configurations for service #{id} version #{version}"
105
+
106
+ configs = FastlyCTL::Fetcher.api_request(:get, "/service/#{id}/version/#{version}/logging/bigquery")
107
+ print_configs(configs)
108
+ end
109
+
110
+ def self.show(options)
111
+ required_opts = ["name"]
112
+ ensure_opts(required_opts,options)
113
+ id = options[:service]
114
+ version = FastlyCTL::Fetcher.get_writable_version(id) unless options[:version]
115
+ version ||= options[:version]
116
+
117
+ resp = FastlyCTL::Fetcher.api_request(:get, "/service/#{id}/version/#{version}/logging/bigquery/#{options[:name]}")
118
+ puts JSON.pretty_generate(resp)
119
+ end
120
+
121
+ def self.delete(options)
122
+ required_opts = ["version","name"]
123
+ ensure_opts(required_opts,options)
124
+
125
+ id = options[:service]
126
+ version = FastlyCTL::Fetcher.get_writable_version(id) unless options[:version]
127
+ version ||= options[:version]
128
+
129
+ resp = FastlyCTL::Fetcher.api_request(:delete, "/service/#{id}/version/#{version}/logging/bigquery/#{options[:name]}")
130
+ puts JSON.pretty_generate(resp)
131
+ end
132
+
133
+ end
@@ -0,0 +1,72 @@
1
+ require "fastlyctl/commands/logging/bigquery"
2
+
3
+ module FastlyCTL
4
+ class LoggingSubCmd < Thor
5
+ namespace :logging
6
+
7
+ # bit of a monkey patch to fix --help output
8
+ def self.banner(command, namespace = nil, subcommand = false)
9
+ "#{basename} logging #{command.usage}"
10
+ end
11
+
12
+ desc "bigquery <action>", "Setup BigQuery As a logging provider, available actions are create, update, delete, list and show"
13
+ method_option :service, :aliases => ["--s","--service"], :banner => "Service ID to use", :required => true
14
+ method_option :version, :aliases => ["--v", "--version"], :banner => "Version of the service to use"
15
+ method_option :name, :aliases => ["--n", "--name"], :banner => "Current name of the logging configuration"
16
+ method_option :new_name, :aliases => ["--nn","--new-name"], :banner => "Used for the update method to rename a configuration"
17
+ method_option :format_file, :aliases => ["--ff","--format-file"], :banner => "File containing the JSON Representation of the logline, must match BigQuery schema"
18
+ method_option :format_version, :aliases => ["--fv","--format-version"], :banner => "Version of customer format, either 1 or 2, defaults to 2"
19
+ method_option :user, :aliases => ["--u","--user"], :banner => "Google Cloud Service Account Email"
20
+ method_option :secret_key_file, :aliases => ["--scf", "--secret-key-file"],:banner => "File that contains the Google Cloud Account secret key"
21
+ method_option :project_id, :aliases => ["--p","--project-id"], :banner => "Google Cloud Project ID"
22
+ method_option :dataset, :aliases => ["--d","--dataset"], :banner => "BigQuery Dataset"
23
+ method_option :table, :aliases => ["--t","--table"], :banner => "BigQuery Table"
24
+ method_option :template_suffix, :aliases => ["--ts","--template-suffix"], :banner => "Optional table name suffix"
25
+ method_option :placement, :aliases => ["--pl","--placement"], :banner => "Placement of the logging call, can be none or waf_debug. Not required and no default"
26
+ method_option :response_condition, :aliases => ["--r","--response-condition"], :banner => "When to execute, if empty it is always"
27
+
28
+ def bigquery(action)
29
+ case action
30
+ when "create"
31
+ BigQuery.create(options)
32
+ when "list"
33
+ BigQuery.list(options)
34
+ when "update"
35
+ BigQuery.update(options)
36
+ when "show"
37
+ BigQuery.show(options)
38
+ when "delete"
39
+ BigQuery.delete(options)
40
+ else
41
+ abort "Sorry, invalid action #{action} supplied, only create, update, delete and show are valid."
42
+ end
43
+
44
+ end
45
+
46
+ # Placeholder for future S3 work
47
+ # desc "s3 <action>", "Setup S3 as a logging provider"
48
+ # method_option :format, :required => true
49
+ # method_option :keyfile, :required => true
50
+ # method_option :email , :required => true
51
+
52
+ # def s3(action)
53
+ # puts "S3: #{action}"
54
+ # end
55
+
56
+ desc "status", "Check the last output of the logging status"
57
+ method_option :service, :aliases => ["--s","--service"], :banner => "Service ID to use", :required => true
58
+
59
+ def status
60
+ id = options[:service]
61
+ resp = FastlyCTL::Fetcher.api_request(:get, "/service/#{id}/logging_status")
62
+ say(JSON.pretty_generate(resp))
63
+ end
64
+
65
+ end
66
+
67
+ class CLI < Thor
68
+ desc "logging SUBCOMMAND ...ARGS", "Interface with Fastly Logging"
69
+ subcommand "logging", LoggingSubCmd
70
+ end
71
+
72
+ end
@@ -1,3 +1,3 @@
1
1
  module FastlyCTL
2
- VERSION = "1.0.9"
2
+ VERSION = "1.0.11"
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.9
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Basile
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-19 00:00:00.000000000 Z
11
+ date: 2019-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -103,6 +103,8 @@ files:
103
103
  - lib/fastlyctl/commands/diff.rb
104
104
  - lib/fastlyctl/commands/domain.rb
105
105
  - lib/fastlyctl/commands/download.rb
106
+ - lib/fastlyctl/commands/logging.rb
107
+ - lib/fastlyctl/commands/logging/bigquery.rb
106
108
  - lib/fastlyctl/commands/login.rb
107
109
  - lib/fastlyctl/commands/open.rb
108
110
  - lib/fastlyctl/commands/purge_all.rb