gazer 0.3.6 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81947b24215954962cc0a753f2f021ab1b2bc23c59be970f48ba3f756b893521
4
- data.tar.gz: 5b7017d8e67c99e807f6cf2efb93cc6e02371b37b4db00b7467e1afc8cef6fe6
3
+ metadata.gz: 166d9eef0212c5bd6a896a1351e5bfc6953bbd92853fed3903c86e54d4653186
4
+ data.tar.gz: '086fcc08489ca7155f76c04dbed03bef703b4e3ec67fe5b10a2daf1df9581781'
5
5
  SHA512:
6
- metadata.gz: 589e1fd671e6b81f21c65817bef12ab70527818516712689b541700718ebe59a142f172e3a79c1d412597d999ccbbd5f72b9e64c884a41e8aa3b7854847ba2d1
7
- data.tar.gz: 12cf46f870a08ecc57e005843fa6fa6c5fb29c16c5713c20c28a0e3a05be326ca3147cf03d62846f80abb4a81b798a40f27bb3afbc1fc8b0dfabeaa636eb57ad
6
+ metadata.gz: c773b741bf66c92a8b9892278f99813c2fb4a2597a565aab43ab1d512ce52abfda28030180277ec61d43db02de5cd36895e394057b8c855b9ebda559729482c2
7
+ data.tar.gz: 38d00674ecc4c7c6900e9a59ff0a770039ce9d3703e378532d1ef68f83d1f1ca064d6cbf26d1f3b64cf17fa46c939ddc89a01f6e920886dfea50ab2665f3bb0b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.8](https://github.com/looker-open-source/gzr/compare/v0.3.7...v0.3.8) (2023-05-16)
4
+
5
+
6
+ ### Features
7
+
8
+ * create role command ([#204](https://github.com/looker-open-source/gzr/issues/204)) ([cba4a80](https://github.com/looker-open-source/gzr/commit/cba4a803af8298915ca0e2189919d542bfd9f982))
9
+ * management of model sets ([#200](https://github.com/looker-open-source/gzr/issues/200)) ([1b964ca](https://github.com/looker-open-source/gzr/commit/1b964ca25cf7eb55ff211dab6ae48c174ad3f4b6))
10
+ * Permission Set management ([#203](https://github.com/looker-open-source/gzr/issues/203)) ([ef7355c](https://github.com/looker-open-source/gzr/commit/ef7355c41234928996540f2c6ed50ba358e197b7))
11
+ * show available permissions in tree format ([#202](https://github.com/looker-open-source/gzr/issues/202)) ([c702a64](https://github.com/looker-open-source/gzr/commit/c702a64a5247fb151b155d1c6d1116cb20cccc0f))
12
+
13
+ ## [0.3.7](https://github.com/looker-open-source/gzr/compare/v0.3.6...v0.3.7) (2023-05-10)
14
+
15
+
16
+ ### Features
17
+
18
+ * option to sync lookml dashboard on import_lookml if it exists already ([#196](https://github.com/looker-open-source/gzr/issues/196)) ([c8ec619](https://github.com/looker-open-source/gzr/commit/c8ec619186c6a0ce81633d701f78444f4e488a5b))
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * Update connection calling wrong API method ([#197](https://github.com/looker-open-source/gzr/issues/197)) ([e122b47](https://github.com/looker-open-source/gzr/commit/e122b47fca9f2ff218cff0904c147cf94d54fe69))
24
+
3
25
  ## [0.3.6](https://github.com/looker-open-source/gzr/compare/v0.3.5...v0.3.6) (2023-05-09)
4
26
 
5
27
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gazer (0.3.6)
4
+ gazer (0.3.8)
5
5
  faraday (~> 1.10.3)
6
6
  looker-sdk (~> 0.1.1)
7
7
  net-http-persistent (~> 4.0, >= 4.0.1)
data/lib/gzr/cli.rb CHANGED
@@ -45,7 +45,6 @@ module Gzr
45
45
  class_option :force, type: :boolean, default: false, desc: 'Overwrite objects on server'
46
46
  class_option :su, type: :string, desc: 'After connecting, change to user_id given'
47
47
  class_option :width, type: :numeric, default: nil, desc: 'Width of rendering for tables'
48
- class_option :persistent, type: :boolean, default: false, desc: 'Use persistent connection to communicate with host'
49
48
  class_option :token, type: :string, default: nil, desc: "Access token to use for authentication"
50
49
  class_option :token_file, type: :boolean, default: false, desc: "Use access token stored in file for authentication"
51
50
 
@@ -59,6 +58,8 @@ module Gzr
59
58
  end
60
59
  map %w(--version -v) => :version
61
60
  map space: :folder # Alias space command to folder
61
+ # map permissions: :permission # Alias permissions command to permission
62
+
62
63
 
63
64
  require_relative 'commands/alert'
64
65
  register Gzr::Commands::Alert, 'alert', 'alert [SUBCOMMAND]', 'Command description...'
@@ -66,8 +67,8 @@ module Gzr
66
67
  require_relative 'commands/attribute'
67
68
  register Gzr::Commands::Attribute, 'attribute', 'attribute [SUBCOMMAND]', 'Command description...'
68
69
 
69
- require_relative 'commands/permissions'
70
- register Gzr::Commands::Permissions, 'permissions', 'permissions [SUBCOMMAND]', 'Command to retrieve available permissions'
70
+ require_relative 'commands/permission'
71
+ register Gzr::Commands::Permission, 'permission', 'permission [SUBCOMMAND]', 'Command to retrieve available permission'
71
72
 
72
73
  require_relative 'commands/query'
73
74
  register Gzr::Commands::Query, 'query', 'query [SUBCOMMAND]', 'Commands to retrieve and run queries'
@@ -49,12 +49,19 @@ module Gzr
49
49
  matching_title = false
50
50
  end
51
51
 
52
- if matching_title
52
+ if matching_title && !(matching_title.first[:lookml_link_id] == @dashboard_id)
53
53
  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]
54
54
  say_ok "Deleting existing dashboard #{matching_title.first[:id]} #{matching_title.first[:title]} in folder #{@target_folder_id}", output: output
55
55
  update_dashboard(matching_title.first[:id],{:deleted=>true})
56
56
  end
57
57
 
58
+ if matching_title && (matching_title.first[:lookml_link_id] == @dashboard_id)
59
+ 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]
60
+ say_ok "Syncing existing dashboard #{matching_title.first[:id]} #{matching_title.first[:title]} in folder #{@target_folder_id}", output: output
61
+ output.puts sync_lookml_dashboard(@dashboard_id)
62
+ return
63
+ end
64
+
58
65
  new_dash = import_lookml_dashboard(@dashboard_id,@target_folder_id)
59
66
 
60
67
  if @options[:unlink]
@@ -104,6 +104,8 @@ module Gzr
104
104
  desc: 'Unlink the new user defined dashboard from the LookML dashboard'
105
105
  method_option :force, type: :boolean,
106
106
  desc: 'Overwrite a dashboard with the same name in the target folder'
107
+ method_option :sync, type: :boolean,
108
+ desc: 'If linked dashboard already exists, sync it with LookML dashboard'
107
109
  def import_lookml(dashboard_id, target_folder_id)
108
110
  if options[:help]
109
111
  invoke :help, ['import_lookml']
@@ -0,0 +1,60 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, Inc.
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ # frozen_string_literal: true
23
+
24
+ require_relative '../../../command'
25
+ require_relative '../../../modules/model/set'
26
+ require_relative '../../../modules/filehelper'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Model
31
+ class Set
32
+ class Cat < Gzr::Command
33
+ include Gzr::Model::Set
34
+ include Gzr::FileHelper
35
+ def initialize(model_set_id,options)
36
+ super()
37
+ @model_set_id = model_set_id
38
+ @options = options
39
+ end
40
+
41
+ def execute(input: $stdin, output: $stdout)
42
+ say_warning(@options) if @options[:debug]
43
+ with_session do
44
+ data = cat_model_set(@model_set_id)
45
+ if data.nil?
46
+ say_warning "Model Set #{@model_set_id} not found"
47
+ return
48
+ end
49
+ data = trim_model_set(data) if @options[:trim]
50
+
51
+ write_file(@options[:dir] ? "Model_Set_#{data[:name]}.json" : nil, @options[:dir],nil, output) do |f|
52
+ f.puts JSON.pretty_generate(data)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,73 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, Inc.
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ # frozen_string_literal: true
23
+
24
+ require_relative '../../../../gzr'
25
+ require_relative '../../../command'
26
+ require_relative '../../../modules/model/set'
27
+ require_relative '../../../modules/filehelper'
28
+
29
+ module Gzr
30
+ module Commands
31
+ class Model
32
+ class Set
33
+ class Import < Gzr::Command
34
+ include Gzr::Model::Set
35
+ include Gzr::FileHelper
36
+ def initialize(file, options)
37
+ super()
38
+ @file = file
39
+ @options = options
40
+ end
41
+
42
+ def execute(input: $stdin, output: $stdout)
43
+ say_warning("options: #{@options.inspect}", output: output) if @options[:debug]
44
+ with_session do
45
+ model_set = nil
46
+
47
+ read_file(@file) do |data|
48
+ search_results = search_model_sets(name: data[:name])
49
+ if search_results && search_results.length == 1
50
+ name = data[:name]
51
+ if !@options[:force]
52
+ raise Gzr::CLI::Error, "Model Set #{name} already exists\nUse --force if you want to overwrite it"
53
+ end
54
+ data.select! do |k,v|
55
+ keys_to_keep('update_model_set').include? k
56
+ end
57
+ model_set = update_model_set(search_results.first[:id], data)
58
+ else
59
+ data.select! do |k,v|
60
+ keys_to_keep('create_model_set').include? k
61
+ end
62
+ model_set = create_model_set(data)
63
+ end
64
+ output.puts "Imported model set #{model_set[:id]}" unless @options[:plain]
65
+ output.puts model_set[:id] if @options[:name]
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,74 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, Inc.
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ # frozen_string_literal: true
23
+
24
+ require_relative '../../../command'
25
+ require_relative '../../../modules/model/set'
26
+ require 'tty-table'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Model
31
+ class Set
32
+ class Ls < Gzr::Command
33
+ include Gzr::Model::Set
34
+ def initialize(options)
35
+ super()
36
+ @options = options
37
+ end
38
+
39
+ def execute(input: $stdin, output: $stdout)
40
+ say_warning(@options) if @options[:debug]
41
+ with_session do
42
+ data = all_model_sets(@options[:fields])
43
+ begin
44
+ say_ok "No model sets found"
45
+ return nil
46
+ end unless data && data.length > 0
47
+
48
+ table_hash = Hash.new
49
+ fields = field_names(@options[:fields])
50
+ table_hash[:header] = fields unless @options[:plain]
51
+ expressions = fields.collect { |fn| field_expression(fn) }
52
+ table_hash[:rows] = data.map do |row|
53
+ expressions.collect do |e|
54
+ eval "row.#{e}"
55
+ end
56
+ end
57
+ table = TTY::Table.new(table_hash)
58
+ alignments = fields.collect do |k|
59
+ (k =~ /id$/) ? :right : :left
60
+ end
61
+ begin
62
+ if @options[:csv] then
63
+ output.puts render_csv(table)
64
+ else
65
+ output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width)
66
+ end
67
+ end if table
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,49 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, Inc.
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ # frozen_string_literal: true
23
+
24
+ require_relative '../../../command'
25
+ require_relative '../../../modules/model/set'
26
+
27
+ module Gzr
28
+ module Commands
29
+ class Model
30
+ class Set
31
+ class Delete < Gzr::Command
32
+ include Gzr::Model::Set
33
+ def initialize(model_set_id,options)
34
+ super()
35
+ @model_set_id = model_set_id
36
+ @options = options
37
+ end
38
+
39
+ def execute(input: $stdin, output: $stdout)
40
+ say_warning(@options) if @options[:debug]
41
+ with_session do
42
+ delete_model_set(@model_set_id)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,97 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, Inc.
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ # frozen_string_literal: true
23
+
24
+ require_relative '../subcommandbase'
25
+
26
+ module Gzr
27
+ module Commands
28
+ class Model
29
+ class Set < SubCommandBase
30
+
31
+ namespace :'model set'
32
+
33
+ desc 'ls', 'List the model sets in this server.'
34
+ method_option :help, aliases: '-h', type: :boolean,
35
+ desc: 'Display usage information'
36
+ method_option :fields, type: :string, default: 'id,name,models',
37
+ desc: 'Fields to display'
38
+ method_option :plain, type: :boolean, default: false,
39
+ desc: 'print without any extra formatting'
40
+ method_option :csv, type: :boolean, default: false,
41
+ desc: 'output in csv format per RFC4180'
42
+ def ls(*)
43
+ if options[:help]
44
+ invoke :help, ['ls']
45
+ else
46
+ require_relative 'set/ls'
47
+ Gzr::Commands::Model::Set::Ls.new(options).execute
48
+ end
49
+ end
50
+
51
+ desc 'cat MODEL_SET_ID', 'Output json information about a model set to screen or file'
52
+ method_option :help, aliases: '-h', type: :boolean,
53
+ desc: 'Display usage information'
54
+ method_option :dir, type: :string,
55
+ desc: 'Directory to store output file'
56
+ method_option :trim, type: :boolean,
57
+ desc: 'Trim output to minimal set of fields for later import'
58
+ def cat(model_set_id)
59
+ if options[:help]
60
+ invoke :help, ['cat']
61
+ else
62
+ require_relative 'set/cat'
63
+ Gzr::Commands::Model::Set::Cat.new(model_set_id,options).execute
64
+ end
65
+ end
66
+
67
+ desc 'import FILE', 'Import a model set from a file'
68
+ method_option :help, aliases: '-h', type: :boolean,
69
+ desc: 'Display usage information'
70
+ method_option :force, type: :boolean,
71
+ desc: 'Overwrite an existing model set'
72
+ method_option :plain, type: :boolean, default: false,
73
+ desc: 'print without any extra formatting'
74
+ def import(file)
75
+ if options[:help]
76
+ invoke :help, ['import']
77
+ else
78
+ require_relative 'set/import'
79
+ Gzr::Commands::Model::Set::Import.new(file, options).execute
80
+ end
81
+ end
82
+
83
+ desc 'rm MODEL_SET_ID', 'Delete the model_set given by MODEL_SET_ID'
84
+ method_option :help, aliases: '-h', type: :boolean,
85
+ desc: 'Display usage information'
86
+ def rm(model_set_id)
87
+ if options[:help]
88
+ invoke :help, ['delete']
89
+ else
90
+ require_relative 'set/rm'
91
+ Gzr::Commands::Model::Set::Delete.new(model_set_id,options).execute
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -27,6 +27,9 @@ module Gzr
27
27
  module Commands
28
28
  class Model < SubCommandBase
29
29
 
30
+ require_relative 'model/set'
31
+ register Gzr::Commands::Model::Set, 'set', 'set [SUBCOMMAND]', 'Commands pertaining to model sets'
32
+
30
33
  namespace :model
31
34
 
32
35
  desc 'ls', 'List the models in this server.'
@@ -22,16 +22,16 @@
22
22
  # frozen_string_literal: true
23
23
 
24
24
  require_relative '../../command'
25
- require_relative '../../modules/permissions'
25
+ require_relative '../../modules/permission'
26
26
  require 'tty-table'
27
27
 
28
28
  require_relative '../../command'
29
29
 
30
30
  module Gzr
31
31
  module Commands
32
- class Permissions
32
+ class Permission
33
33
  class Ls < Gzr::Command
34
- include Gzr::Permissions
34
+ include Gzr::Permission
35
35
  def initialize(options)
36
36
  super()
37
37
  @options = options
@@ -0,0 +1,60 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, Inc.
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ # frozen_string_literal: true
23
+
24
+ require_relative '../../../command'
25
+ require_relative '../../../modules/permission/set'
26
+ require_relative '../../../modules/filehelper'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Permission
31
+ class Set
32
+ class Cat < Gzr::Command
33
+ include Gzr::Permission::Set
34
+ include Gzr::FileHelper
35
+ def initialize(permission_set_id,options)
36
+ super()
37
+ @permission_set_id = permission_set_id
38
+ @options = options
39
+ end
40
+
41
+ def execute(input: $stdin, output: $stdout)
42
+ say_warning(@options) if @options[:debug]
43
+ with_session do
44
+ data = cat_permission_set(@permission_set_id)
45
+ if data.nil?
46
+ say_warning "Permission Set #{permission_set_id} not found"
47
+ return
48
+ end
49
+ data = trim_permission_set(data) if @options[:trim]
50
+
51
+ write_file(@options[:dir] ? "Permission_Set_#{data[:name]}.json" : nil, @options[:dir],nil, output) do |f|
52
+ f.puts JSON.pretty_generate(data)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,73 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, Inc.
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ # frozen_string_literal: true
23
+
24
+ require_relative '../../../../gzr'
25
+ require_relative '../../../command'
26
+ require_relative '../../../modules/permission/set'
27
+ require_relative '../../../modules/filehelper'
28
+
29
+ module Gzr
30
+ module Commands
31
+ class Permission
32
+ class Set
33
+ class Import < Gzr::Command
34
+ include Gzr::Permission::Set
35
+ include Gzr::FileHelper
36
+ def initialize(file, options)
37
+ super()
38
+ @file = file
39
+ @options = options
40
+ end
41
+
42
+ def execute(input: $stdin, output: $stdout)
43
+ say_warning("options: #{@options.inspect}", output: output) if @options[:debug]
44
+ with_session do
45
+ permission_set = nil
46
+
47
+ read_file(@file) do |data|
48
+ search_results = search_permission_sets(name: data[:name])
49
+ if search_results && search_results.length == 1
50
+ name = data[:name]
51
+ if !@options[:force]
52
+ raise Gzr::CLI::Error, "Permission Set #{name} already exists\nUse --force if you want to overwrite it"
53
+ end
54
+ data.select! do |k,v|
55
+ keys_to_keep('update_permission_set').include? k
56
+ end
57
+ permission_set = update_permission_set(search_results.first[:id], data)
58
+ else
59
+ data.select! do |k,v|
60
+ keys_to_keep('create_permission_set').include? k
61
+ end
62
+ permission_set = create_permission_set(data)
63
+ end
64
+ output.puts "Imported permission set #{permission_set[:id]}" unless @options[:plain]
65
+ output.puts permission_set[:id] if @options[:name]
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end