Skip to content

Commit

Permalink
feat: dashboard sync_lookml to sync UDDs with their associated lookml…
Browse files Browse the repository at this point in the history
… dashboards (#194)
  • Loading branch information
drstrangelooker authored May 9, 2023
1 parent b4d6c47 commit 7b94a79
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/gzr/commands/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 52 additions & 0 deletions lib/gzr/commands/dashboard/sync_lookml.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions lib/gzr/modules/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7b94a79

Please sign in to comment.