Module: BigQuery
- Defined in:
- lib/fastlyctl/commands/logging/bigquery.rb
Class Method Summary collapse
- .create(options) ⇒ Object
- .delete(options) ⇒ Object
- .ensure_opts(required_opts, options) ⇒ Object
- .list(options) ⇒ Object
- .parse_secret_key(file) ⇒ Object
- .print_configs(config) ⇒ Object
- .show(options) ⇒ Object
- .update(options) ⇒ Object
Class Method Details
.create(options) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fastlyctl/commands/logging/bigquery.rb', line 44 def self.create() puts "Creating bigquery log endpoint" required_opts = ["name", "format_file", "user", "secret_key_file", "project_id", "dataset", "table" ] ensure_opts(required_opts,) parsed_key = parse_secret_key([:secret_key_file]) parsed_format = File.read([:format_file]) params = {} id = [:service] version = FastlyCTL::Fetcher.get_writable_version(id) unless [:version] version ||= [:version] params[:name] = [:name] params[:format] = parsed_format params[:format_version] = [:format_version] unless [:format_version].nil? params[:user] = [:user] params[:secret_key] = parsed_key params[:project_id] = [:project_id] params[:dataset] = [:dataset] params[:table] = [:table] params[:template_suffix] = [:template_suffix] unless [:template_suffix].nil? params[:placement] = [:placement] unless [:placement].nil? params[:response_condition] = [:response_condition] unless [:response_condition].nil? FastlyCTL::Fetcher.api_request(:post, "/service/#{id}/version/#{version}/logging/bigquery", body: params) puts "BigQuery logging provider created in service id #{id} on version #{version}" end |
.delete(options) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/fastlyctl/commands/logging/bigquery.rb', line 129 def self.delete() required_opts = ["version","name"] ensure_opts(required_opts,) id = [:service] version = FastlyCTL::Fetcher.get_writable_version(id) unless [:version] version ||= [:version] resp = FastlyCTL::Fetcher.api_request(:delete, "/service/#{id}/version/#{version}/logging/bigquery/#{[:name]}") puts JSON.pretty_generate(resp) end |
.ensure_opts(required_opts, options) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/fastlyctl/commands/logging/bigquery.rb', line 12 def BigQuery.ensure_opts(required_opts,) required_opts.each { |k| if !.key?(k) abort "Error, option #{k.to_s} is required for this action" end } end |
.list(options) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fastlyctl/commands/logging/bigquery.rb', line 107 def self.list() id = [:service] version = FastlyCTL::Fetcher.get_writable_version(id) unless [:version] version ||= [:version] puts "Listing all BigQuery configurations for service #{id} version #{version}" configs = FastlyCTL::Fetcher.api_request(:get, "/service/#{id}/version/#{version}/logging/bigquery") print_configs(configs) end |
.parse_secret_key(file) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/fastlyctl/commands/logging/bigquery.rb', line 3 def BigQuery.parse_secret_key(file) key = File.read(file) if key[0..26] != "-----BEGIN PRIVATE KEY-----" abort "Error, private key file should begin with -----BEGIN PRIVATE KEY-----" end return key end |
.print_configs(config) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fastlyctl/commands/logging/bigquery.rb', line 20 def BigQuery.print_configs(config) max = {} max["name"] = 0 max["dataset"] = 0 max["table"] = 0 max["project_id"] = 0 fields = ["name","dataset","table","project_id"] config.each { |c| fields.each { |f| max[f] = c[f].length > max[f] ? c[f].length : max[f] } } puts puts "Name".ljust(max["name"]) + " | " + "Dataset".ljust(max["dataset"]) + " | " + "Table".ljust(max["table"]) + " | " + "ProjectId".ljust(max["project_id"]) puts "-" * (max["name"] + max["dataset"] + max["table"] + max["project_id"]) config.each { |c| 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"])] } puts end |
.show(options) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/fastlyctl/commands/logging/bigquery.rb', line 118 def self.show() required_opts = ["name"] ensure_opts(required_opts,) id = [:service] version = FastlyCTL::Fetcher.get_writable_version(id) unless [:version] version ||= [:version] resp = FastlyCTL::Fetcher.api_request(:get, "/service/#{id}/version/#{version}/logging/bigquery/#{[:name]}") puts JSON.pretty_generate(resp) end |
.update(options) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fastlyctl/commands/logging/bigquery.rb', line 76 def self.update() required_opts = ["name"] ensure_opts(required_opts,) puts "Updating bigquery log endpoint #{[:name]}" parsed_key = parse_secret_key([:secret_key_file]) unless [:secret_key_file].nil? parsed_format = File.read([:format_file]) unless [:format_file].nil? params = {} id = [:service] version = FastlyCTL::Fetcher.get_writable_version(id) unless [:version] version ||= [:version] params[:name] = [:new_name] unless [:new_name].nil? params[:format] = parsed_format unless [:format_file].nil? params[:format_version] = [:format_version] unless [:format_version].nil? params[:user] = [:user] unless [:user].nil? params[:secret_key] = parsed_key unless [:secret_key_file].nil? params[:project_id] = [:project_id] unless [:project_id].nil? params[:dataset] = [:dataset] unless [:dataset].nil? params[:table] = [:table] unless [:table].nil? params[:template_suffix] = [:template_suffix] unless [:template_suffix].nil? params[:placement] = [:placement] unless [:placement].nil? params[:response_condition] = [:response_condition] unless [:response_condition].nil? FastlyCTL::Fetcher.api_request(:put, "/service/#{id}/version/#{version}/logging/bigquery/#{[:name]}", body: params) puts "BigQuery logging provider update in service id #{id} on version #{version}" end |