From 7b94a7962d36d865759b105b481f602aac87523e Mon Sep 17 00:00:00 2001 From: "Dr. Strangelove" Date: Tue, 9 May 2023 13:37:28 -0400 Subject: [PATCH] feat: dashboard sync_lookml to sync UDDs with their associated lookml dashboards (#194) --- lib/gzr/commands/dashboard.rb | 12 ++++++ lib/gzr/commands/dashboard/sync_lookml.rb | 52 +++++++++++++++++++++++ lib/gzr/modules/dashboard.rb | 10 +++++ 3 files changed, 74 insertions(+) create mode 100644 lib/gzr/commands/dashboard/sync_lookml.rb diff --git a/lib/gzr/commands/dashboard.rb b/lib/gzr/commands/dashboard.rb index dd95366..689e60f 100644 --- a/lib/gzr/commands/dashboard.rb +++ b/lib/gzr/commands/dashboard.rb @@ -112,6 +112,18 @@ def import_lookml(dashboard_id, target_folder_id) Gzr::Commands::Dashboard::ImportLookml.new(dashboard_id, target_folder_id, options).execute end end + + desc 'sync_lookml DASHBOARD_ID', 'Sync any UDD from a lookml dashboard' + method_option :help, aliases: '-h', type: :boolean, + desc: 'Display usage information' + def sync_lookml(dashboard_id) + if options[:help] + invoke :help, ['sync_lookml'] + else + require_relative 'dashboard/sync_lookml' + Gzr::Commands::Dashboard::SyncLookml.new(dashboard_id, options).execute + end + end end end end diff --git a/lib/gzr/commands/dashboard/sync_lookml.rb b/lib/gzr/commands/dashboard/sync_lookml.rb new file mode 100644 index 0000000..05faa45 --- /dev/null +++ b/lib/gzr/commands/dashboard/sync_lookml.rb @@ -0,0 +1,52 @@ +# 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 diff --git a/lib/gzr/modules/dashboard.rb b/lib/gzr/modules/dashboard.rb index e273002..72a5417 100644 --- a/lib/gzr/modules/dashboard.rb +++ b/lib/gzr/modules/dashboard.rb @@ -364,5 +364,15 @@ def import_lookml_dashboard(id,folder) raise end end + + def sync_lookml_dashboard(id) + begin + return @sdk.sync_lookml_dashboard(id, {}) + rescue LookerSDK::Error => e + say_error "Error sync_lookml_dashboard(#{id})" + say_error e + raise + end + end end end