repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/model/import.rb
lib/gzr/commands/model/import.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/model' require_relative '../../modules/filehelper' module Gzr module Commands class Model class Import < Gzr::Command include Gzr::Model include Gzr::FileHelper def initialize(file, options) super() @file = file @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do read_file(@file) do |data| if !!cat_model(data[:name]) name = data[:name] if !@options[:force] raise Gzr::CLI::Error, "Model #{name} already exists\nUse --force if you want to overwrite it" end data.select! do |k,v| keys_to_keep('update_lookml_model').include? k end model = update_model(data[:name],data) output.puts "Updated model #{model[:name]}" unless @options[:plain] output.puts model[:name] if @options[:plain] else data.select! do |k,v| keys_to_keep('create_lookml_model').include? k end model = create_model(data) output.puts "Created model #{model[:name]}" unless @options[:plain] output.puts model[:name] if @options[:plain] end end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/model/cat.rb
lib/gzr/commands/model/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/model' require_relative '../../modules/filehelper' module Gzr module Commands class Model class Cat < Gzr::Command include Gzr::Model include Gzr::FileHelper def initialize(model_name,options) super() @model_name = model_name @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = cat_model(@model_name) if data.nil? say_warning "Model #{@model_name} not found" return end data = trim_model(data) if @options[:trim] write_file(@options[:dir] ? "Model_#{data[:name]}.json" : nil, @options[:dir],nil, output) do |f| f.puts JSON.pretty_generate(data) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/model/set/ls.rb
lib/gzr/commands/model/set/ls.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../command' require_relative '../../../modules/model/set' require 'tty-table' module Gzr module Commands class Model class Set class Ls < Gzr::Command include Gzr::Model::Set def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = all_model_sets(@options[:fields]) begin say_ok "No model sets found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, multiline: true, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/model/set/rm.rb
lib/gzr/commands/model/set/rm.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../command' require_relative '../../../modules/model/set' module Gzr module Commands class Model class Set class Delete < Gzr::Command include Gzr::Model::Set def initialize(model_set_id,options) super() @model_set_id = model_set_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do delete_model_set(@model_set_id) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/model/set/import.rb
lib/gzr/commands/model/set/import.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../../gzr' require_relative '../../../command' require_relative '../../../modules/model/set' require_relative '../../../modules/filehelper' module Gzr module Commands class Model class Set class Import < Gzr::Command include Gzr::Model::Set include Gzr::FileHelper def initialize(file, options) super() @file = file @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do model_set = nil read_file(@file) do |data| search_results = search_model_sets(name: data[:name]) if search_results && search_results.length == 1 name = data[:name] if !@options[:force] raise Gzr::CLI::Error, "Model Set #{name} already exists\nUse --force if you want to overwrite it" end data.select! do |k,v| keys_to_keep('update_model_set').include? k end model_set = update_model_set(search_results.first[:id], data) else data.select! do |k,v| keys_to_keep('create_model_set').include? k end model_set = create_model_set(data) end output.puts "Imported model set #{model_set[:id]}" unless @options[:plain] output.puts model_set[:id] if @options[:name] end end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/model/set/cat.rb
lib/gzr/commands/model/set/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../command' require_relative '../../../modules/model/set' require_relative '../../../modules/filehelper' module Gzr module Commands class Model class Set class Cat < Gzr::Command include Gzr::Model::Set include Gzr::FileHelper def initialize(model_set_id,options) super() @model_set_id = model_set_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = cat_model_set(@model_set_id) if data.nil? say_warning "Model Set #{@model_set_id} not found" return end data = trim_model_set(data) if @options[:trim] write_file(@options[:dir] ? "Model_Set_#{data[:name]}.json" : nil, @options[:dir],nil, output) do |f| f.puts JSON.pretty_generate(data) end end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/plan/randomize.rb
lib/gzr/commands/plan/randomize.rb
# The MIT License (MIT) # Copyright (c) 2024 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/plan' require_relative '../../modules/user' require_relative '../../modules/cron' module Gzr module Commands class Plan class Randomize < Gzr::Command include Gzr::Plan include Gzr::User include Gzr::Cron def initialize(plan_id,options) super() @plan_id = plan_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] window = @options[:window] if window < 1 or window > 60 say_error("window must be between 1 and 60") raise Gzr::CLI::Error.new() end with_session do @me ||= query_me("id") if @plan_id plan = query_scheduled_plan(@plan_id) if plan randomize_plan(plan,window) else say_warning("Plan #{@plan_id} not found") end else plans = query_all_scheduled_plans( @options[:all]?'all':@me[:id] ) plans.each do |plan| randomize_plan(plan,window) end end end end def randomize_plan(plan,window=60) crontab = plan[:crontab] if crontab == "" say_warning("skipping plan #{plan[:id]} with no crontab") return end crontab = randomize_cron(crontab, window) begin update_scheduled_plan(plan[:id], { crontab: crontab }) rescue LookerSDK::UnprocessableEntity => e say_warning("Skipping invalid entry") end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/plan/enable.rb
lib/gzr/commands/plan/enable.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/plan' module Gzr module Commands class Plan class Enable < Gzr::Command include Gzr::Plan def initialize(plan_id,options) super() @plan_id = plan_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do plan = update_scheduled_plan(@plan_id, { :enabled=>true }) output.puts "Enabled plan #{plan[:id]}" unless @options[:plain] output.puts plan[:id] if @options[:plain] end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/plan/disable.rb
lib/gzr/commands/plan/disable.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/plan' module Gzr module Commands class Plan class Disable < Gzr::Command include Gzr::Plan def initialize(plan_id,options) super() @plan_id = plan_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do plan = update_scheduled_plan(@plan_id, { :enabled=>false }) output.puts "Disabled plan #{plan[:id]}" unless @options[:plain] output.puts plan[:id] if @options[:plain] end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/plan/ls.rb
lib/gzr/commands/plan/ls.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/plan' require 'tty-table' module Gzr module Commands class Plan class Ls < Gzr::Command include Gzr::Plan def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do fields = nil expressions = nil if @options[:disabled] then query = { :model=>"i__looker", :view=>"scheduled_plan", :fields=>[ "scheduled_plan.id", "scheduled_plan.enabled", "scheduled_plan.name", "user.id", "user.name", "scheduled_plan.look_id", "scheduled_plan.dashboard_id", "scheduled_plan.lookml_dashboard_id" ], :filters=>{ "scheduled_plan.enabled"=>"false" }, :sorts=>[ "scheduled_plan.id asc 0" ], :limit=>"500" } data = run_inline_query(query) fields = query[:fields] else data = query_all_scheduled_plans("all",@options[:fields]) fields = field_names(@options[:fields]) end begin say_ok "No plans found" return nil end unless data && data.length > 0 table_hash = Hash.new table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| if @options[:disabled] then fields.collect do |f| row.fetch(f.to_sym, nil) end else field_expressions_eval(fields,row) end end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| next :left if k == "external_group_id" (k =~ /(id|count)$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/plan/failures.rb
lib/gzr/commands/plan/failures.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/plan' require 'tty-table' module Gzr module Commands class Plan class Failures < Gzr::Command include Gzr::Plan def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do query = { :model=>"i__looker", :view=>"scheduled_plan", :fields=>[ "scheduled_plan.id", "scheduled_plan.name", "user.id", "user.name", "scheduled_job.status", "scheduled_job.id", "scheduled_job.created_time", "scheduled_plan.next_run_time", "scheduled_plan.look_id", "scheduled_plan.dashboard_id", "scheduled_plan.lookml_dashboard_id" ], :filters=>{ "scheduled_job_stage.stage": "execute", "scheduled_job.created_time": "1 months", "scheduled_plan.run_once": "no" }, :sorts=>[ "scheduled_plan.id", "scheduled_job.created_time desc" ], :limit=>"5000" } data = run_inline_query(query) fields = query[:fields] begin say_ok "No plans found in history" return nil end unless data && data.length > 0 table_hash = Hash.new table_hash[:header] = fields unless @options[:plain] prior_plan_id = nil table_hash[:rows] = data.collect do |row| next if row[:'scheduled_plan.id'] == prior_plan_id prior_plan_id = row[:'scheduled_plan.id'] next if row[:'scheduled_job.status'] == 'success' fields.collect do |f| row.fetch(f.to_sym, nil) end end.compact table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /(id|count)$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/plan/rm.rb
lib/gzr/commands/plan/rm.rb
# The MIT License (MIT) # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/plan' module Gzr module Commands class Plan class Rm < Gzr::Command include Gzr::Plan def initialize(plan_id, options) super() @plan_id = plan_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do delete_scheduled_plan(@plan_id) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/plan/import.rb
lib/gzr/commands/plan/import.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/plan' require_relative '../../modules/user' require_relative '../../modules/filehelper' module Gzr module Commands class Plan class Import < Gzr::Command include Gzr::Plan include Gzr::User include Gzr::FileHelper def initialize(plan_file, obj_type, obj_id, options) super() @plan_file = plan_file @obj_type = obj_type @obj_id = obj_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do @me ||= query_me("id") read_file(@plan_file) do |data| plan = nil case @obj_type when /dashboard/i plan = upsert_plan_for_dashboard(@obj_id,@me[:id],data) when /look/i plan = upsert_plan_for_look(@obj_id,@me[:id],data) else raise Gzr::CLI::Error, "Invalid type '#{obj_type}', valid types are look and dashboard" end output.puts "Imported plan #{plan[:id]}" unless @options[:plain] output.puts plan[:id] if @options[:plain] end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/plan/run.rb
lib/gzr/commands/plan/run.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/plan' module Gzr module Commands class Plan class RunIt < Gzr::Command include Gzr::Plan def initialize(plan_id,options) super() @plan_id = plan_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do plan = query_scheduled_plan(@plan_id) # The api call scheduled_plan_run_once is an odd duck. It accepts # the output of any of the calls to retrieve a scheduled plan # even though many of the attributes passed are marked read-only. # Furthermore, if there is a "secret" - like the password for # sftp or s3 - it will match the plan body up with the plan # as known in the server and if they are identical apart from # the secret, the api will effectively include to secret in order # execute the plan. plan.delete(:id) run_scheduled_plan(plan) output.puts "Executed plan #{@plan_id}" unless @options[:plain] end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/plan/cat.rb
lib/gzr/commands/plan/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/plan' require_relative '../../modules/filehelper' module Gzr module Commands class Plan class Cat < Gzr::Command include Gzr::Plan include Gzr::FileHelper def initialize(plan_id,options) super() @plan_id = plan_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do data = query_scheduled_plan(@plan_id) write_file(@options[:dir] ? "Plan_#{data[:id]}_#{data[:name]}.json" : nil, @options[:dir], nil, output) do |f| f.puts JSON.pretty_generate(data) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/connection/test.rb
lib/gzr/commands/connection/test.rb
# The MIT License (MIT) # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/connection' require 'tty-table' module Gzr module Commands class Connection class Test < Gzr::Command include Gzr::Connection def initialize(connection_name,options) super() @connection_name = connection_name @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = test_connection(@connection_name) table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, multiline: if @options[:plain] then false else true end, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/connection/ls.rb
lib/gzr/commands/connection/ls.rb
# The MIT License (MIT) # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/connection' require 'tty-table' module Gzr module Commands class Connection class Ls < Gzr::Command include Gzr::Connection def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = query_all_connections(@options[:fields]) begin say_ok "No connections found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/connection/dialects.rb
lib/gzr/commands/connection/dialects.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/connection' require 'tty-table' module Gzr module Commands class Connection class Dialects < Gzr::Command include Gzr::Connection def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = query_all_dialects(@options[:fields]) begin say_ok "No dialects found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = data[0].keys unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/connection/rm.rb
lib/gzr/commands/connection/rm.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require 'json' require_relative '../../command' require_relative '../../modules/connection' require_relative '../../modules/filehelper' module Gzr module Commands class Connection class Rm < Gzr::Command include Gzr::Connection include Gzr::FileHelper def initialize(connection_name,options) super() @connection_name = connection_name @options = options end def execute(*args, input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do delete_connection(@connection_name) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/connection/import.rb
lib/gzr/commands/connection/import.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/connection' require_relative '../../modules/filehelper' module Gzr module Commands class Connection class Import < Gzr::Command include Gzr::Connection include Gzr::FileHelper def initialize(file, options) super() @file = file @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do connection = nil if @options[:prompt] reader = TTY::Reader.new @secret = reader.read_line("Enter your connection password:", echo: false) @secret.chomp! end read_file(@file) do |data| if !!cat_connection(data[:name]) name = data[:name] if !@options[:force] raise Gzr::CLI::Error, "Connection #{name} already exists\nUse --force if you want to overwrite it" end data.select! do |k,v| keys_to_keep('update_connection').include? k end data[:password] = @secret if @secret connection = update_connection(name, data) else data.select! do |k,v| keys_to_keep('create_connection').include? k end data[:password] = @secret if @secret connection = create_connection(data) end output.puts "Imported connection #{connection[:name]}" unless @options[:plain] output.puts connection[:id] if @options[:name] end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/connection/cat.rb
lib/gzr/commands/connection/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require 'json' require_relative '../../command' require_relative '../../modules/connection' require_relative '../../modules/filehelper' module Gzr module Commands class Connection class Cat < Gzr::Command include Gzr::Connection include Gzr::FileHelper def initialize(connection_id,options) super() @connection_id = connection_id @options = options end def execute(*args, input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do data = cat_connection(@connection_id) if data.nil? say_warning "Connection #{@connection_id} not found" return end data = trim_connection(data) if @options[:trim] outputJSON = JSON.pretty_generate(data) file_name = if @options[:dir] @options[:simple_filename] ? "Connection_#{data[:name]}.json" : "Connection_#{data[:name]}_#{data[:dialect_name]}.json" else nil end write_file(file_name, @options[:dir], nil, output) do |f| f.puts outputJSON end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/project/update.rb
lib/gzr/commands/project/update.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/project' require_relative '../../modules/filehelper' module Gzr module Commands class Project class Update < Gzr::Command include Gzr::Project include Gzr::FileHelper def initialize(id,file, options) super() @id = id @file = file @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do if get_auth()[:workspace_id] == 'production' say_warning %Q( This command only works in dev mode. Use persistent sessions and change to dev mode before running this command. $ gzr session login --host looker.example.com $ gzr session update dev --token_file --host looker.example.com $ # run the command requiring dev mode here with the --token_file switch $ gzr session logout --token_file --host looker.example.com ) end read_file(@file) do |data| data.select! do |k,v| keys_to_keep('update_project').include? k end project = update_project(@id, data) output.puts "Updated project #{project[:id]}" unless @options[:plain] output.puts project[:id] if @options[:plain] end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/project/checkout.rb
lib/gzr/commands/project/checkout.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/project' module Gzr module Commands class Project class Checkout < Gzr::Command include Gzr::Project def initialize(project_id,name,options) super() @project_id = project_id @name = name @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do if get_auth()[:workspace_id] == 'production' say_warning %Q( This command only works in dev mode. Use persistent sessions and change to dev mode before running this command. $ gzr session login --host looker.example.com $ gzr session update dev --token_file --host looker.example.com $ # run the command requiring dev mode here with the --token_file switch $ gzr session logout --token_file --host looker.example.com ) return end data = update_git_branch(@project_id, @name ) if data.nil? say_warning "Project #{@project_id} not found" return end output.puts data end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/project/ls.rb
lib/gzr/commands/project/ls.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/project' require 'tty-table' module Gzr module Commands class Project class Ls < Gzr::Command include Gzr::Project def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do say_warning "querying all_projects({ fields: '#{@options[:fields]}' })" if @options[:debug] data = all_projects(fields: @options[:fields]) begin say_ok "No projects found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/project/deploy_key.rb
lib/gzr/commands/project/deploy_key.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/project' module Gzr module Commands class Project class DeployKey < Gzr::Command include Gzr::Project def initialize(id,options) super() @id = id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do if get_auth()[:workspace_id] == 'production' say_warning %Q( This command only works in dev mode. Use persistent sessions and change to dev mode before running this command. $ gzr session login --host looker.example.com $ gzr session update dev --token_file --host looker.example.com $ # run the command requiring dev mode here with the --token_file switch $ gzr session logout --token_file --host looker.example.com ) end key = git_deploy_key(@id) || create_git_deploy_key(@id) output.puts key end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/project/deploy.rb
lib/gzr/commands/project/deploy.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/project' module Gzr module Commands class Project class Deploy < Gzr::Command include Gzr::Project def initialize(project_id,options) super() @project_id = project_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do if get_auth()[:workspace_id] == 'production' say_warning %Q( This command only works in dev mode. Use persistent sessions and change to dev mode before running this command. $ gzr session login --host looker.example.com $ gzr session update dev --token_file --host looker.example.com $ # run the command requiring dev mode here with the --token_file switch $ gzr session logout --token_file --host looker.example.com ) return end data = deploy_to_production(@project_id) if data.nil? say_warning "Project #{@project_id} not found" return end output.puts data end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/project/import.rb
lib/gzr/commands/project/import.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/project' require_relative '../../modules/filehelper' module Gzr module Commands class Project class Import < Gzr::Command include Gzr::Project include Gzr::FileHelper def initialize(file, options) super() @file = file @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do if get_auth()[:workspace_id] == 'production' say_warning %Q( This command only works in dev mode. Use persistent sessions and change to dev mode before running this command. $ gzr session login --host looker.example.com $ gzr session update dev --token_file --host looker.example.com $ # run the command requiring dev mode here with the --token_file switch $ gzr session logout --token_file --host looker.example.com ) end read_file(@file) do |data| data.select! do |k,v| (keys_to_keep('create_project') - [:git_remote_url]).include? k end project = create_project(data) output.puts "Created project #{project[:id]}" unless @options[:plain] output.puts project[:id] if @options[:plain] end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/project/branch.rb
lib/gzr/commands/project/branch.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/project' require 'tty-table' module Gzr module Commands class Project class Branch < Gzr::Command include Gzr::Project def initialize(project_id,options) super() @project_id = project_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do if get_auth()[:workspace_id] == 'production' say_warning %Q( This command only works in dev mode. Use persistent sessions and change to dev mode before running this command. $ gzr session login --host looker.example.com $ gzr session update dev --token_file --host looker.example.com $ # run the command requiring dev mode here with the --token_file switch $ gzr session logout --token_file --host looker.example.com ) return end say_warning "querying git_branch(#{@project_id})" if @options[:debug] data = [git_branch(@project_id)] begin say_ok "No active branch found" return nil end unless data && data.length > 0 if @options[:all] say_warning "querying all_git_branches(#{@project_id})" if @options[:debug] data += all_git_branches(@project_id).select{ |e| e[:name] != data[0][:name] } end begin say_ok "No branches found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/project/cat.rb
lib/gzr/commands/project/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/project' require_relative '../../modules/filehelper' module Gzr module Commands class Project class Cat < Gzr::Command include Gzr::Project include Gzr::FileHelper def initialize(project_id,options) super() @project_id = project_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = cat_project(@project_id) if data.nil? say_warning "Project #{@project_id} not found" return end data = trim_project(data) if @options[:trim] write_file(@options[:dir] ? "Project_#{data[:id]}.json" : nil, @options[:dir],nil, output) do |f| f.puts JSON.pretty_generate(data) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/group/ls.rb
lib/gzr/commands/group/ls.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/group' require 'tty-table' module Gzr module Commands class Group class Ls < Gzr::Command include Gzr::Group def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = query_all_groups(@options[:fields], "id") begin say_ok "No groups found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| next :left if k == "external_group_id" (k =~ /(id|count)$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/group/member_groups.rb
lib/gzr/commands/group/member_groups.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/group' require 'tty-table' module Gzr module Commands class Group class MemberGroups < Gzr::Command include Gzr::Group def initialize(group_id,options) super() @group_id = group_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = query_group_groups(@group_id,@options[:fields]) begin say_ok "No groups found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| next :left if k == "external_group_id" (k =~ /(id|count)$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/group/member_users.rb
lib/gzr/commands/group/member_users.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/group' require 'tty-table' module Gzr module Commands class Group class MemberUsers < Gzr::Command include Gzr::Group def initialize(group_id,options) super() @group_id = group_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = query_group_users(@group_id,@options[:fields],"id") begin say_ok "No users found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| next :left if k == "external_group_id" (k =~ /(id|count)$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/randomize.rb
lib/gzr/commands/alert/randomize.rb
# The MIT License (MIT) # Copyright (c) 2024 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' require_relative '../../modules/user' require_relative '../../modules/cron' module Gzr module Commands class Alert class Randomize < Gzr::Command include Gzr::Alert include Gzr::User include Gzr::Cron def initialize(alert_id,options) super() @alert_id = alert_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] window = @options[:window] if window < 1 or window > 60 say_error("window must be between 1 and 60") raise Gzr::CLI::Error.new() end with_session do @me ||= query_me("id") if @alert_id alert = get_alert(@alert_id) if alert randomize_alert(alert,window) else say_warning("Alert #{@alert_id} not found") end else req = {} req[:disabled] = false req[:all_owners] = @options[:all] unless @options[:all].nil? alerts = search_alerts(**req) begin say_ok "No alerts found" return nil end unless alerts && alerts.length > 0 alerts.each do |alert| randomize_alert(alert,window) end end end end def randomize_alert(alert,window=60) crontab = alert[:cron] if crontab == "" say_warning("skipping alert #{alert[:id]} with no cron") return end crontab = randomize_cron(crontab, window) begin alert[:cron] = crontab update_alert(alert[:id], alert) rescue LookerSDK::UnprocessableEntity => e say_warning("Skipping invalid entry") end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/enable.rb
lib/gzr/commands/alert/enable.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' module Gzr module Commands class Alert class Enable < Gzr::Command include Gzr::Alert def initialize(alert_id,options) super() @alert_id = alert_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do update_alert_field(@alert_id, is_disabled: false) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/disable.rb
lib/gzr/commands/alert/disable.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' module Gzr module Commands class Alert class Disable < Gzr::Command include Gzr::Alert def initialize(alert_id, disabled_reason, options) super() @alert_id = alert_id @disabled_reason = disabled_reason @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do update_alert_field(@alert_id, is_disabled: true, disabled_reason: @disabled_reason) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/delete.rb
lib/gzr/commands/alert/delete.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' module Gzr module Commands class Alert class Delete < Gzr::Command include Gzr::Alert def initialize(alert_id,options) super() @alert_id = alert_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do delete_alert(@alert_id) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/threshold.rb
lib/gzr/commands/alert/threshold.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' module Gzr module Commands class Alert class Threshold < Gzr::Command include Gzr::Alert def initialize(alert_id, threshold, options) super() @alert_id = alert_id @threshold = threshold @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do update_alert_field(@alert_id, threshold: @threshold) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/chown.rb
lib/gzr/commands/alert/chown.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' module Gzr module Commands class Alert class Chown < Gzr::Command include Gzr::Alert def initialize(alert_id,owner_id,options) super() @alert_id = alert_id @owner_id = owner_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do update_alert_field(@alert_id, owner_id: @owner_id) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/ls.rb
lib/gzr/commands/alert/ls.rb
# The MIT License (MIT) # Copyright (c) 2018 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' require 'tty-table' module Gzr module Commands class Alert class Ls < Gzr::Command include Gzr::Alert def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do req = {} req[:fields] = @options[:fields] unless @options[:fields].nil? req[:disabled] = @options[:disabled] unless @options[:disabled].nil? req[:all_owners] = @options[:all] unless @options[:all].nil? data = search_alerts(**req) begin say_ok "No alerts found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/unfollow.rb
lib/gzr/commands/alert/unfollow.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' module Gzr module Commands class Alert class Unfollow < Gzr::Command include Gzr::Alert def initialize(alert_id,options) super() @alert_id = alert_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do unfollow_alert(@alert_id) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/notifications.rb
lib/gzr/commands/alert/notifications.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' require 'tty-table' module Gzr module Commands class Alert class Notifications < Gzr::Command include Gzr::Alert def initialize(options) super() @options = options @fields = "notification_id,alert_condition_id,user_id,is_read,field_value,threshold_value,ran_at,alert(title,alert_id,investigative_content_id,dashboard_name,dashboard_id,query_slug)" end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = alert_notifications() begin puts "No notifications returned" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@fields) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/import.rb
lib/gzr/commands/alert/import.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/alert' require_relative '../../modules/user' require_relative '../../modules/filehelper' module Gzr module Commands class Alert class Import < Gzr::Command include Gzr::Alert include Gzr::User include Gzr::FileHelper def initialize(file, dashboard_element_id, options) super() @file = file @dashboard_element_id = dashboard_element_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do @me ||= query_me("id") read_file(@file) do |data| data.select! do |k,v| keys_to_keep('create_alert').include? k end data[:owner_id] = @me[:id] data[:dashboard_element_id] = @dashboard_element_id if @dashboard_element_id alert = create_alert(data) output.puts "Imported alert #{alert[:id]}" unless @options[:plain] output.puts alert[:id] if @options[:plain] end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/read.rb
lib/gzr/commands/alert/read.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' module Gzr module Commands class Alert class Read < Gzr::Command include Gzr::Alert def initialize(notification_id,options) super() @notification_id = notification_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = read_alert_notification(@notification_id) output.puts JSON.pretty_generate(data) unless (data.nil? || data.empty?) output.puts "No notification found" if (data.nil? || data.empty?) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/follow.rb
lib/gzr/commands/alert/follow.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' module Gzr module Commands class Alert class Follow < Gzr::Command include Gzr::Alert def initialize(alert_id,options) super() @alert_id = alert_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do follow_alert(@alert_id) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/alert/cat.rb
lib/gzr/commands/alert/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/alert' require_relative '../../modules/filehelper' module Gzr module Commands class Alert class Cat < Gzr::Command include Gzr::Alert include Gzr::FileHelper def initialize(alert_id,options) super() @alert_id = alert_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do alert = get_alert(@alert_id) write_file(@options[:dir] ? "Alert_#{alert[:id]}_#{alert[:field][:name]}.json" : nil, @options[:dir],nil, output) do |f| f.puts JSON.pretty_generate(alert) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/session/update.rb
lib/gzr/commands/session/update.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/session' module Gzr module Commands class Session class Update < Gzr::Command include Gzr::Session def initialize(workspace_id,options) super() @options = options @workspace_id = workspace_id end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] if !@options[:token] && !@options[:token_file] say_warning "Setting the session workspace_id only makes sense with a persistent session using --token or --token_file options" end with_session do auth = update_auth(@workspace_id) output.puts JSON.pretty_generate(auth) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/session/logout.rb
lib/gzr/commands/session/logout.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' module Gzr module Commands class Session class Logout < Gzr::Command def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] login @sdk.logout token_data = read_token_data || {} token_data[@options[:host].to_sym] ||= {} token_data[@options[:host].to_sym]&.delete(@options[:su]&.to_sym || :default) write_token_data(token_data) end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/session/login.rb
lib/gzr/commands/session/login.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' module Gzr module Commands class Session class Login < Gzr::Command def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] login if @options[:text] puts @sdk.access_token return end token_data = read_token_data || {} token_data[@options[:host].to_sym] ||= {} token_data[@options[:host].to_sym][@options[:su]&.to_sym || :default] = { token: @sdk.access_token, expiration: @sdk.access_token_expires_at } write_token_data(token_data) end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/session/get.rb
lib/gzr/commands/session/get.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/session' module Gzr module Commands class Session class Get < Gzr::Command include Gzr::Session def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do auth = get_auth() output.puts JSON.pretty_generate(auth) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/dashboard/mv.rb
lib/gzr/commands/dashboard/mv.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/dashboard' module Gzr module Commands class Dashboard class Mv < Gzr::Command include Gzr::Dashboard def initialize(dashboard_id, target_folder_id, options) super() @dashboard_id = dashboard_id @target_folder_id = target_folder_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do dash = query_dashboard(@dashboard_id) raise Gzr::CLI::Error, "Dashboard with id #{@dashboard_id} does not exist" unless dash matching_title = search_dashboards_by_title(dash[:title],@target_folder_id) if matching_title.empty? || matching_title.first[:deleted] matching_title = false end if matching_title raise Gzr::CLI::Error, "Dashboard #{dash[:title]} already exists in folder #{@target_folder_id}\nUse --force if you want to overwrite it" unless @options[:force] say_ok "Deleting existing dashboard #{matching_title.first[:id]} #{matching_title.first[:title]} in folder #{@target_folder_id}", output: output update_dashboard(matching_title.first[:id],{:deleted=>true}) end update_dashboard(dash[:id],{:folder_id=>@target_folder_id}) output.puts "Moved dashboard #{dash[:id]} to folder #{@target_folder_id}" unless @options[:plain] end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/dashboard/rm.rb
lib/gzr/commands/dashboard/rm.rb
# The MIT License (MIT) # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/dashboard' module Gzr module Commands class Dashboard class Rm < Gzr::Command include Gzr::Dashboard def initialize(dashboard,options) super() @dashboard = dashboard @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do if @options[:restore] update_dashboard(@dashboard, {:deleted=>false}) elsif @options[:soft] update_dashboard(@dashboard, {:deleted=>true}) else delete_dashboard(@dashboard) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/dashboard/import.rb
lib/gzr/commands/dashboard/import.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/dashboard' require_relative '../../modules/look' require_relative '../../modules/user' require_relative '../../modules/plan' require_relative '../../modules/filehelper' module Gzr module Commands class Dashboard class Import < Gzr::Command include Gzr::Dashboard include Gzr::Look include Gzr::User include Gzr::Plan include Gzr::FileHelper def initialize(file, dest_folder_id, options) super() @file = file @dest_folder_id = dest_folder_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do @me ||= query_me("id") read_file(@file) do |data| if data[:deleted] say_warning("Attempt to import a deleted dashboard!") say_warning("This may result in errors.") end if !data[:dashboard_elements] say_error("File contains no dashboard_elements! Is this a look?") raise Gzr::CLI::Error, "import file is not a valid dashboard" end dashboard = sync_dashboard(data,@dest_folder_id, output: output) say_warning "dashboard object #{JSON.pretty_generate dashboard.map(&:to_a).to_json}" if @options[:debug] dashboard[:dashboard_filters] ||= [] source_filters = data[:dashboard_filters].sort { |a,b| a[:row] <=> b[:row] } source_filters.each do |new_filter| filter = new_filter.select do |k,v| (keys_to_keep('create_dashboard_filter') + [:row]).include? k end filter[:dashboard_id] = dashboard[:id] say_warning "Creating filter" if @options[:debug] dashboard[:dashboard_filters].push create_dashboard_filter(filter) end dashboard[:dashboard_elements] ||= [] elem_table = data[:dashboard_elements].map do |new_element| element = new_element.select do |k,v| (keys_to_keep('create_dashboard_element') - [:dashboard_id, :look_id, :query_id, :merge_result_id, :result_maker_id, :query, :merge_result]).include? k end (element[:query_id],element[:look_id],element[:merge_result_id]) = process_dashboard_element(new_element) say_warning "Creating dashboard element #{element.select {|k,v| !v.nil?}.inspect}" if @options[:debug] element[:dashboard_id] = dashboard[:id] result_maker = copy_result_maker_filterables(new_element) element[:result_maker] = result_maker if result_maker dashboard_element = create_dashboard_element(element) say_warning "dashboard_element #{dashboard_element.inspect}" if @options[:debug] if new_element[:alerts] new_element[:alerts].each do |a| a.select! do |k,v| (keys_to_keep('create_alert') - [:owner_id, :dashboard_element_id]).include? k end a[:dashboard_element_id] = dashboard_element[:id] a[:owner_id] = @me[:id] new_alert = create_alert(a) say_warning "alert #{JSON.pretty_generate(new_alert)}" if @options[:debug] end end dashboard[:dashboard_elements].push dashboard_element [new_element[:id], dashboard_element[:id]] end source_dashboard_layouts = data[:dashboard_layouts].map do |new_layout| layout_obj = nil if new_layout[:active] layout_obj = get_dashboard_layout(dashboard[:dashboard_layouts].first[:id]) say_warning "Updating layout #{layout_obj[:id]}" if @options[:debug] else layout = new_layout.select do |k,v| (keys_to_keep('create_dashboard_layout') - [:dashboard_id]).include? k end layout[:dashboard_id] = dashboard[:id] say_warning "Creating dashboard layout #{layout}" if @options[:debug] layout_obj = create_dashboard_layout(layout) say_warning "Created dashboard layout #{JSON.pretty_generate layout_obj.map(&:to_a).to_json}" if @options[:debug] end layout_components = new_layout[:dashboard_layout_components].zip(layout_obj[:dashboard_layout_components]) layout_components.each do |source,target| component = keys_to_keep('update_dashboard_layout_component').collect do |e| [e,nil] end.to_h component[:dashboard_layout_id] = target[:dashboard_layout_id] component.merge!(source.select do |k,v| (keys_to_keep('update_dashboard_layout_component') - [:id,:dashboard_layout_id]).include? k end) component[:dashboard_element_id] = elem_table.assoc(source[:dashboard_element_id])[1] say_warning "Updating dashboard layout component #{target[:id]}" if @options[:debug] update_dashboard_layout_component(target[:id],component) end end upsert_plans_for_dashboard(dashboard[:id],@me[:id],data[:scheduled_plans]) if data[:scheduled_plans] output.puts "Imported dashboard #{dashboard[:id]}" unless @options[:plain] output.puts dashboard[:id] if @options[:plain] end end end def sync_dashboard(source, target_folder_id, output: $stdout) # try to find dashboard by slug in target folder existing_dashboard = search_dashboards_by_slug(source[:slug], target_folder_id).fetch(0,nil) if source[:slug] # check for dash of same title in target folder title_used = search_dashboards_by_title(source[:title], target_folder_id).select {|d| !d[:deleted] }.fetch(0,nil) # If there is no match by slug in target folder or no slug given, then we match by title existing_dashboard ||= title_used say_warning "existing_dashboard object #{existing_dashboard.inspect}" if @options[:debug] # same_title is now a flag indicating that there is already a dash in the same folder with # that title, and it is the one we are updating. same_title = (title_used&.fetch(:id,nil) == existing_dashboard&.fetch(:id,nil)) # check if the slug is used by any dashboard slug_used = search_dashboards_by_slug(source[:slug]).fetch(0,nil) if source[:slug] # same_slug is now a flag indicating that there is already a dash with # that slug, but it is the one we are updating. same_slug = (slug_used&.fetch(:id,nil) == existing_dashboard&.fetch(:id,nil)) if slug_used && !same_slug then say_warning "slug #{slug_used[:slug]} already used for dashboard #{slug_used[:title]} in folder #{slug_used[:folder_id]}", output: output say_warning("That dashboard is in the 'Trash' but not fully deleted yet", output: output) if slug_used[:deleted] say_warning "dashboard will be imported with new slug", output: output end if existing_dashboard then if title_used && !same_title then raise Gzr::CLI::Error, "Dashboard #{source[:title]} already exists in folder #{target_folder_id}\nDelete it before trying to upate another dashboard to have that title." end raise Gzr::CLI::Error, "Dashboard #{existing_dashboard[:title]} with slug #{existing_dashboard[:slug]} already exists in folder #{target_folder_id}\nUse --force if you want to overwrite it" unless @options[:force] say_ok "Modifying existing dashboard #{existing_dashboard[:id]} #{existing_dashboard[:title]} in folder #{target_folder_id}", output: output new_dash = source.select do |k,v| (keys_to_keep('update_dashboard') - [:space_id,:folder_id,:user_id,:slug]).include? k end new_dash[:slug] = source[:slug] unless slug_used new_dash[:deleted] = false if existing_dashboard[:deleted] d = update_dashboard(existing_dashboard[:id],new_dash) d[:dashboard_filters].each do |f| delete_dashboard_filter(f[:id]) end d[:dashboard_filters] = [] d[:dashboard_elements].each do |e| delete_dashboard_element(e[:id]) end d[:dashboard_elements] = [] d[:dashboard_layouts].each do |l| delete_dashboard_layout(l[:id]) unless l[:active] end d[:dashboard_layouts].select! { |l| l[:active] } return d else new_dash = source.select do |k,v| (keys_to_keep('create_dashboard') - [:space_id,:folder_id,:user_id,:slug]).include? k end new_dash[:slug] = source[:slug] unless slug_used new_dash[:folder_id] = target_folder_id new_dash[:user_id] = @me[:id] new_dash.select!{|k,v| !v.nil?} say_warning "new dashboard request #{new_dash.inspect}" if @options[:debug] d = create_dashboard(new_dash) say_warning "new dashboard object #{d.inspect}" if @options[:debug] return d end end def copy_result_maker_filterables(new_element) return nil unless new_element[:result_maker] if new_element[:result_maker].fetch(:filterables,[]).length > 0 result_maker = { :filterables => [] } new_element[:result_maker][:filterables].each do |filterable| result_maker[:filterables] << filterable.select do |k,v| true unless [:can].include? k end end return result_maker end nil end def process_dashboard_element(dash_elem) return [nil, upsert_look(@me[:id], create_fetch_query(dash_elem[:look][:query])[:id], @dest_folder_id, dash_elem[:look])[:id], nil] if dash_elem[:look] query = dash_elem[:result_maker]&.fetch(:query, false) || dash_elem[:query] return [create_fetch_query(query)[:id], nil, nil] if query merge_result = dash_elem[:result_maker]&.fetch(:merge_result, false) || dash_elem[:merge_result] return [nil,nil,create_merge_result(merge_result)[:id]] if merge_result [nil,nil,nil] end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/dashboard/import_lookml.rb
lib/gzr/commands/dashboard/import_lookml.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/dashboard' module Gzr module Commands class Dashboard class ImportLookml < Gzr::Command include Gzr::Dashboard def initialize(dashboard_id, target_folder_id, options) super() @dashboard_id = dashboard_id @target_folder_id = target_folder_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do dash = query_dashboard(@dashboard_id) raise Gzr::CLI::Error, "Dashboard with id #{@dashboard_id} does not exist" unless dash matching_title = search_dashboards_by_title(dash[:title],@target_folder_id) if matching_title.empty? || matching_title.first[:deleted] matching_title = false end if matching_title && !(matching_title.first[:lookml_link_id] == @dashboard_id) raise Gzr::CLI::Error, "Dashboard #{dash[:title]} already exists in folder #{@target_folder_id}\nUse --force if you want to overwrite it" unless @options[:force] say_ok "Deleting existing dashboard #{matching_title.first[:id]} #{matching_title.first[:title]} in folder #{@target_folder_id}", output: output update_dashboard(matching_title.first[:id],{:deleted=>true}) end if matching_title && (matching_title.first[:lookml_link_id] == @dashboard_id) raise Gzr::CLI::Error, "Linked Dashboard #{dash[:title]} already exists in folder #{@target_folder_id}\nUse --sync if you want to synchronize it" unless @options[:sync] say_ok "Syncing existing dashboard #{matching_title.first[:id]} #{matching_title.first[:title]} in folder #{@target_folder_id}", output: output output.puts sync_lookml_dashboard(@dashboard_id) return end new_dash = import_lookml_dashboard(@dashboard_id,@target_folder_id) if @options[:unlink] body = {} body[:lookml_link_id] = nil update_dashboard(new_dash[:id],body) end output.puts "Created user defined dashboard #{new_dash[:id]} in folder #{@target_folder_id}" unless @options[:plain] output.puts new_dash[:id] if @options[:plain] end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/dashboard/sync_lookml.rb
lib/gzr/commands/dashboard/sync_lookml.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/dashboard' module Gzr module Commands class Dashboard class SyncLookml < Gzr::Command include Gzr::Dashboard def initialize(dashboard_id, options) super() @dashboard_id = dashboard_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do dash = query_dashboard(@dashboard_id) raise Gzr::CLI::Error, "Dashboard with id #{@dashboard_id} does not exist" unless dash say_ok sync_lookml_dashboard(@dashboard_id) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/dashboard/cat.rb
lib/gzr/commands/dashboard/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require 'json' require_relative '../../command' require_relative '../../modules/dashboard' require_relative '../../modules/plan' require_relative '../../modules/filehelper' module Gzr module Commands class Dashboard class Cat < Gzr::Command include Gzr::Dashboard include Gzr::FileHelper include Gzr::Plan def initialize(dashboard_id,options) super() @dashboard_id = dashboard_id @options = options end def execute(*args, input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do data = cat_dashboard(@dashboard_id) data = trim_dashboard(data) if @options[:trim] replacements = {} if @options[:transform] max_row = 0 data[:dashboard_layouts][0][:dashboard_layout_components].each_index do |i| component = data[:dashboard_layouts][0][:dashboard_layout_components][i] if component[:row] + component[:height] > max_row max_row = component[:row] + component[:height] + 4 end end read_file(@options[:transform]) do |transform| i = 0 transform[:dashboard_elements].collect! do |e| i += 1 # there is no significance to 9900, we just need to prevent ID collisions e['id'] = 9900 + i data[:dashboard_elements] << e # when inserting an element into the top row, shift the other elements down according to the height of the inserted element if e[:position] === 'top' data[:dashboard_layouts][0][:dashboard_layout_components].each_index do |i| component = data[:dashboard_layouts][0][:dashboard_layout_components][i] component[:row] = component[:row] + e[:height] end row = '0' elsif e[:position] === 'bottom' row = max_row.to_s end column = '0' width = e[:width].to_s height = e[:height].to_s data[:dashboard_layouts][0][:dashboard_layout_components] << JSON.parse('{"id":' + e['id'].to_s + ',"dashboard_layout_id":1,"dashboard_element_id":' + e['id'].to_s + ''',"row":' + row + ',"column":' + column + ',"width":' + width + ',"height":' + height + ',"deleted":false,"element_title_hidden":false,"vis_type":"' + e[:type].to_s + '","can":{"index":true,"show":true,"create":true,"update":true,"destroy":true}}') end transform[:replacements].collect! do |e| replacements[e.keys.first.to_s] = e[e.keys[0]] end end end outputJSON = JSON.pretty_generate(data) replacements.each do |k,v| say_warning("Replaced #{k} with #{v}") if @options[:debug] outputJSON.gsub! k,v end file_name = if @options[:dir] @options[:simple_filename] ? "Dashboard_#{data[:id]}.json" : "Dashboard_#{data[:id]}_#{data[:title]}.json" else nil end write_file(file_name, @options[:dir], nil, output) do |f| f.puts outputJSON end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/folder/export.rb
lib/gzr/commands/folder/export.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/folder' require_relative '../../modules/look' require_relative '../../modules/dashboard' require_relative '../../modules/plan' require_relative '../../modules/filehelper' require 'pathname' require 'stringio' require 'zip' module Gzr module Commands class Folder class Export < Gzr::Command include Gzr::Folder include Gzr::Look include Gzr::Dashboard include Gzr::Plan include Gzr::FileHelper def initialize(folder_id, options) super() @folder_id = folder_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do if @options[:tar] || @options[:tgz] || @options[:zip] then arc_path = Pathname.new(@options[:tgz] || @options[:tar] || @options[:zip]) arc_path = Pathname.new(File.expand_path(@options[:dir])) + arc_path unless arc_path.absolute? if @options[:tar] || @options[:tgz] f = File.open(arc_path.to_path, "wb") tarfile = StringIO.new(String.new,"w") unless @options[:zip] begin tw = Gem::Package::TarWriter.new(tarfile) process_folder(@folder_id, tw) tw.flush tarfile.rewind if @options[:tgz] gzw = Zlib::GzipWriter.new(f) gzw.write tarfile.string gzw.close else f.write tarfile.string end ensure f.close tarfile.close end else z = Zip::File.new(arc_path.to_path, Zip::File::CREATE, false, continue_on_exists_proc: true) begin process_folder(@folder_id, z) ensure z.close end end else process_folder(@folder_id, @options[:dir]) end end end def process_folder(folder_id, base, rel_path = nil) folder = query_folder(folder_id) name = folder[:name] name = "nil (#{folder_id})" if name.nil? path = Pathname.new(name.gsub('/',"\u{2215}")) path = rel_path + path if rel_path write_file("Folder_#{folder[:id]}_#{name}.json", base, path) do |f| f.write JSON.pretty_generate(folder.reject do |k,v| [:looks, :dashboards].include?(k) end) end folder[:looks].each do |l| look = cat_look(l[:id]) look = trim_look(look) if @options[:trim] write_file("Look_#{look[:id]}_#{look[:title]}.json", base, path) do |f| f.write JSON.pretty_generate(look) end end folder[:dashboards].each do |d| data = cat_dashboard(d[:id]) data = trim_dashboard(data) if @options[:trim] write_file("Dashboard_#{data[:id]}_#{data[:title]}.json", base, path) do |f| f.write JSON.pretty_generate(data) end end folder_children = query_folder_children(folder_id) folder_children.each do |child_folder| process_folder(child_folder[:id], base, path) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/folder/tree.rb
lib/gzr/commands/folder/tree.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/folder' require 'tty-tree' # The tty-tree tool is built on the idea of handling directories, so it does # parsing based on slashs (or backslashs on Windows). If those characters are # in object names, tty-tree pulls them out. # This monkey patch disables that. module TTY class Tree class Node def initialize(path, parent, prefix, level) if path.is_a? String # strip null bytes from the string to avoid throwing errors path = path.delete("\0") end @path = path @name = path @parent = parent @prefix = prefix @level = level end end end end module Gzr module Commands class Folder class Tree < Gzr::Command include Gzr::Folder def initialize(filter_spec, options) super() @filter_spec = filter_spec @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do folder_ids = process_args([@filter_spec]) tree_data = Hash.new folder_ids.each do |folder_id| s = query_folder(folder_id, "id,name,parent_id,looks(id,title),dashboards(id,title)") folder_name = s[:name] folder_name = "nil (#{s[:id]})" unless folder_name folder_name = "\"#{folder_name}\"" if ((folder_name != folder_name.strip) || (folder_name.length == 0)) folder_name += " (#{folder_id})" unless folder_ids.length == 1 tree_data[folder_name] = [ recurse_folders(s[:id]) ] + s[:looks].map { |l| "(l) #{l[:title]}" } + s[:dashboards].map { |d| "(d) #{d[:title]}" } end tree = TTY::Tree.new(tree_data) output.puts tree.render end end def recurse_folders(folder_id) data = query_folder_children(folder_id, "id,name,parent_id,looks(id,title),dashboards(id,title)") tree_branch = Hash.new data.each do |s| folder_name = s[:name] folder_name = "nil (#{s[:id]})" unless folder_name folder_name = "\"#{folder_name}\"" if ((folder_name != folder_name.strip) || (folder_name.length == 0)) tree_branch[folder_name] = [ recurse_folders(s[:id]) ] + s[:looks].map { |l| "(l) #{l[:title]}" } + s[:dashboards].map { |d| "(d) #{d[:title]}" } end tree_branch end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/folder/top.rb
lib/gzr/commands/folder/top.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/folder' require 'tty-table' module Gzr module Commands class Folder class Top < Gzr::Command include Gzr::Folder def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do extra_fields = %w(is_shared_root is_users_root is_embed_shared_root is_embed_users_root) query_fields = (@options[:fields].split(',') + extra_fields).uniq folders = all_folders(query_fields.join(',')) begin puts "No folders found" return nil end unless folders && folders.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] data = folders.select { |h| ( h[:is_shared_root] || h[:is_users_root] || h[:is_embed_shared_root] || h[:is_embed_users_root] )} table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: [:right], width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/folder/ls.rb
lib/gzr/commands/folder/ls.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/folder' require 'tty-table' module Gzr module Commands class Folder class Ls < Gzr::Command include Gzr::Folder def initialize(filter_spec, options) super() @filter_spec = filter_spec @options = options end def flatten_data(raw_array) rows = raw_array.map do |entry| entry.select do |k,v| !(v.kind_of?(Array) || v.kind_of?(Hash)) end end raw_array.map do |entry| entry.select do |k,v| v.kind_of? Array end.each do |section,section_value| section_value.each do |section_entry| h = {} section_entry.each_pair do |k,v| h[:"#{section}.#{k}"] = v end rows.push(h) end end end rows end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do folder_ids = process_args([@filter_spec]) begin puts "No folders match #{@filter_spec}" return nil end unless folder_ids && folder_ids.length > 0 @options[:fields] = 'dashboards(id,title)' if @filter_spec == 'lookml' f = @options[:fields] data = folder_ids.map do |folder_id| query_folder(folder_id, f) end.compact folder_ids.each do |folder_id| query_folder_children(folder_id, 'id,name,parent_id').each do |child| data.push child end end begin puts "No data returned for folders #{folder_ids.inspect}" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = flatten_data(data).map do |row| fields.collect do |e| row.fetch(e.to_sym,nil) end end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id\)*$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/folder/create.rb
lib/gzr/commands/folder/create.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/folder' module Gzr module Commands class Folder class Create < Gzr::Command include Gzr::Folder def initialize(name,parent_folder, options) super() @name = name @parent_folder = parent_folder @options = options end def execute(input: $stdin, output: $stdout) folder = nil with_session do folder = create_folder(@name, @parent_folder) output.puts "Created folder #{folder[:id]}" unless @options[:plain] output.puts folder[:id] if @options[:plain] end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/folder/rm.rb
lib/gzr/commands/folder/rm.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/folder' module Gzr module Commands class Folder class Rm < Gzr::Command include Gzr::Folder def initialize(folder,options) super() @folder = folder @options = options end def execute(input: $stdin, output: $stdout) with_session do folder = query_folder(@folder) begin puts "Folder #{@folder} not found" return nil end unless folder children = query_folder_children(@folder) unless (folder[:looks].length == 0 && folder[:dashboards].length == 0 && children.length == 0) || @options[:force] then raise Gzr::CLI::Error, "Folder '#{folder[:name]}' is not empty. Folder cannot be deleted unless --force is specified" end delete_folder(@folder) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/folder/cat.rb
lib/gzr/commands/folder/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/folder' require_relative '../../modules/filehelper' require 'zlib' module Gzr module Commands class Folder class Cat < Gzr::Command include Gzr::Folder include Gzr::FileHelper def initialize(folder_id, options) super() @folder_id = folder_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do data = query_folder(@folder_id) write_file(@options[:dir] ? "Folder_#{data[:id]}_#{data[:name]}.json" : nil, @options[:dir], nil, output) do |f| f.puts JSON.pretty_generate(data) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/look/mv.rb
lib/gzr/commands/look/mv.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../gzr' require_relative '../../command' require_relative '../../modules/look' module Gzr module Commands class Look class Mv < Gzr::Command include Gzr::Look def initialize(look_id, target_folder_id, options) super() @look_id = look_id @target_folder_id = target_folder_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do look = query_look(@look_id) raise Gzr::CLI::Error, "Look with id #{@look_id} does not exist" unless look matching_title = search_looks_by_title(look[:title],@target_folder_id) if matching_title.empty? || matching_title.first[:deleted] matching_title = false end if matching_title raise Gzr::CLI::Error, "Look #{look[:title]} already exists in folder #{@target_folder_id}\nUse --force if you want to overwrite it" unless @options[:force] say_ok "Deleting existing look #{matching_title.first[:id]} #{matching_title.first[:title]} in folder #{@target_folder_id}", output: output update_look(matching_title.first[:id],{:deleted=>true}) end update_look(look[:id],{:folder_id=>@target_folder_id}) output.puts "Moved look #{look[:id]} to folder #{@target_folder_id}" unless @options[:plain] end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/look/rm.rb
lib/gzr/commands/look/rm.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/look' module Gzr module Commands class Look class Rm < Gzr::Command include Gzr::Look def initialize(look_id, options) super() @look_id = look_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do if @options[:restore] update_look(@look_id, {:deleted=>false}) elsif @options[:soft] update_look(@look_id, {:deleted=>true}) else delete_look(@look_id) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/look/import.rb
lib/gzr/commands/look/import.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/look' require_relative '../../modules/user' require_relative '../../modules/plan' require_relative '../../modules/filehelper' module Gzr module Commands class Look class Import < Gzr::Command include Gzr::Look include Gzr::User include Gzr::Plan include Gzr::FileHelper def initialize(file, dest_folder_id, options) super() @file = file @dest_folder_id = dest_folder_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do @me ||= query_me("id") read_file(@file) do |data| if data[:deleted] say_warning("Attempt to import a deleted look!") say_warning("This may result in errors.") end if data[:dashboard_elements] say_error("File contains dashboard_elements! Is this a dashboard?") raise Gzr::CLI::Error, "import file is not a valid look" end look = upsert_look(@me[:id],create_fetch_query(data[:query]).id,@dest_folder_id,data,output: output) upsert_plans_for_look(look.id,@me[:id],data[:scheduled_plans]) if data[:scheduled_plans] output.puts "Imported look #{look[:id]}" unless @options[:plain] output.puts look[:id] if @options[:plain] end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/look/cat.rb
lib/gzr/commands/look/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/look' require_relative '../../modules/plan' require_relative '../../modules/filehelper' module Gzr module Commands class Look class Cat < Gzr::Command include Gzr::Look include Gzr::FileHelper include Gzr::Plan def initialize(look_id,options) super() @look_id = look_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do data = cat_look(@look_id) data = trim_look(data) if @options[:trim] file_name = if @options[:dir] @options[:simple_filename] ? "Look_#{data[:id]}.json" : "Look_#{data[:id]}_#{data[:title]}.json" else nil end write_file(file_name, @options[:dir],nil, output) do |f| f.puts JSON.pretty_generate(data) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/role/user_ls.rb
lib/gzr/commands/role/user_ls.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/role' require 'tty-table' module Gzr module Commands class Role class UserLs < Gzr::Command include Gzr::Role def initialize(role_id,options) super() @role_id = role_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = query_role_users(@role_id,@options[:fields],!@options[:all_users]) begin say_ok "No role users found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| next :left if k == "external_group_id" (k =~ /(id|count)$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, multiline: true, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/role/ls.rb
lib/gzr/commands/role/ls.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/role' require 'tty-table' module Gzr module Commands class Role class Ls < Gzr::Command include Gzr::Role def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = query_all_roles(@options[:fields]) begin say_ok "No roles found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| next :left if k == "external_group_id" (k =~ /(id|count)$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, multiline: true, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/role/user_rm.rb
lib/gzr/commands/role/user_rm.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/role' module Gzr module Commands class Role class UserRm < Gzr::Command include Gzr::Role def initialize(role_id,users,options) super() @role_id = role_id @users = users.collect { |u| u.to_i } @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do users = query_role_users(@role_id, 'id').collect { |u| u[:id] } users -= @users set_role_users(@role_id,users.uniq) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/role/create.rb
lib/gzr/commands/role/create.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/role' module Gzr module Commands class Role class Create < Gzr::Command include Gzr::Role def initialize(name,pset,mset, options) super() @name = name @pset = pset @mset = mset @options = options end def execute(input: $stdin, output: $stdout) folder = nil with_session do role = create_role(@name, @pset, @mset) output.puts "Created role #{role[:id]} #{role[:name]}" unless @options[:plain] output.puts role[:id] if @options[:plain] end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/role/group_add.rb
lib/gzr/commands/role/group_add.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/role' module Gzr module Commands class Role class GroupAdd < Gzr::Command include Gzr::Role def initialize(role_id,groups,options) super() @role_id = role_id @groups = groups.collect { |g| g.to_i } @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do groups = query_role_groups(@role_id, 'id').collect { |g| g[:id] } groups += @groups set_role_groups(@role_id,groups.uniq) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/role/group_rm.rb
lib/gzr/commands/role/group_rm.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/role' module Gzr module Commands class Role class GroupRm < Gzr::Command include Gzr::Role def initialize(role_id,groups,options) super() @role_id = role_id @groups = groups.collect { |g| g.to_i } @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do groups = query_role_groups(@role_id, 'id').collect { |g| g[:id] } groups -= @groups set_role_groups(@role_id,groups.uniq) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/role/rm.rb
lib/gzr/commands/role/rm.rb
# The MIT License (MIT) # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/role' module Gzr module Commands class Role class Rm < Gzr::Command include Gzr::Role def initialize(role_id,options) super() @role_id = role_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do delete_role(@role_id) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/role/group_ls.rb
lib/gzr/commands/role/group_ls.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/role' require 'tty-table' module Gzr module Commands class Role class GroupLs < Gzr::Command include Gzr::Role def initialize(role_id,options) super() @role_id = role_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = query_role_groups(@role_id,@options[:fields]) begin say_ok "No role groups found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| next :left if k == "external_group_id" (k =~ /(id|count)$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, multiline: true, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/role/user_add.rb
lib/gzr/commands/role/user_add.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/role' module Gzr module Commands class Role class UserAdd < Gzr::Command include Gzr::Role def initialize(role_id,users,options) super() @role_id = role_id @users = users.collect { |u| u.to_i } @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do users = query_role_users(@role_id, 'id').collect { |u| u[:id] } users += @users set_role_users(@role_id,users.uniq) end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/role/cat.rb
lib/gzr/commands/role/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/role' require_relative '../../modules/filehelper' module Gzr module Commands class Role class Cat < Gzr::Command include Gzr::Role include Gzr::FileHelper def initialize(role_id,options) super() @role_id = role_id @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if @options[:debug] with_session do data = query_role(@role_id) data = trim_role(data) if @options[:trim] write_file(@options[:dir] ? "Role_#{data[:id]}_#{data[:name]}.json" : nil, @options[:dir], nil, output) do |f| f.puts JSON.pretty_generate(data) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/attribute/set_group_value.rb
lib/gzr/commands/attribute/set_group_value.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/group' require_relative '../../modules/attribute' module Gzr module Commands class Attribute class SetGroupValue < Gzr::Command include Gzr::Attribute include Gzr::Group def initialize(group,attr,value,options) super() @group = group @attr = attr @value = value @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do group_id = @group if /^\d+$/.match @group group = nil if group_id group = query_group(group_id) else results = search_groups(@group) if results && results.length == 1 group = results.first elsif results raise(Gzr::CLI::Error, "Pattern #{@group} matched more than one group") else raise(Gzr::CLI::Error, "Pattern #{@group} did not match any groups") end end attr_id = @attr if /^\d+$/.match @attr attr = nil if attr_id attr = query_user_attribute(attr_id) else attr = get_attribute_by_name(@attr) end raise(Gzr::CLI::Error, "Attribute #{@attr} does not exist") unless attr data = update_user_attribute_group_value(group[:id],attr[:id], @value) say_warning("Attribute #{attr[:name]} does not have a value set for group #{group[:name]}", output: output) unless data output.puts "Group attribute #{data[:id]} set to #{data[:value]}" end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/attribute/ls.rb
lib/gzr/commands/attribute/ls.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/attribute' require 'tty-table' module Gzr module Commands class Attribute class Ls < Gzr::Command include Gzr::Attribute def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do f = @options[:fields] data = query_all_user_attributes(f) begin say_ok "No use attributes found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/attribute/create.rb
lib/gzr/commands/attribute/create.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/attribute' module Gzr module Commands class Attribute class Create < Gzr::Command include Gzr::Attribute def initialize(name,label,options) super() @name = name @label = label || @name.split(/ |\_|\-/).map(&:capitalize).join(" ") @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do source = { :name=>@name, :label=>@label, :type=>@options[:type] } source[:'default_value'] = @options[:'default-value'] if @options[:'default-value'] source[:'value_is_hidden'] = true if @options[:'is-hidden'] source[:'user_can_view'] = true if @options[:'can-view'] source[:'user_can_edit'] = true if @options[:'can-edit'] source[:'hidden_value_domain_allowlist'] = @options[:'domain-allowlist'] if @options[:'is-hidden'] && @options[:'domain-allowlist'] attr = upsert_user_attribute(source, @options[:force], output: $stdout) output.puts "Imported attribute #{attr[:name]} #{attr[:id]}" unless @options[:plain] output.puts attr.id if @options[:plain] end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/attribute/get_group_value.rb
lib/gzr/commands/attribute/get_group_value.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/group' require_relative '../../modules/attribute' module Gzr module Commands class Attribute class GetGroupValue < Gzr::Command include Gzr::Attribute include Gzr::Group def initialize(group,attr,options) super() @group = group @attr = attr @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do group_id = @group if /^\d+$/.match @group group = nil if group_id group = query_group(group_id) else results = search_groups(@group) if results && results.length == 1 group = results.first elsif results raise(Gzr::CLI::Error, "Pattern #{@group} matched more than one group") else raise(Gzr::CLI::Error, "Pattern #{@group} did not match any groups") end end attr_id = @attr if /^\d+$/.match @attr attr = nil if attr_id attr = query_user_attribute(attr_id) else attr = get_attribute_by_name(@attr) end raise(Gzr::CLI::Error, "Attribute #{@attr} does not exist") unless attr data = query_user_attribute_group_value(group[:id],attr[:id]) say_warning("Attribute #{attr[:name]} does not have a value set for group #{group[:name]}", output: output) unless data output.puts data[:value] if data end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/attribute/rm.rb
lib/gzr/commands/attribute/rm.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/attribute' module Gzr module Commands class Attribute class Rm < Gzr::Command include Gzr::Attribute def initialize(attr,options) super() @attr = attr @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do id = @attr if /^\d+$/.match @attr attr = nil if id attr = query_user_attribute(id) else attr = get_attribute_by_name(@attr) end raise(Gzr::CLI::Error, "Attribute #{@attr} does not exist") unless attr raise(Gzr::CLI::Error, "Attribute #{attr[:name]} is a system built-in and cannot be deleted ") if attr[:is_system] raise(Gzr::CLI::Error, "Attribute #{attr[:name]} is marked permanent and cannot be deleted ") if attr[:is_permanent] delete_user_attribute(attr[:id]) output.puts "Deleted attribute #{attr[:name]} #{attr[:id]}" unless @options[:plain] output.puts attr[:id] if @options[:plain] end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/attribute/import.rb
lib/gzr/commands/attribute/import.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/attribute' require_relative '../../modules/filehelper' module Gzr module Commands class Attribute class Import < Gzr::Command include Gzr::Attribute include Gzr::FileHelper def initialize(file,options) super() @file = file @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do read_file(@file) do |source| attr = upsert_user_attribute(source, @options[:force], output: $stdout) output.puts "Imported attribute #{attr[:name]} #{attr[:id]}" unless @options[:plain] output.puts attr[:id] if @options[:plain] end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/attribute/cat.rb
lib/gzr/commands/attribute/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/attribute' require_relative '../../modules/filehelper' module Gzr module Commands class Attribute class Cat < Gzr::Command include Gzr::Attribute include Gzr::FileHelper def initialize(attr,options) super() @attr = attr @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do f = @options[:fields] id = @attr if /^\d+$/.match @attr attr = nil if id attr = query_user_attribute(id,f) else attr = get_attribute_by_name(@attr,f) end raise(Gzr::CLI::Error, "Attribute #{@attr} does not exist") unless attr write_file(@options[:dir] ? "Attribute_#{attr[:id]}_#{attr[:name]}.json" : nil, @options[:dir],nil, output) do |f| f.puts JSON.pretty_generate(attr) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/permission/tree.rb
lib/gzr/commands/permission/tree.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/permission' require 'tty-tree' require_relative '../../command' module Gzr module Commands class Permission class Tree < Gzr::Command include Gzr::Permission def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = query_all_permissions() begin say_ok "No permissions found" return nil end unless data && data.length > 0 tree_data = Hash.new data.sort! { |a,b| a[:permission] <=> b[:permission] } data.select {|e| e[:parent] == nil}.each do |e| tree_data[e[:permission]] = [recurse_permissions(e[:permission], data)] end tree = TTY::Tree.new(tree_data) output.puts tree.render end end def recurse_permissions(permission, data) tree_branch = Hash.new data.select { |e| e[:parent] == permission }.each do |e| tree_branch[e[:permission]] = [recurse_permissions(e[:permission], data)] end tree_branch end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/permission/set.rb
lib/gzr/commands/permission/set.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../subcommandbase' module Gzr module Commands class Permission class Set < SubCommandBase namespace :'permission set' desc 'ls', 'List the permission sets in this server.' method_option :help, aliases: '-h', type: :boolean, desc: 'Display usage information' method_option :fields, type: :string, default: 'id,name,permissions,built_in,all_access', desc: 'Fields to display' method_option :plain, type: :boolean, default: false, desc: 'print without any extra formatting' method_option :csv, type: :boolean, default: false, desc: 'output in csv format per RFC4180' def ls(*) if options[:help] invoke :help, ['ls'] else require_relative 'set/ls' Gzr::Commands::Permission::Set::Ls.new(options).execute end end desc 'cat PERMISSION_SET_ID', 'Output json information about a permission set to screen or file' method_option :help, aliases: '-h', type: :boolean, desc: 'Display usage information' method_option :dir, type: :string, desc: 'Directory to store output file' method_option :trim, type: :boolean, desc: 'Trim output to minimal set of fields for later import' def cat(permission_set_id) if options[:help] invoke :help, ['cat'] else require_relative 'set/cat' Gzr::Commands::Permission::Set::Cat.new(permission_set_id,options).execute end end desc 'import FILE', 'Import a permission set from a file' method_option :help, aliases: '-h', type: :boolean, desc: 'Display usage information' method_option :force, type: :boolean, desc: 'Overwrite an existing permission set' method_option :plain, type: :boolean, default: false, desc: 'print without any extra formatting' def import(file) if options[:help] invoke :help, ['import'] else require_relative 'set/import' Gzr::Commands::Permission::Set::Import.new(file, options).execute end end desc 'rm PERMISSION_SET_ID', 'Delete the permission_set given by PERMISSION_SET_ID' method_option :help, aliases: '-h', type: :boolean, desc: 'Display usage information' def rm(permission_set_id) if options[:help] invoke :help, ['delete'] else require_relative 'set/rm' Gzr::Commands::Permission::Set::Delete.new(permission_set_id,options).execute end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/permission/ls.rb
lib/gzr/commands/permission/ls.rb
# The MIT License (MIT) # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../command' require_relative '../../modules/permission' require 'tty-table' require_relative '../../command' module Gzr module Commands class Permission class Ls < Gzr::Command include Gzr::Permission def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = query_all_permissions() begin say_ok "No permissions found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names('permission,parent,description') table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/permission/set/ls.rb
lib/gzr/commands/permission/set/ls.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../command' require_relative '../../../modules/permission/set' require 'tty-table' module Gzr module Commands class Permission class Set class Ls < Gzr::Command include Gzr::Permission::Set def initialize(options) super() @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = all_permission_sets(@options[:fields]) begin say_ok "No permission sets found" return nil end unless data && data.length > 0 table_hash = Hash.new fields = field_names(@options[:fields]) table_hash[:header] = fields unless @options[:plain] table_hash[:rows] = data.map do |row| field_expressions_eval(fields,row) end table = TTY::Table.new(table_hash) alignments = fields.collect do |k| (k =~ /id$/) ? :right : :left end begin if @options[:csv] then output.puts render_csv(table) else output.puts table.render(if @options[:plain] then :basic else :ascii end, multiline: !@options[:plain], alignments: alignments, width: @options[:width] || TTY::Screen.width) end end if table end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/permission/set/rm.rb
lib/gzr/commands/permission/set/rm.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../command' require_relative '../../../modules/permission/set' module Gzr module Commands class Permission class Set class Delete < Gzr::Command include Gzr::Permission::Set def initialize(permission_set_id,options) super() @permission_set_id = permission_set_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do delete_permission_set(@permission_set_id) end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/permission/set/import.rb
lib/gzr/commands/permission/set/import.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../../gzr' require_relative '../../../command' require_relative '../../../modules/permission/set' require_relative '../../../modules/filehelper' module Gzr module Commands class Permission class Set class Import < Gzr::Command include Gzr::Permission::Set include Gzr::FileHelper def initialize(file, options) super() @file = file @options = options end def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do permission_set = nil read_file(@file) do |data| search_results = search_permission_sets(name: data[:name]) if search_results && search_results.length == 1 name = data[:name] if !@options[:force] raise Gzr::CLI::Error, "Permission Set #{name} already exists\nUse --force if you want to overwrite it" end data.select! do |k,v| keys_to_keep('update_permission_set').include? k end permission_set = update_permission_set(search_results.first[:id], data) else data.select! do |k,v| keys_to_keep('create_permission_set').include? k end permission_set = create_permission_set(data) end output.puts "Imported permission set #{permission_set[:id]}" unless @options[:plain] output.puts permission_set[:id] if @options[:name] end end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/commands/permission/set/cat.rb
lib/gzr/commands/permission/set/cat.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative '../../../command' require_relative '../../../modules/permission/set' require_relative '../../../modules/filehelper' module Gzr module Commands class Permission class Set class Cat < Gzr::Command include Gzr::Permission::Set include Gzr::FileHelper def initialize(permission_set_id,options) super() @permission_set_id = permission_set_id @options = options end def execute(input: $stdin, output: $stdout) say_warning(@options) if @options[:debug] with_session do data = cat_permission_set(@permission_set_id) if data.nil? say_warning "Permission Set #{permission_set_id} not found" return end data = trim_permission_set(data) if @options[:trim] write_file(@options[:dir] ? "Permission_Set_#{data[:name]}.json" : nil, @options[:dir],nil, output) do |f| f.puts JSON.pretty_generate(data) end end end end end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/modules/cron.rb
lib/gzr/modules/cron.rb
# The MIT License (MIT) # Copyright (c) 2024 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true module Gzr module Cron def randomize_cron(crontab, window=60) cronfields = crontab.split(%r{\s+}) minute = cronfields[0].to_i hour = cronfields[1].to_i factor = rand(window) - (window/2) minute = minute + factor if minute < 0 hour = hour - 1 minute = minute + 60 end if hour < 0 hour = 23 end if minute > 59 hour = hour + 1 minute = minute - 60 end if hour > 23 hour = 0 end cronfields[0] = minute cronfields[1] = hour if /^[[:digit:]]+$/.match? cronfields[1] return cronfields.join(' ') end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/modules/permission.rb
lib/gzr/modules/permission.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true module Gzr module Permission def query_all_permissions() begin @sdk.all_permissions().collect { |p| p.to_attrs } rescue LookerSDK::Error => e say_error "Error querying all_permissions()" say_error e raise end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/modules/session.rb
lib/gzr/modules/session.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require 'json' require 'pastel' require 'tty-reader' require_relative '../../gzr' module Gzr module Session def pastel @pastel ||= Pastel.new end def say_ok(data, output: $stdout) output.puts pastel.green data end def say_warning(data, output: $stderr) output.puts pastel.yellow data end def say_error(data, output: $stderr) output.puts pastel.red data end @versions = [] @current_version = nil def sufficient_version?(given_version, minimum_version) return true unless (given_version && minimum_version) versions = @versions.sort !versions.drop_while {|v| v < minimum_version}.reverse.drop_while {|v| v > given_version}.empty? end def token_file "#{ENV["HOME"]}/.gzr_auth" end def read_token_data return nil unless File.exist?(token_file) s = File.stat(token_file) if !(s.mode.to_s(8)[3..5] == "600") say_error "#{token_file} mode is #{s.mode.to_s(8)[3..5]}. It must be 600. Ignoring." return nil end token_data = nil file = nil begin file = File.open(token_file) token_data = JSON.parse(file.read,{:symbolize_names => true}) ensure file.close if file end token_data end def write_token_data(token_data) file = nil begin file = File.new(token_file, "wt") file.chmod(0600) file.write JSON.pretty_generate(token_data) ensure file.close if file end end def build_connection_hash(api_version=nil) conn_hash = Hash.new conn_hash[:api_endpoint] = "http#{@options[:ssl] ? "s" : ""}://#{@options[:host]}:#{@options[:port]}/api/#{api_version||@current_version||""}" if @options[:http_proxy] conn_hash[:connection_options] ||= {} conn_hash[:connection_options][:proxy] = { :uri => @options[:http_proxy] } end if @options[:ssl] conn_hash[:connection_options] ||= {} if @options[:verify_ssl] then conn_hash[:connection_options][:ssl] = { :verify => true, :verify_mode => (OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT) } else conn_hash[:connection_options][:ssl] = { :verify => false, :verify_mode => (OpenSSL::SSL::VERIFY_NONE) } end end if @options[:timeout] conn_hash[:connection_options] ||= {} conn_hash[:connection_options][:request] = { :timeout => @options[:timeout] } end conn_hash[:user_agent] = "Gazer #{Gzr::VERSION}" return conn_hash if @options[:token] || @options[:token_file] if @options[:client_id] then conn_hash[:client_id] = @options[:client_id] if @options[:client_secret] then conn_hash[:client_secret] = @options[:client_secret] else reader = TTY::Reader.new @secret ||= reader.read_line("Enter your client_secret:", echo: false) conn_hash[:client_secret] = @secret end else conn_hash[:netrc] = true conn_hash[:netrc_file] = "~/.netrc" end conn_hash end def login(min_api_version="4.0") if !@options[:token] && !@options[:token_file] if (@options[:client_id].nil? && ENV["LOOKERSDK_CLIENT_ID"]) @options[:client_id] = ENV["LOOKERSDK_CLIENT_ID"] end if (@options[:client_secret].nil? && ENV["LOOKERSDK_CLIENT_SECRET"]) @options[:client_secret] = ENV["LOOKERSDK_CLIENT_SECRET"] end end if (@options[:verify_ssl] && ENV["LOOKERSDK_VERIFY_SSL"]) @options[:verify_ssl] = !(/^f(alse)?$/i =~ ENV["LOOKERSDK_VERIFY_SSL"]) end if ((@options[:host] == 'localhost') && ENV["LOOKERSDK_BASE_URL"]) base_url = ENV["LOOKERSDK_BASE_URL"] @options[:ssl] = !!(/^https/ =~ base_url) @options[:host] = /^https?:\/\/([^:\/]+)/.match(base_url)[1] md = /:([0-9]+)\/?$/.match(base_url) @options[:port] = md[1] if md end say_ok("using options #{@options.select { |k,v| k != 'client_secret' }.map { |k,v| "#{k}=>#{v}" }}") if @options[:debug] @secret = nil begin conn_hash = build_connection_hash sawyer_options = { :links_parser => Sawyer::LinkParsers::Simple.new, :serializer => LookerSDK::Client::Serializer.new(JSON), :faraday => Faraday.new(conn_hash[:connection_options]) do |conn| conn.use LookerSDK::Response::RaiseError if @options[:persistent] conn.adapter :net_http_persistent end end } endpoint = conn_hash[:api_endpoint] endpoint_uri = URI.parse(endpoint) root = endpoint.slice(0..-endpoint_uri.path.length) agent = Sawyer::Agent.new(root, sawyer_options) do |http| http.headers[:accept] = 'application/json' http.headers[:user_agent] = conn_hash[:user_agent] end begin versions_response = agent.call(:get,"/versions") @versions = versions_response.data.supported_versions.map {|v| v.version} @current_version = versions_response.data.current_version.version || "4.0" rescue Faraday::SSLError => e raise Gzr::CLI::Error, "SSL Certificate could not be verified\nDo you need the --no-verify-ssl option or the --no-ssl option?" rescue Faraday::ConnectionFailed => cf raise Gzr::CLI::Error, "Connection Failed.\nDid you specify the --no-ssl option for an ssl secured server?\nYou may need to use --port=443 in some cases as well." rescue LookerSDK::NotFound => nf say_warning "endpoint #{root}/versions was not found" end end say_warning "API current_version #{@current_version}" if @options[:debug] say_warning "Supported API versions #{@versions}" if @options[:debug] api_version = [min_api_version, @current_version].max raise Gzr::CLI::Error, "Operation requires API v#{api_version}, which is not available from this host" if api_version && !@versions.any? {|v| v == api_version} conn_hash = build_connection_hash(api_version) @secret = nil say_ok("connecting to #{conn_hash.map { |k,v| "#{k}=>#{(k == :client_secret) ? '*********' : v}" }}") if @options[:debug] begin faraday = Faraday.new(conn_hash[:connection_options]) do |conn| conn.use LookerSDK::Response::RaiseError if @options[:persistent] conn.adapter :net_http_persistent end end @sdk = LookerSDK::Client.new(conn_hash.merge(faraday: faraday)) unless @sdk say_ok "check for connectivity: #{@sdk.alive?}" if @options[:debug] if @options[:token_file] entry = read_token_data&.fetch(@options[:host].to_sym,nil)&.fetch(@options[:su]&.to_sym || :default,nil) if entry.nil? say_error "No token found for host #{@options[:host]} and user #{@options[:su] || "default"}" say_error "login with `gzr session login --host #{@options[:host]}` to set a token" raise LookerSDK::Unauthorized.new end (day, time, tz) = entry[:expiration].split(' ') day_parts = day.split('-') time_parts = time.split(':') date_time_parts = day_parts + time_parts + [tz] expiration = Time.new(*date_time_parts) if expiration < (Time.now + 300) if expiration < Time.now say_error "token expired at #{expiration}" else say_error "token expires at #{expiration}, which is in the next 5 minutes" end say_error "login again with `gzr session login --host #{@options[:host]}`" raise LookerSDK::Unauthorized.new end @sdk.access_token = entry[:token] elsif @options[:token] @sdk.access_token = @options[:token] end say_ok "verify authentication: #{@sdk.authenticated?}" if @options[:debug] rescue LookerSDK::Unauthorized => e say_error "Unauthorized - credentials are not valid" raise rescue LookerSDK::Error => e say_error "Unable to connect" say_error e say_error e.errors if e.respond_to?(:errors) && e.errors raise end raise Gzr::CLI::Error, "Invalid credentials" unless @sdk.authenticated? if @options[:su] && !(@options[:token] || @options[:token_file])then say_ok "su to user #{@options[:su]}" if @options[:debug] @access_token_stack.push(@sdk.access_token) begin @sdk.access_token = @sdk.login_user(@options[:su]).access_token say_warning "verify authentication: #{@sdk.authenticated?}" if @options[:debug] rescue LookerSDK::Error => e say_error "Unable to su to user #{@options[:su]}" say_error e say_error e.errors if e.respond_to?(:errors) && e.errors raise end end @sdk end def logout_all pastel = Pastel.new(enabled: true) say_ok "logout" if @options[:debug] begin @sdk.logout rescue LookerSDK::Error => e say_error "Unable to logout" say_error e say_error e.errors if e.respond_to?(:errors) && e.errors end if @sdk loop do token = @access_token_stack.pop break unless token say_ok "logout the parent session" if @options[:debug] @sdk.access_token = token begin @sdk.logout rescue LookerSDK::Error => e say_error "Unable to logout" say_error e say_error e.errors if e.respond_to?(:errors) && e.errors end end end def with_session(min_api_version="4.0") return nil unless block_given? begin login(min_api_version) unless @sdk yield rescue LookerSDK::Error => e say_error e.errors if e.respond_to?(:errors) && e.errors e.backtrace.each { |b| say_error b } if @options[:debug] raise Gzr::CLI::Error, e.message ensure logout_all unless @options[:token] || @options[:token_file] end end def update_auth(workspace_id) body = {} body[:workspace_id] = workspace_id begin @sdk.update_session(body)&.to_attrs rescue LookerSDK::Error => e say_error "Unable to run update_session(#{JSON.pretty_generate(body)})" say_error e end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/modules/project.rb
lib/gzr/modules/project.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true module Gzr module Project def all_projects(fields: 'id') begin @sdk.all_projects({ fields: fields }).collect { |p| p.to_attrs } rescue LookerSDK::NotFound => e return [] rescue LookerSDK::Error => e say_error "Error querying all_projects(#{fields})" say_error e raise end end def cat_project(project_id) begin @sdk.project(project_id)&.to_attrs rescue LookerSDK::NotFound => e say_error "project(#{project_id}) not found" say_error e raise rescue LookerSDK::Error => e say_error "Error getting project(#{project_id})" say_error e raise end end def trim_project(data) data.select do |k,v| keys_to_keep('create_project').include? k end end def create_project(body) begin @sdk.create_project(body)&.to_attrs rescue LookerSDK::Error => e say_error "Error running create_project(#{JSON.pretty_generate(body)})" say_error e raise end end def update_project(id,body) begin @sdk.update_project(id,body)&.to_attrs rescue LookerSDK::NotFound => e say_error "update_project(#{id},#{JSON.pretty_generate(body)} not found)" say_error e raise rescue LookerSDK::Error => e say_error "Error running update_project(#{id},#{JSON.pretty_generate(body)})" say_error e raise end end def git_deploy_key(id) begin @sdk.git_deploy_key(id) rescue LookerSDK::NotFound => e nil rescue LookerSDK::Error => e say_error "Error running git_deploy_key(#{id})" say_error e raise end end def create_git_deploy_key(id) begin @sdk.create_git_deploy_key(id) rescue LookerSDK::NotFound => e nil rescue LookerSDK::Error => e say_error "Error running create_git_deploy_key(#{id})" say_error e raise end end def all_git_branches(proj_id) begin @sdk.all_git_branches(proj_id).collect { |b| b.to_attrs } rescue LookerSDK::NotFound => e [] rescue LookerSDK::Error => e say_error "Error running all_git_branches(#{proj_id})" say_error e raise end end def git_branch(proj_id) begin @sdk.git_branch(proj_id).to_attrs rescue LookerSDK::NotFound => e nil rescue LookerSDK::Error => e say_error "Error running git_branch(#{proj_id})" say_error e raise end end def deploy_to_production(proj_id) begin @sdk.deploy_to_production(proj_id) rescue LookerSDK::NotFound => e say_error "deploy_to_production(#{proj_id}) not found" say_error e raise rescue LookerSDK::Error => e say_error "Error running deploy_to_production(#{proj_id})" say_error e raise end end def update_git_branch(proj_id, name) body = { name: name } begin @sdk.update_git_branch(proj_id, body)&.to_attrs rescue LookerSDK::NotFound => e say_error "update_git_branch(#{proj_id},#{JSON.pretty_generate(body)}) not found" say_error e raise rescue LookerSDK::Error => e say_error "Error running update_git_branch(#{proj_id},#{JSON.pretty_generate(body)})" say_error e raise end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/modules/group.rb
lib/gzr/modules/group.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true module Gzr module Group def query_all_groups(fields=nil, sorts=nil) req = { :per_page=>128 } req[:fields] = fields if fields req[:sorts] = sorts if sorts data = Array.new page = 1 loop do begin req[:page] = page scratch_data = @sdk.all_groups(req).collect { |e| e.to_attrs } rescue LookerSDK::ClientError => e say_error "Unable to get all_groups(#{JSON.pretty_generate(req)})" say_error e raise end break if scratch_data.length == 0 page += 1 data += scratch_data end data end def query_group_groups(group_id,fields=nil) req = { } req[:fields] = fields if fields begin @sdk.all_group_groups(group_id,req).collect { |e| e.to_attrs } rescue LookerSDK::NotFound => e return [] rescue LookerSDK::ClientError => e say_error "Unable to get all_group_groups(#{group_id},#{JSON.pretty_generate(req)})" say_error e raise end end def query_group_users(group_id,fields=nil,sorts=nil) req = { :per_page=>128 } req[:fields] = fields if fields req[:sorts] = sorts if sorts data = Array.new page = 1 loop do begin req[:page] = page scratch_data = @sdk.all_group_users(group_id,req).collect { |e| e.to_attrs } rescue LookerSDK::ClientError => e say_error "Unable to get all_group_users(#{group_id},#{JSON.pretty_generate(req)})" say_error e raise end break if scratch_data.length == 0 page += 1 data += scratch_data end data end def search_groups(name) req = {:name => name } begin return @sdk.search_groups(req).collect { |e| e.to_attrs } rescue LookerSDK::NotFound => e return [] rescue LookerSDK::ClientError => e say_error "Unable to search_groups(#{JSON.pretty_generate(req)})" say_error e raise end end def query_group(id, fields=nil) req = Hash.new req[:fields] = fields if fields begin return @sdk.group(id,req).to_attrs rescue LookerSDK::NotFound => e return nil rescue LookerSDK::ClientError => e say_error "Unable to find group(#{id},#{JSON.pretty_generate(req)})" say_error e raise end end def update_user_attribute_group_value(group_id, attr_id, value) req = Hash.new req[:value] = value begin return @sdk.update_user_attribute_group_value(group_id,attr_id, req).to_attrs rescue LookerSDK::ClientError => e say_error "Unable to update_user_attribute_group_value(#{group_id},#{attr_id},#{JSON.pretty_generate(req)})" say_error e raise end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/modules/dashboard.rb
lib/gzr/modules/dashboard.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require_relative 'alert' module Gzr module Dashboard include Gzr::Alert def query_dashboard(dashboard_id) data = nil begin data = @sdk.dashboard(dashboard_id).to_attrs data[:dashboard_filters]&.sort! { |a,b| a[:row] <=> b[:row] } data[:dashboard_layouts]&.sort_by! { |v| (v[:active] ? 0 : 1) } rescue LookerSDK::Error => e say_error "dashboard #{dashboard_id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error querying dashboard(#{dashboard_id})" say_error e raise end data end def delete_dashboard(dash) begin @sdk.delete_dashboard(dash) rescue LookerSDK::Error => e say_error "dashboard #{dash} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting dashboard(#{dash})" say_error e raise end end def search_dashboards_by_slug(slug, folder_id=nil) data = [] begin req = { :slug => slug } req[:folder_id] = folder_id if folder_id data = @sdk.search_dashboards(req).collect { |e| e.to_attrs } req[:deleted] = true data = @sdk.search_dashboards(req).collect { |e| e.to_attrs } if data.empty? rescue LookerSDK::Error => e say_error "Error search_dashboards_by_slug(#{JSON.pretty_generate(req)})" say_error e raise end data end def search_dashboards_by_title(title, folder_id=nil) data = [] begin req = { :title => title } req[:folder_id] = folder_id if folder_id data = @sdk.search_dashboards(req).collect { |e| e.to_attrs } req[:deleted] = true data = @sdk.search_dashboards(req).collect { |e| e.to_attrs } if data.empty? rescue LookerSDK::Error => e say_error "Error search_dashboards_by_title(#{JSON.pretty_generate(req)})" say_error e raise end data end def create_dashboard(dash) data = nil begin data = @sdk.create_dashboard(dash).to_attrs say_error data.inspect if data.respond_to?(:message) data[:dashboard_filters]&.sort! { |a,b| a[:row] <=> b[:row] } data[:dashboard_layouts]&.sort_by! { |v| (v[:active] ? 0 : 1) } rescue LookerSDK::Error => e say_error "Error creating dashboard(#{JSON.pretty_generate(dash)})" say_error e raise end data end def update_dashboard(dash_id,dash) data = nil begin data = @sdk.update_dashboard(dash_id,dash).to_attrs data[:dashboard_filters]&.sort! { |a,b| a[:row] <=> b[:row] } rescue LookerSDK::NotFound => e say_error "dashboard #{dash_id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating dashboard(#{dash_id},#{JSON.pretty_generate(dash)})" say_error e raise end data end def create_dashboard_element(dash_elem) begin @sdk.create_dashboard_element(dash_elem).to_attrs rescue LookerSDK::Error => e say_error "Error creating dashboard_element(#{JSON.pretty_generate(dash_elem)})" say_error e raise end end def update_dashboard_element(id,dash_elem) begin @sdk.update_dashboard_element(id,dash_elem).to_attrs rescue LookerSDK::NotFound => e say_error "dashboard_element #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating dashboard_element(#{id},#{JSON.pretty_generate(dash_elem)})" say_error e raise end end def delete_dashboard_element(id) begin @sdk.delete_dashboard_element(id) rescue LookerSDK::NotFound => e say_error "dashboard_element #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting dashboard_element(#{id})})" say_error e raise end end def get_dashboard_layout(id) begin @sdk.dashboard_layout(id).to_attrs rescue LookerSDK::NotFound => e say_error "dashboard_layout #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error getting dashboard_layout(#{id})" say_error e raise end end def create_dashboard_layout(dash_layout) begin @sdk.create_dashboard_layout(dash_layout).to_attrs rescue LookerSDK::Error => e say_error "Error creating dashboard_layout(#{JSON.pretty_generate(dash_layout)})" say_error e raise end end def update_dashboard_layout(id,dash_layout) begin @sdk.update_dashboard_layout(id,dash_layout).to_attrs rescue LookerSDK::NotFound => e say_error "dashboard_layout #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating dashboard_layout(#{id},#{JSON.pretty_generate(dash_layout)})" say_error e raise end end def delete_dashboard_layout(id) begin @sdk.delete_dashboard_layout(id) rescue LookerSDK::NotFound => e say_error "dashboard_layout #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting dashboard_layout(#{id})" say_error e raise end end def get_all_dashboard_layout_components(id) begin @sdk.dashboard_layout_dashboard_layout_components(id).collect { |e| e.to_attrs } rescue LookerSDK::NotFound => e say_error "dashboard_layout #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error getting dashboard_layout_dashboard_layout_components(#{id})" say_error e raise end end def update_dashboard_layout_component(id,component) begin @sdk.update_dashboard_layout_component(id,component).to_attrs rescue LookerSDK::NotFound => e say_error "dashboard_layout #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating dashboard_layout_component(#{id},#{JSON.pretty_generate(component)})" say_error e raise end end def create_dashboard_filter(dash_filter) begin @sdk.create_dashboard_filter(dash_filter).to_attrs rescue LookerSDK::Error => e say_error "Error creating dashboard_filter(#{JSON.pretty_generate(dash_filter)})" say_error e raise end end def update_dashboard_filter(id,dash_filter) begin @sdk.update_dashboard_filter(id,dash_filter).to_attrs rescue LookerSDK::NotFound => e say_error "dashboard_filter #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating dashboard_filter(#{id},#{JSON.pretty_generate(dash_filter)})" say_error e raise end end def delete_dashboard_filter(id) begin @sdk.delete_dashboard_filter(id) rescue LookerSDK::NotFound => e say_error "dashboard_filter #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting dashboard_filter(#{id})})" say_error e raise end end def cat_dashboard(dashboard_id) data = query_dashboard(dashboard_id) data[:dashboard_elements].each_index do |i| element = data[:dashboard_elements][i] find_vis_config_reference(element) do |vis_config| find_color_palette_reference(vis_config) do |o,default_colors| rewrite_color_palette!(o,default_colors) end end alerts = [] begin alerts = search_alerts(fields: 'id,dashboard_element_id', group_by: 'dashboard', all_owners: true) rescue LookerSDK::Forbidden => e say_warning "Must be an admin user to look up all alerts" begin alerts = search_alerts(fields: 'id,dashboard_element_id', group_by: 'dashboard') rescue LookerSDK::Error => e say_warning "Error looking up alerts owned by user." end end say_warning alerts if @options[:debug] data[:dashboard_elements].each do |e| alerts_found = alerts.select { |a| a[:dashboard_element_id] == e[:id]} say_warning "Found alerts #{alerts_found}" if @options[:debug] alerts_entries = alerts_found.map { |a| get_alert(a[:id]) } say_warning "Looked up alerts entries #{alerts_entries}" if @options[:debug] e[:alerts] = alerts_entries end merge_result = merge_query(element[:merge_result_id])&.to_attrs if element[:merge_result_id] if merge_result merge_result[:source_queries].each_index do |j| source_query = merge_result[:source_queries][j] merge_result[:source_queries][j][:query] = query(source_query[:query_slug] || source_query[:query_id]).to_attrs end find_vis_config_reference(merge_result) do |vis_config| find_color_palette_reference(vis_config) do |o,default_colors| rewrite_color_palette!(o,default_colors) end end data[:dashboard_elements][i][:merge_result] = merge_result end end data[:scheduled_plans] = query_scheduled_plans_for_dashboard(@dashboard_id,"all") if @options[:plans] data end def trim_dashboard(data) trimmed = data.select do |k,v| (keys_to_keep('update_dashboard') + [:id,:dashboard_elements,:dashboard_filters,:dashboard_layouts,:scheduled_plans]).include? k end trimmed[:dashboard_elements] = data[:dashboard_elements].map do |de| new_de = de.select do |k,v| (keys_to_keep('update_dashboard_element') + [:id,:look,:query,:merge_result,:alerts]).include? k end if de[:look] new_de[:look] = de[:look].select do |k,v| (keys_to_keep('update_look') + [:id,:query]).include? k end if de[:look][:query] new_de[:look][:query] = de[:look][:query].select do |k,v| (keys_to_keep('create_query') + [:id]).include? k end end end if de[:query] new_de[:query] = de[:query].select do |k,v| (keys_to_keep('create_query') + [:id]).include? k end end if de[:merge_result] new_de[:merge_result] = de[:merge_result].select do |k,v| (keys_to_keep('update_merge_query') + [:id]).include? k end new_de[:merge_result][:source_queries] = de[:merge_result][:source_queries].map do |sq| sq.select do |k,v| (keys_to_keep('create_query') + [:id]).include? k end end end if de[:alerts] new_de[:alerts] = de[:alerts].map do |a| a.select do |k,v| (keys_to_keep('update_alert') + [:id,:owner]).include? k end end end new_de end trimmed[:dashboard_filters] = data[:dashboard_filters].map do |df| new_df = df.select do |k,v| keys_to_keep('update_dashboard_filter').include? k end new_df end trimmed[:dashboard_layouts] = data[:dashboard_layouts].map do |dl| new_dl = dl.select do |k,v| (keys_to_keep('update_dashboard_layout') + [:id]).include? k end if dl[:dashboard_layout_components] new_dl[:dashboard_layout_components] = dl[:dashboard_layout_components].map do |dlc| dlc.select do |k,v| (keys_to_keep('update_dashboard_layout_component') + [:id]).include? k end end end new_dl end trimmed[:scheduled_plans] = data[:scheduled_plans].map do |sp| sp.select do |k,v| (keys_to_keep('create_scheduled_plan') + [:id]).include? k end end if data[:scheduled_plans] trimmed end def import_lookml_dashboard(id,folder) begin return @sdk.import_lookml_dashboard(id,folder).to_attrs rescue LookerSDK::NotFound => e say_error "lookml_dashboard #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error import_lookml_dashboard(#{id},#{folder})" say_error e raise end end def sync_lookml_dashboard(id) begin return @sdk.sync_lookml_dashboard(id, {}) rescue LookerSDK::NotFound => e say_error "lookml_dashboard #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error sync_lookml_dashboard(#{id})" say_error e raise end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/modules/attribute.rb
lib/gzr/modules/attribute.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true module Gzr module Attribute def query_user_attribute(attr_id,fields=nil) begin req = {} req[:fields] = fields if fields @sdk.user_attribute(attr_id,req).to_attrs rescue LookerSDK::NotFound => e say_error "User_attribute #{attr_id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error querying user_attribute(#{attr_id},#{JSON.pretty_generate(req)})" say_error e raise end end def query_all_user_attributes(fields=nil, sorts=nil) begin req = {} req[:fields] = fields if fields req[:sorts] = sorts if sorts @sdk.all_user_attributes(req).collect { |a| a.to_attrs } rescue LookerSDK::NotFound => e [] rescue LookerSDK::Error => e say_error "Error querying all_user_attributes(#{JSON.pretty_generate(req)})" say_error e raise end end def get_attribute_by_name(name, fields = nil) data = query_all_user_attributes(fields).select {|a| a[:name] == name} return nil if data.empty? data.first end def get_attribute_by_label(label, fields = nil) data = query_all_user_attributes(fields).select {|a| a[:label] == label} return nil if data.empty? data.first end def create_attribute(attr) begin @sdk.create_user_attribute(attr).to_attrs rescue LookerSDK::Error => e say_error "Error creating user_attribute(#{JSON.pretty_generate(attr)})" say_error e raise end end def update_attribute(id,attr) begin @sdk.update_user_attribute(id,attr).to_attrs rescue LookerSDK::NotFound => e say_error "user_attribute #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating user_attribute(#{id},#{JSON.pretty_generate(attr)})" say_error e raise end end def delete_user_attribute(id) begin @sdk.delete_user_attribute(id) rescue LookerSDK::NotFound => e say_error "user_attribute #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting user_attribute(#{id})" say_error e raise end end def query_all_user_attribute_group_values(attr_id, fields=nil) begin req = {} req[:fields] = fields if fields return @sdk.all_user_attribute_group_values(attr_id,req).collect { |v| v.to_attrs } rescue LookerSDK::NotFound => e return nil rescue LookerSDK::Error => e say_error "Error querying all_user_attribute_group_values(#{attr_id},#{JSON.pretty_generate(req)})" say_error e raise end end def query_user_attribute_group_value(group_id, attr_id) data = query_all_user_attribute_group_values(attr_id)&.select {|a| a[:group_id] == group_id} return nil if data.nil? || data.empty? data.first end def upsert_user_attribute(source, force=false, output: $stdout) name_used = get_attribute_by_name(source[:name]) if name_used raise(Gzr::CLI::Error, "Attribute #{source[:name]} already exists and can't be modified") if name_used[:is_system] raise(Gzr::CLI::Error, "Attribute #{source[:name]} already exists\nUse --force if you want to overwrite it") unless @options[:force] end label_used = get_attribute_by_label(source[:label]) if label_used raise(Gzr::CLI::Error, "Attribute with label #{source[:label]} already exists and can't be modified") if label_used[:is_system] raise(Gzr::CLI::Error, "Attribute with label #{source[:label]} already exists\nUse --force if you want to overwrite it") unless force end existing = name_used || label_used if existing upd_attr = source.select do |k,v| keys_to_keep('update_user_attribute').include?(k) && !(name_used[k] == v) end return update_attribute(existing[:id],upd_attr) else new_attr = source.select do |k,v| (keys_to_keep('create_user_attribute') - [:hidden_value_domain_whitelist]).include? k end new_attr[:hidden_value_domain_whitelist] = source[:hidden_value_domain_allowlist] if source[:value_is_hidden] && source[:hidden_value_domain_allowlist] return create_attribute(new_attr) end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/modules/plan.rb
lib/gzr/modules/plan.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true module Gzr module Plan def query_all_scheduled_plans(user_id,fields=nil) req = {} req[:all_users] = true if user_id == "all" req[:user_id] = user_id if user_id && !(user_id == "all") req[:fields] = fields if fields begin @sdk.all_scheduled_plans(req).collect { |p| p.to_attrs } rescue LookerSDK::NotFound => e return [] rescue LookerSDK::Error => e say_error "Unable to get all_scheduled_plans(#{JSON.pretty_generate(req)})" say_error e raise end end def query_scheduled_plans_for_look(look_id,user_id,fields=nil) req = {} req[:all_users] = true if user_id == "all" req[:user_id] = user_id if user_id && !(user_id == "all") req[:fields] = fields if fields begin @sdk.scheduled_plans_for_look(look_id,req).collect { |p| p.to_attrs } rescue LookerSDK::NotFound => e return [] rescue LookerSDK::Error => e say_error "Unable to get scheduled_plans_for_look(#{look_id},#{JSON.pretty_generate(req)})" say_error e raise end end def query_scheduled_plans_for_dashboard(dashboard_id,user_id,fields=nil) req = {} req[:all_users] = true if user_id == "all" req[:user_id] = user_id if user_id && !(user_id == "all") req[:fields] = fields if fields begin @sdk.scheduled_plans_for_dashboard(dashboard_id,req).collect { |p| p.to_attrs } rescue LookerSDK::NotFound return [] rescue LookerSDK::Error => e say_error "Unable to get scheduled_plans_for_dashboard(#{dashboard_id},#{JSON.pretty_generate(req)})" say_error e raise end end def query_scheduled_plan(plan_id,fields=nil) req = {} req[:fields] = fields if fields begin @sdk.scheduled_plan(plan_id,req).to_attrs rescue LookerSDK::NotFound return nil rescue LookerSDK::Error => e say_error "Unable to get scheduled_plan(#{plan_id},#{JSON.pretty_generate(req)})" say_error e raise end end def delete_scheduled_plan(plan_id) begin @sdk.delete_scheduled_plan(plan_id) rescue LookerSDK::NotFound say_error "delete_scheduled_plan(#{plan_id}) not found" say_error e raise rescue LookerSDK::Error => e say_error "Unable to delete scheduled_plan(#{plan_id})" say_error e raise end end def create_scheduled_plan(plan) begin @sdk.create_scheduled_plan(plan).to_attrs rescue LookerSDK::Error => e say_error "Error creating scheduled_plan(#{JSON.pretty_generate(plan)})" say_error e raise end end def update_scheduled_plan(plan_id,plan) begin @sdk.update_scheduled_plan(plan_id,plan).to_attrs rescue LookerSDK::NotFound say_error "update_scheduled_plan(#{plan_id},#{JSON.pretty_generate(plan)}) not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating scheduled_plan(#{plan_id},#{JSON.pretty_generate(plan)})" say_error e raise end end def run_scheduled_plan(plan) begin @sdk.scheduled_plan_run_once(plan) rescue LookerSDK::NotFound say_error "scheduled_plan_run_once(#{plan_id}) not found" say_error e raise rescue LookerSDK::Error => e say_error "Error executing scheduled_plan_run_once(#{JSON.pretty_generate(plan)})" say_error e raise end end def upsert_plans_for_look(look_id,user_id,source_plans) existing_plans = query_scheduled_plans_for_look(look_id,"all") upsert_plans_for_obj(user_id,source_plans,existing_plans) { |p| p[:look_id] = look_id } end def upsert_plans_for_dashboard(dashboard_id,user_id,source_plans) existing_plans = query_scheduled_plans_for_dashboard(dashboard_id,"all") upsert_plans_for_obj(user_id,source_plans,existing_plans) { |p| p[:dashboard_id] = dashboard_id } end def upsert_plan_for_look(look_id,user_id,source_plan) existing_plans = query_scheduled_plans_for_look(look_id,"all") upsert_plan_for_obj(user_id,source_plan,existing_plans) { |p| p[:look_id] = look_id } end def upsert_plan_for_dashboard(dashboard_id,user_id,source_plan) existing_plans = query_scheduled_plans_for_dashboard(dashboard_id,"all") upsert_plan_for_obj(user_id,source_plan,existing_plans) { |p| p[:dashboard_id] = dashboard_id } end def upsert_plans_for_obj(user_id,source_plans,existing_plans, &block) plans = nil source_plans.collect do |source_plan| plans = upsert_plan_for_obj(user_id, source_plan, existing_plans, &block) end return nil unless plans.length > 0 plans.first end def upsert_plan_for_obj(user_id, source_plan, existing_plans) matches = existing_plans.select { |p| p[:name] == source_plan[:name] && user_id == p[:user_id] } if matches.length > 0 then say_ok "Modifying existing plan #{matches.first[:id]} #{matches.first[:name]}" plan = keys_to_keep('update_scheduled_plan').collect do |e| [e,nil] end.to_h plan.merge!( source_plan.select do |k,v| (keys_to_keep('update_scheduled_plan') - [:plan_id,:look_id,:dashboard_id,:user_id,:dashboard_filters,:lookml_dashboard_id,:scheduled_plan_destination]).include? k end) plan[:scheduled_plan_destination] = source_plan[:scheduled_plan_destination].collect do |p| p.reject do |k,v| [:id,:scheduled_plan_id,:looker_recipient,:can].include? k end end plan[:user_id] = user_id plan[:enabled] = true if @options[:enabled] plan[:enabled] = false if @options[:disabled] plan[:enabled] = false if plan[:enabled].nil? plan[:require_results] = false if plan[:require_results].nil? plan[:require_no_results] = false if plan[:require_no_results].nil? plan[:require_change] = false if plan[:require_change].nil? plan[:send_all_results] = false if plan[:send_all_results].nil? plan[:run_once] = false if plan[:run_once].nil? plan[:include_links] = false if plan[:include_links].nil? yield plan update_scheduled_plan(matches.first[:id],plan) else plan = source_plan.select do |k,v| (keys_to_keep('create_scheduled_plan') - [:plan_id,:dashboard_id,:user_id,:dashboard_filters,:lookml_dashboard_id,:scheduled_plan_destination]).include? k end plan[:scheduled_plan_destination] = source_plan[:scheduled_plan_destination].collect do |p| p.reject do |k,v| [:id,:scheduled_plan_id,:looker_recipient,:can].include? k end end yield plan plan[:enabled] = true if @options[:enabled] plan[:enabled] = false if @options[:disabled] plan[:enabled] = false if plan[:enabled].nil? plan[:require_results] = false if plan[:require_results].nil? plan[:require_no_results] = false if plan[:require_no_results].nil? plan[:require_change] = false if plan[:require_change].nil? plan[:send_all_results] = false if plan[:send_all_results].nil? plan[:run_once] = false if plan[:run_once].nil? plan[:include_links] = false if plan[:include_links].nil? create_scheduled_plan(plan) end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/modules/filehelper.rb
lib/gzr/modules/filehelper.rb
# The MIT License (MIT) # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true require 'pathname' require 'rubygems/package' require 'stringio' module Gzr module FileHelper def write_file(file_name=nil,base_dir=nil,path=nil,output=$stdout) f = nil if base_dir.respond_to?(:mkdir)&& (base_dir.respond_to?(:add_file) || base_dir.respond_to?(:get_output_stream)) then if path then @archived_paths ||= Array.new begin base_dir.mkdir(path.to_path, 0755) unless @archived_paths.include?(path.to_path) rescue Errno::EEXIST => e nil end @archived_paths << path.to_path end fn = Pathname.new(file_name.gsub('/',"\u{2215}")) fn = path + fn if path if base_dir.respond_to?(:add_file) base_dir.add_file(fn.to_path, 0644) do |tf| yield tf end elsif base_dir.respond_to?(:get_output_stream) base_dir.get_output_stream(fn.to_path, 0644) do |zf| yield zf end end return end base = Pathname.new(File.expand_path(base_dir)) if base_dir begin p = Pathname.new(path) if path p.descend do |path_part| test_dir = base + Pathname.new(path_part) Dir.mkdir(test_dir) unless (test_dir.exist? && test_dir.directory?) end if p file = Pathname.new(file_name.gsub('/',"\u{2215}").gsub(':','')) if file_name file = p + file if p file = base + file if base f = File.open(file, "wt") if file end if base return ( f || output ) unless block_given? begin yield ( f || output ) ensure f.close if f end nil end def read_file(file_name) file = nil data_hash = nil begin file = (file_name.kind_of? StringIO) ? file_name : File.open(file_name) data_hash = JSON.parse(file.read,{:symbolize_names => true}) ensure file.close if file end return (data_hash || {}) unless block_given? yield data_hash || {} end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false
looker-open-source/gzr
https://github.com/looker-open-source/gzr/blob/329fd27a33941ecabc87192a5460efdf34352806/lib/gzr/modules/connection.rb
lib/gzr/modules/connection.rb
# The MIT License (MIT) # Copyright (c) 2023 Mike DeAngelo Google, Inc. # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of # the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # frozen_string_literal: true module Gzr module Connection def query_all_connections(fields=nil) begin @sdk.all_connections(fields ? {:fields=>fields} : nil ).collect { |e| e.to_attrs } rescue LookerSDK::Error => e say_error "Error querying all_connections({:fields=>\"#{fields}\"})" say_error e raise end end def query_all_dialects(fields=nil) begin @sdk.all_dialect_infos(fields ? {:fields=>fields} : nil ).collect { |e| e.to_attrs } rescue LookerSDK::Error => e say_error "Error querying all_dialect_infos({:fields=>\"#{fields}\"})" say_error e raise end end def test_connection(name, tests=nil) if tests.nil? connection = cat_connection(name) return nil if connection.nil? tests = connection[:dialect][:connection_tests] end begin @sdk.test_connection(name, {}, tests: tests).collect { |e| e.to_attrs } rescue LookerSDK::NotFound => e return [] rescue LookerSDK::Error => e say_error "Error executing test_connection(#{name},#{tests})" say_error e raise end end def delete_connection(name) begin @sdk.delete_connection(name) rescue LookerSDK::NotFound => e say_warning "Connection #{name} not found" rescue LookerSDK::Error => e say_error "Error executing delete_connection(#{name})" say_error e raise end end def create_connection(body) begin @sdk.create_connection(body).to_attrs rescue LookerSDK::Error => e say_error "Error executing create_connection(#{JSON.pretty_generate(body)})" say_error e raise end end def update_connection(name,body) begin @sdk.update_connection(name,body).to_attrs rescue LookerSDK::NotFound => e say_warning "Connection #{name} not found" rescue LookerSDK::Error => e say_error "Error executing update_connection(#{name},#{JSON.pretty_generate(body)})" say_error e raise end end def cat_connection(name) begin @sdk.connection(name).to_attrs rescue LookerSDK::NotFound => e nil rescue LookerSDK::Error => e say_error "Error executing connection(#{name})" say_error e raise end end def trim_connection(data) data.select do |k,v| (keys_to_keep('create_connection') + [:pdt_context_override]).include? k end end end end
ruby
MIT
329fd27a33941ecabc87192a5460efdf34352806
2026-01-04T17:49:18.520281Z
false