gazer 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ee219afcd17f3191d17c1f87ed6b6683beecc7210736fa9da4e5190bc9cab07
4
- data.tar.gz: 6982e0ee5cb893d2ef81e23987e7fe26f729f8c33bd417195c0d226dff01e4a4
3
+ metadata.gz: 166d9eef0212c5bd6a896a1351e5bfc6953bbd92853fed3903c86e54d4653186
4
+ data.tar.gz: '086fcc08489ca7155f76c04dbed03bef703b4e3ec67fe5b10a2daf1df9581781'
5
5
  SHA512:
6
- metadata.gz: 2e28feecde59cbe5d3dc3b0f0da26162bd057828d2e6c615cb0598ed834e2729770fa6d4fb1a2a2ffb7e4e80624adba886a1ef17aa7990df41f05baef8d84f5b
7
- data.tar.gz: d5688042b3437473cec0caed7e3521e1b38f10d22fee304cabfb01052c36a03a88269c16bb7b4338f74e401b2cc7470e4e169fa4c346d6efcd487893f36fc015
6
+ metadata.gz: c773b741bf66c92a8b9892278f99813c2fb4a2597a565aab43ab1d512ce52abfda28030180277ec61d43db02de5cd36895e394057b8c855b9ebda559729482c2
7
+ data.tar.gz: 38d00674ecc4c7c6900e9a59ff0a770039ce9d3703e378532d1ef68f83d1f1ca064d6cbf26d1f3b64cf17fa46c939ddc89a01f6e920886dfea50ab2665f3bb0b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
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
+
3
13
  ## [0.3.7](https://github.com/looker-open-source/gzr/compare/v0.3.6...v0.3.7) (2023-05-10)
4
14
 
5
15
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gazer (0.3.7)
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'
@@ -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
@@ -0,0 +1,78 @@
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 'tty-table'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Permission
31
+ class Set
32
+ class Ls < Gzr::Command
33
+ include Gzr::Permission::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_permission_sets(@options[:fields])
43
+ begin
44
+ say_ok "No permission 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
+ exp = eval "row.#{e}"
55
+ if exp.kind_of? Array
56
+ exp = exp.join "\n"
57
+ end
58
+ exp
59
+ end
60
+ end
61
+ table = TTY::Table.new(table_hash)
62
+ alignments = fields.collect do |k|
63
+ (k =~ /id$/) ? :right : :left
64
+ end
65
+ begin
66
+ if @options[:csv] then
67
+ output.puts render_csv(table)
68
+ else
69
+ output.puts table.render(if @options[:plain] then :basic else :ascii end, multiline: !@options[:plain], alignments: alignments, width: @options[:width] || TTY::Screen.width)
70
+ end
71
+ end if table
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end