gazer 0.3.7 → 0.3.9

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/p3-issue-label.yml +21 -0
  3. data/.github/workflows/ruby-ci.yml +145 -2
  4. data/.github/workflows/triage-issue-label.yml +20 -0
  5. data/CHANGELOG.md +17 -0
  6. data/Gemfile.lock +1 -1
  7. data/examples/Dashboard_17_FAA_KPIs.json +687 -0
  8. data/examples/add_project.sh +151 -0
  9. data/lib/gzr/cli.rb +4 -3
  10. data/lib/gzr/commands/model/import.rb +18 -5
  11. data/lib/gzr/commands/model/set/cat.rb +60 -0
  12. data/lib/gzr/commands/model/set/import.rb +73 -0
  13. data/lib/gzr/commands/model/set/ls.rb +74 -0
  14. data/lib/gzr/commands/model/set/rm.rb +49 -0
  15. data/lib/gzr/commands/model/set.rb +97 -0
  16. data/lib/gzr/commands/model.rb +5 -0
  17. data/lib/gzr/commands/{permissions → permission}/ls.rb +3 -3
  18. data/lib/gzr/commands/permission/set/cat.rb +60 -0
  19. data/lib/gzr/commands/permission/set/import.rb +73 -0
  20. data/lib/gzr/commands/permission/set/ls.rb +78 -0
  21. data/lib/gzr/commands/permission/set/rm.rb +49 -0
  22. data/lib/gzr/commands/permission/set.rb +98 -0
  23. data/lib/gzr/commands/permission/tree.rb +71 -0
  24. data/lib/gzr/commands/{permissions.rb → permission.rb} +22 -6
  25. data/lib/gzr/commands/role/cat.rb +4 -3
  26. data/lib/gzr/commands/role/create.rb +51 -0
  27. data/lib/gzr/commands/role.rb +19 -1
  28. data/lib/gzr/commands/subcommandbase.rb +2 -2
  29. data/lib/gzr/modules/model/set.rb +123 -0
  30. data/lib/gzr/modules/model.rb +10 -0
  31. data/lib/gzr/modules/permission/set.rb +123 -0
  32. data/lib/gzr/modules/{permissions.rb → permission.rb} +1 -1
  33. data/lib/gzr/modules/role.rb +23 -0
  34. data/lib/gzr/version.rb +1 -1
  35. metadata +23 -5
@@ -0,0 +1,151 @@
1
+ #! /bin/bash
2
+
3
+ # The MIT License (MIT)
4
+
5
+ # Copyright (c) 2023 Mike DeAngelo Google, Inc.
6
+
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
8
+ # this software and associated documentation files (the "Software"), to deal in
9
+ # the Software without restriction, including without limitation the rights to
10
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
+ # the Software, and to permit persons to whom the Software is furnished to do so,
12
+ # subject to the following conditions:
13
+
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ SECRET_GITHUB_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
25
+ DATABASE_HOST=XXXXXXXXXXXXX
26
+ DATABASE_USERNAME=XXXXXXXXXXXXXX
27
+ DATABASE_PASSWORD=XXXXXXXXXXXXXX
28
+
29
+ echo '***************************************************************'
30
+ echo Login persistently
31
+ echo '***************************************************************'
32
+ gzr session login
33
+
34
+ echo '***************************************************************'
35
+ echo create and test the connection
36
+ echo '***************************************************************'
37
+ cat > Connection_faa_mysql.json <<HERE
38
+ {
39
+ "name": "faa",
40
+ "host": "$DATABASE_HOST",
41
+ "port": "3306",
42
+ "database": "flightstats",
43
+ "db_timezone": "UTC",
44
+ "query_timezone": "UTC",
45
+ "schema": null,
46
+ "max_connections": 30,
47
+ "ssl": false,
48
+ "verify_ssl": false,
49
+ "tmp_db_name": "tmp",
50
+ "pool_timeout": 120,
51
+ "sql_runner_precache_tables": true,
52
+ "sql_writing_with_info_schema": true,
53
+ "uses_tns": false,
54
+ "pdt_concurrency": 1,
55
+ "dialect_name": "mysql",
56
+ "username": "$DATABASE_USERNAME",
57
+ "password": "$DATABASE_PASSWORD"
58
+ }
59
+ HERE
60
+ gzr connection import Connection_faa_mysql.json --token_file
61
+ gzr connection test faa --token_file
62
+
63
+ echo '***************************************************************'
64
+ echo Change the session to dev mode
65
+ echo '***************************************************************'
66
+ gzr session get --token_file
67
+ gzr session update dev --token_file
68
+
69
+ echo '***************************************************************'
70
+ echo Import the project
71
+ echo '***************************************************************'
72
+ cat > Project_faa.json <<HERE
73
+ {
74
+ "name": "faa",
75
+ "uses_git": true
76
+ }
77
+ HERE
78
+ gzr project import Project_faa.json --token-file
79
+
80
+ echo '***************************************************************'
81
+ echo Create a deploy key and set it on the github repo for the project
82
+ echo '***************************************************************'
83
+ DEPLOY_KEY=$(gzr project deploy_key faa --token_file)
84
+ curl -L \
85
+ -X POST \
86
+ -H "Accept: application/vnd.github+json" \
87
+ -H "Authorization: Bearer $SECRET_GITHUB_TOKEN" \
88
+ -H "X-GitHub-Api-Version: 2022-11-28" \
89
+ https://api.github.com/repos/looker-open-source/faa/keys \
90
+ -d "{\"title\":\"test_key $(uuidgen)\",\"key\":\"$DEPLOY_KEY\",\"read_only\":false}"
91
+
92
+ echo '***************************************************************'
93
+ echo Set the project github connection
94
+ echo '***************************************************************'
95
+ cat > github_repo.json <<HERE
96
+ {
97
+ "git_remote_url": "git@github.com:looker-open-source/faa.git",
98
+ "git_service_name": "github"
99
+ }
100
+ HERE
101
+ gzr project update faa github_repo.json --token-file
102
+
103
+ echo '***************************************************************'
104
+ echo Check the project config
105
+ echo '***************************************************************'
106
+ gzr project cat faa --trim --token-file
107
+
108
+ echo '***************************************************************'
109
+ echo Checkout a shared branch
110
+ echo '***************************************************************'
111
+ gzr project checkout faa main --token_file
112
+
113
+ echo '***************************************************************'
114
+ echo Deploy to production
115
+ echo '***************************************************************'
116
+ gzr project deploy faa --token_file
117
+
118
+ echo '***************************************************************'
119
+ echo Configure lookml model
120
+ echo '***************************************************************'
121
+ cat > Model_faa.json <<HERE
122
+ {
123
+ "name": "aviation",
124
+ "project_name": "faa",
125
+ "unlimited_db_connections": false,
126
+ "allowed_db_connection_names": [
127
+ "faa"
128
+ ]
129
+ }
130
+ HERE
131
+ gzr model import Model_faa.json --token_file
132
+
133
+ echo '***************************************************************'
134
+ echo run a query against the model
135
+ echo '***************************************************************'
136
+ cat > query.json <<HERE
137
+ {
138
+ "model": "aviation",
139
+ "view": "aircraft_types",
140
+ "fields": ["aircraft_types.description","aircraft_types.count"],
141
+ "pivots": null,
142
+ "fill_fields": null,
143
+ "filters": null,
144
+ "filter_expression": null,
145
+ "sorts": [
146
+ "aircraft_types.description"
147
+ ],
148
+ "limit": "500"
149
+ }
150
+ HERE
151
+ gzr query runquery "$(cat query.json)"
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'
@@ -42,12 +42,25 @@ module Gzr
42
42
  say_warning("options: #{@options.inspect}", output: output) if @options[:debug]
43
43
  with_session do
44
44
  read_file(@file) do |data|
45
- data.select! do |k,v|
46
- keys_to_keep('create_lookml_model').include? k
45
+ if !!cat_model(data[:name])
46
+ name = data[:name]
47
+ if !@options[:force]
48
+ raise Gzr::CLI::Error, "Model #{name} already exists\nUse --force if you want to overwrite it"
49
+ end
50
+ data.select! do |k,v|
51
+ keys_to_keep('update_lookml_model').include? k
52
+ end
53
+ model = update_model(data[:name],data)
54
+ output.puts "Updated model #{model[:name]}" unless @options[:plain]
55
+ output.puts model[:name] if @options[:plain]
56
+ else
57
+ data.select! do |k,v|
58
+ keys_to_keep('create_lookml_model').include? k
59
+ end
60
+ model = create_model(data)
61
+ output.puts "Created model #{model[:name]}" unless @options[:plain]
62
+ output.puts model[:name] if @options[:plain]
47
63
  end
48
- model = create_model(data)
49
- output.puts "Created model #{model[:name]}" unless @options[:plain]
50
- output.puts model[:name] if @options[:plain]
51
64
  end
52
65
  end
53
66
  end
@@ -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.'
@@ -64,6 +67,8 @@ module Gzr
64
67
  end
65
68
 
66
69
  desc 'import MODEL_FILE', 'Import a model configuration from a file containing json information'
70
+ method_option :force, type: :boolean,
71
+ desc: 'Overwrite an existing connection'
67
72
  method_option :help, aliases: '-h', type: :boolean,
68
73
  desc: 'Display usage information'
69
74
  def import(model_file)
@@ -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