gazer 0.2.27 → 0.2.28

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
  SHA1:
3
- metadata.gz: f369430803f6b9f9399ac276dc1782290d795a6b
4
- data.tar.gz: d782a75396113fcf993babb399967305eb9c8b25
3
+ metadata.gz: 6f0cbb4a2a0249acc8a634fb3a813cecdbb60d00
4
+ data.tar.gz: a0b2d54e41d164fd34c199107f350b5332bf859b
5
5
  SHA512:
6
- metadata.gz: 36677ca488edd93c88dc4ed50154f600a9cecd5c12700be8e0acc79058c4551fed0018331a3888012763fb69e86574eade14d5d10822dcf919834a0112456d04
7
- data.tar.gz: cbb933613180bdf7940407db04f62821ac29b6f8443b60a05cda349845c9e1ec8ae5952b16c1e9fe795e6f6d5f10b148dd971e86827f027dee189f9b912bafbf
6
+ metadata.gz: 2b7eff72d81f4b892e98b3924c1db00613f3819035d4d551718f74094c48857814f2e49d4bf0aaa744e1b9a920fa0ee13386dc549aa12e77114690fb12c0d174
7
+ data.tar.gz: 54aeaaf8808e134eced33969ff8bf78e82b3270d52a59b5cfb2a8298384af73c83aaf0197281d137d7aedce887ab2471c311f68a802e2162c0ee65c0527b4a2a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gazer (0.2.27)
4
+ gazer (0.2.28)
5
5
  looker-sdk (~> 0.0.6)
6
6
  netrc (~> 0.11.0)
7
7
  pastel (~> 0.7.2)
@@ -53,6 +53,9 @@ module Gzr
53
53
  end
54
54
  map %w(--version -v) => :version
55
55
 
56
+ require_relative 'commands/attribute'
57
+ register Gzr::Commands::Attribute, 'attribute', 'attribute [SUBCOMMAND]', 'Command description...'
58
+
56
59
  require_relative 'commands/permissions'
57
60
  register Gzr::Commands::Permissions, 'permissions', 'permissions [SUBCOMMAND]', 'Command to retrieve available permissions'
58
61
 
@@ -0,0 +1,149 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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 'thor'
25
+
26
+ module Gzr
27
+ module Commands
28
+ class Attribute < Thor
29
+
30
+ namespace :attribute
31
+
32
+ desc 'set_group_value GROUP_ID|GROUP_NAME ATTR_ID|ATTR_NAME VALUE', 'Set a user attribute value for a group'
33
+ method_option :help, aliases: '-h', type: :boolean,
34
+ desc: 'Display usage information'
35
+ def set_group_value(group,attr,value)
36
+ if options[:help]
37
+ invoke :help, ['set_group_value']
38
+ else
39
+ require_relative 'attribute/set_group_value'
40
+ Gzr::Commands::Attribute::SetGroupValue.new(group,attr,value,options).execute
41
+ end
42
+ end
43
+
44
+ desc 'get_group_value GROUP_ID|GROUP_NAME ATTR_ID|ATTR_NAME', 'Retrieve a user attribute value for a group'
45
+ method_option :help, aliases: '-h', type: :boolean,
46
+ desc: 'Display usage information'
47
+ def get_group_value(group,attr)
48
+ if options[:help]
49
+ invoke :help, ['get_group_value']
50
+ else
51
+ require_relative 'attribute/get_group_value'
52
+ Gzr::Commands::Attribute::GetGroupValue.new(group,attr,options).execute
53
+ end
54
+ end
55
+
56
+ desc 'rm ATTR_ID|ATTR_NAME', 'Delete a user attribute'
57
+ method_option :help, aliases: '-h', type: :boolean,
58
+ desc: 'Display usage information'
59
+ method_option :plain, type: :boolean,
60
+ desc: 'Provide minimal response information'
61
+ def rm(attr)
62
+ if options[:help]
63
+ invoke :help, ['rm']
64
+ else
65
+ require_relative 'attribute/rm'
66
+ Gzr::Commands::Attribute::Rm.new(attr,options).execute
67
+ end
68
+ end
69
+
70
+ desc 'import FILE', 'Import a user attribute from a file'
71
+ method_option :help, aliases: '-h', type: :boolean,
72
+ desc: 'Display usage information'
73
+ method_option :plain, type: :boolean,
74
+ desc: 'Provide minimal response information'
75
+ method_option :force, type: :boolean,
76
+ desc: 'If the user attribute already exists, modify it'
77
+ def import(file)
78
+ if options[:help]
79
+ invoke :help, ['import']
80
+ else
81
+ require_relative 'attribute/import'
82
+ Gzr::Commands::Attribute::Import.new(file,options).execute
83
+ end
84
+ end
85
+
86
+ desc 'create ATTR_NAME [ATTR_LABEL] [OPTIONS]', 'Create or modify an attribute'
87
+ method_option :help, aliases: '-h', type: :boolean,
88
+ desc: 'Display usage information'
89
+ method_option :plain, type: :boolean,
90
+ desc: 'Provide minimal response information'
91
+ method_option :force, type: :boolean,
92
+ desc: 'If the user attribute already exists, modify it'
93
+ method_option :type, type: :string, default: 'string',
94
+ desc: '"string", "number", "datetime", "yesno", "zipcode"'
95
+ method_option :'default-value', type: :string,
96
+ desc: 'default value to be used if one not otherwise set'
97
+ method_option :'is-hidden', type: :boolean, default: false,
98
+ desc: 'can a non-admin user view the value'
99
+ method_option :'can-view', type: :boolean, default: true,
100
+ desc: 'can a non-admin user view the value'
101
+ method_option :'can-edit', type: :boolean, default: true,
102
+ desc: 'can a user change the value themself'
103
+ method_option :'domain-whitelist', type: :string,
104
+ desc: 'what domains can receive the value of a hidden attribute.'
105
+ def create(attr_name, attr_label=nil)
106
+ if options[:help]
107
+ invoke :help, ['create']
108
+ else
109
+ require_relative 'attribute/create'
110
+ Gzr::Commands::Attribute::Create.new(attr_name, attr_label, options).execute
111
+ end
112
+ end
113
+
114
+ desc 'cat ATTR_ID|ATTR_NAME', 'Output json information about an attribute to screen or file'
115
+ method_option :help, aliases: '-h', type: :boolean,
116
+ desc: 'Display usage information'
117
+ method_option :fields, type: :string,
118
+ desc: 'Fields to display'
119
+ method_option :dir, type: :string,
120
+ desc: 'Directory to store output file'
121
+ def cat(attr)
122
+ if options[:help]
123
+ invoke :help, ['cat']
124
+ else
125
+ require_relative 'attribute/cat'
126
+ Gzr::Commands::Attribute::Cat.new(attr,options).execute
127
+ end
128
+ end
129
+
130
+ desc 'ls', 'List all the defined user attributes'
131
+ method_option :help, aliases: '-h', type: :boolean,
132
+ desc: 'Display usage information'
133
+ method_option :fields, type: :string, default: 'id,name,label,type,default_value',
134
+ desc: 'Fields to display'
135
+ method_option :plain, type: :boolean, default: false,
136
+ desc: 'print without any extra formatting'
137
+ method_option :csv, type: :boolean, default: false,
138
+ desc: 'output in csv format per RFC4180'
139
+ def ls(*)
140
+ if options[:help]
141
+ invoke :help, ['ls']
142
+ else
143
+ require_relative 'attribute/ls'
144
+ Gzr::Commands::Attribute::Ls.new(options).execute
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,60 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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/attribute'
26
+ require_relative '../../modules/filehelper'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Attribute
31
+ class Cat < Gzr::Command
32
+ include Gzr::Attribute
33
+ include Gzr::FileHelper
34
+ def initialize(attr,options)
35
+ super()
36
+ @attr = attr
37
+ @options = options
38
+ end
39
+
40
+ def execute(input: $stdin, output: $stdout)
41
+ say_warning(@options) if @options[:debug]
42
+ with_session do
43
+ f = @options[:fields]
44
+ id = @attr if /^\d+$/.match @attr
45
+ attr = nil
46
+ if id
47
+ attr = query_user_attribute(id,f)
48
+ else
49
+ attr = get_attribute_by_name(@attr,f)
50
+ end
51
+ raise(Gzr::CLI::Error, "Attribute #{@attr} does not exist") unless attr
52
+ write_file(@options[:dir] ? "Attribute_#{attr.id}_#{attr.name}.json" : nil, @options[:dir],nil, output) do |f|
53
+ f.puts JSON.pretty_generate(attr.to_attrs)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,57 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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/attribute'
26
+
27
+ module Gzr
28
+ module Commands
29
+ class Attribute
30
+ class Create < Gzr::Command
31
+ include Gzr::Attribute
32
+ def initialize(name,label,options)
33
+ super()
34
+ @name = name
35
+ @label = label || @name.split(/ |\_|\-/).map(&:capitalize).join(" ")
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
+ source = { :name=>@name, :label=>@label, :type=>@options[:type] }
43
+ source[:'default_value'] = @options[:'default-value'] if @options[:'default-value']
44
+ source[:'value_is_hidden'] = true if @options[:'is-hidden']
45
+ source[:'user_can_view'] = true if @options[:'can-view']
46
+ source[:'user_can_edit'] = true if @options[:'can-edit']
47
+ source[:'hidden_value_domain_whitelist'] = @options[:'domain-whitelist'] if @options[:'is-hidden'] && @options[:'domain-whitelist']
48
+
49
+ attr = upsert_user_attribute(source, @options[:force], output: $stdout)
50
+ output.puts "Imported attribute #{attr.name} #{attr.id}" unless @options[:plain]
51
+ output.puts attr.id if @options[:plain]
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,77 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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/group'
26
+ require_relative '../../modules/attribute'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Attribute
31
+ class GetGroupValue < Gzr::Command
32
+ include Gzr::Attribute
33
+ include Gzr::Group
34
+ def initialize(group,attr,options)
35
+ super()
36
+ @group = group
37
+ @attr = attr
38
+ @options = options
39
+ end
40
+
41
+ def execute(input: $stdin, output: $stdout)
42
+ say_warning(@options) if @options[:debug]
43
+ with_session("3.1") do
44
+
45
+ group_id = @group if /^\d+$/.match @group
46
+ group = nil
47
+ if group_id
48
+ group = query_group(group_id)
49
+ else
50
+ results = search_groups(@group)
51
+ if results && results.length == 1
52
+ group = results.first
53
+ elsif results
54
+ raise(Gzr::CLI::Error, "Pattern #{@group} matched more than one group")
55
+ else
56
+ raise(Gzr::CLI::Error, "Pattern #{@group} did not match any groups")
57
+ end
58
+ end
59
+
60
+ attr_id = @attr if /^\d+$/.match @attr
61
+ attr = nil
62
+ if attr_id
63
+ attr = query_user_attribute(attr_id)
64
+ else
65
+ attr = get_attribute_by_name(@attr)
66
+ end
67
+ raise(Gzr::CLI::Error, "Attribute #{@attr} does not exist") unless attr
68
+
69
+ data = query_user_attribute_group_value(group.id,attr.id)
70
+ say_warning("Attribute #{attr.name} does not have a value set for group #{group.name}", output: output) unless data
71
+ output.puts data.value if data
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,53 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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/attribute'
26
+ require_relative '../../modules/filehelper'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Attribute
31
+ class Import < Gzr::Command
32
+ include Gzr::Attribute
33
+ include Gzr::FileHelper
34
+ def initialize(file,options)
35
+ super()
36
+ @file = file
37
+ @options = options
38
+ end
39
+
40
+ def execute(input: $stdin, output: $stdout)
41
+ say_warning(@options) if @options[:debug]
42
+ with_session do
43
+ read_file(@file) do |source|
44
+ attr = upsert_user_attribute(source, @options[:force], output: $stdout)
45
+ output.puts "Imported attribute #{attr.name} #{attr.id}" unless @options[:plain]
46
+ output.puts attr.id if @options[:plain]
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,73 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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/attribute'
26
+ require 'tty-table'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Attribute
31
+ class Ls < Gzr::Command
32
+ include Gzr::Attribute
33
+ def initialize(options)
34
+ super()
35
+ @options = options
36
+ end
37
+
38
+ def execute(input: $stdin, output: $stdout)
39
+ say_warning(@options) if @options[:debug]
40
+ with_session do
41
+ f = @options[:fields]
42
+ data = query_all_user_attributes(f)
43
+ begin
44
+ say_ok "No use attributes 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)
66
+ end
67
+ end if table
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,62 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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/attribute'
26
+
27
+ module Gzr
28
+ module Commands
29
+ class Attribute
30
+ class Rm < Gzr::Command
31
+ include Gzr::Attribute
32
+ def initialize(attr,options)
33
+ super()
34
+ @attr = attr
35
+ @options = options
36
+ end
37
+
38
+ def execute(input: $stdin, output: $stdout)
39
+ say_warning(@options) if @options[:debug]
40
+ with_session do
41
+ id = @attr if /^\d+$/.match @attr
42
+ attr = nil
43
+ if id
44
+ attr = query_user_attribute(id)
45
+ else
46
+ attr = get_attribute_by_name(@attr)
47
+ end
48
+
49
+ raise(Gzr::CLI::Error, "Attribute #{@attr} does not exist") unless attr
50
+ raise(Gzr::CLI::Error, "Attribute #{attr[:name]} is a system built-in and cannot be deleted ") if attr[:is_system]
51
+ raise(Gzr::CLI::Error, "Attribute #{attr[:name]} is marked permanent and cannot be deleted ") if attr[:is_permanent]
52
+
53
+ delete_user_attribute(attr.id)
54
+
55
+ output.puts "Deleted attribute #{attr.name} #{attr.id}" unless @options[:plain]
56
+ output.puts attr.id if @options[:plain]
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,78 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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/group'
26
+ require_relative '../../modules/attribute'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Attribute
31
+ class SetGroupValue < Gzr::Command
32
+ include Gzr::Attribute
33
+ include Gzr::Group
34
+ def initialize(group,attr,value,options)
35
+ super()
36
+ @group = group
37
+ @attr = attr
38
+ @value = value
39
+ @options = options
40
+ end
41
+
42
+ def execute(input: $stdin, output: $stdout)
43
+ say_warning(@options) if @options[:debug]
44
+ with_session("3.1") do
45
+
46
+ group_id = @group if /^\d+$/.match @group
47
+ group = nil
48
+ if group_id
49
+ group = query_group(group_id)
50
+ else
51
+ results = search_groups(@group)
52
+ if results && results.length == 1
53
+ group = results.first
54
+ elsif results
55
+ raise(Gzr::CLI::Error, "Pattern #{@group} matched more than one group")
56
+ else
57
+ raise(Gzr::CLI::Error, "Pattern #{@group} did not match any groups")
58
+ end
59
+ end
60
+
61
+ attr_id = @attr if /^\d+$/.match @attr
62
+ attr = nil
63
+ if attr_id
64
+ attr = query_user_attribute(attr_id)
65
+ else
66
+ attr = get_attribute_by_name(@attr)
67
+ end
68
+ raise(Gzr::CLI::Error, "Attribute #{@attr} does not exist") unless attr
69
+
70
+ data = update_user_attribute_group_value(group.id,attr.id, @value)
71
+ say_warning("Attribute #{attr.name} does not have a value set for group #{group.name}", output: output) unless data
72
+ output.puts "Group attribute #{data.id} set to #{data.value}"
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,3 +1,24 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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
+
1
22
  # frozen_string_literal: true
2
23
 
3
24
  require 'thor'
@@ -0,0 +1,155 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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
+ module Gzr
25
+ module Attribute
26
+ def query_user_attribute(attr_id,fields=nil)
27
+ data = nil
28
+ begin
29
+ req = {}
30
+ req[:fields] = fields if fields
31
+ data = @sdk.user_attribute(attr_id,req)
32
+ rescue LookerSDK::NotFound => e
33
+ # do nothing
34
+ rescue LookerSDK::Error => e
35
+ say_error "Error querying user_attribute(#{attr_id},#{JSON.pretty_generate(req)})"
36
+ say_error e.message
37
+ raise
38
+ end
39
+ data
40
+ end
41
+
42
+ def query_all_user_attributes(fields=nil, sorts=nil)
43
+ data = nil
44
+ begin
45
+ req = {}
46
+ req[:fields] = fields if fields
47
+ req[:sorts] = sorts if sorts
48
+ data = @sdk.all_user_attributes(req)
49
+ rescue LookerSDK::Error => e
50
+ say_error "Error querying all_user_attributes(#{JSON.pretty_generate(req)})"
51
+ say_error e.message
52
+ raise
53
+ end
54
+ data
55
+ end
56
+
57
+ def get_attribute_by_name(name, fields = nil)
58
+ data = query_all_user_attributes(fields).select {|a| a.name == name}
59
+ return nil if data.empty?
60
+ data.first
61
+ end
62
+
63
+ def get_attribute_by_label(label, fields = nil)
64
+ data = query_all_user_attributes(fields).select {|a| a.label == label}
65
+ return nil if data.empty?
66
+ data.first
67
+ end
68
+
69
+ def create_attribute(attr)
70
+ data = nil
71
+ begin
72
+ data = @sdk.create_user_attribute(attr)
73
+ rescue LookerSDK::Error => e
74
+ say_error "Error creating user_attribute(#{JSON.pretty_generate(attr)})"
75
+ say_error e.message
76
+ raise
77
+ end
78
+ data
79
+ end
80
+
81
+ def update_attribute(id,attr)
82
+ data = nil
83
+ begin
84
+ data = @sdk.update_user_attribute(id,attr)
85
+ rescue LookerSDK::Error => e
86
+ say_error "Error updating user_attribute(#{id},#{JSON.pretty_generate(attr)})"
87
+ say_error e.message
88
+ raise
89
+ end
90
+ data
91
+ end
92
+
93
+ def delete_user_attribute(id)
94
+ data = nil
95
+ begin
96
+ data = @sdk.delete_user_attribute(id)
97
+ rescue LookerSDK::Error => e
98
+ say_error "Error deleting user_attribute(#{id})"
99
+ say_error e.message
100
+ raise
101
+ end
102
+ data
103
+ end
104
+
105
+ def query_all_user_attribute_group_values(attr_id, fields=nil)
106
+ begin
107
+ req = {}
108
+ req[:fields] = fields if fields
109
+ return @sdk.all_user_attribute_group_values(attr_id,req)
110
+ rescue LookerSDK::NotFound => e
111
+ return nil
112
+ rescue LookerSDK::Error => e
113
+ say_error "Error querying all_user_attribute_group_values(#{attr_id},#{JSON.pretty_generate(req)})"
114
+ say_error e.message
115
+ raise
116
+ end
117
+ end
118
+
119
+ def query_user_attribute_group_value(group_id, attr_id)
120
+ data = query_all_user_attribute_group_values(attr_id)&.select {|a| a.group_id == group_id}
121
+ return nil if data.nil? || data.empty?
122
+ data.first
123
+ end
124
+
125
+ def upsert_user_attribute(source, force=false, output: $stdout)
126
+ name_used = get_attribute_by_name(source[:name])
127
+ if name_used
128
+ raise(Gzr::CLI::Error, "Attribute #{source[:name]} already exists and can't be modified") if name_used[:is_system]
129
+ raise(Gzr::CLI::Error, "Attribute #{source[:name]} already exists\nUse --force if you want to overwrite it") unless @options[:force]
130
+ end
131
+
132
+ label_used = get_attribute_by_label(source[:label])
133
+ if label_used
134
+ raise(Gzr::CLI::Error, "Attribute with label #{source[:label]} already exists and can't be modified") if label_used[:is_system]
135
+ raise(Gzr::CLI::Error, "Attribute with label #{source[:label]} already exists\nUse --force if you want to overwrite it") unless force
136
+ end
137
+
138
+ existing = name_used || label_used
139
+ if existing
140
+ upd_attr = source.select do |k,v|
141
+ keys_to_keep('update_user_attribute').include?(k) && !(name_used[k] == v)
142
+ end
143
+
144
+ return update_attribute(existing.id,upd_attr)
145
+ else
146
+ new_attr = source.select do |k,v|
147
+ (keys_to_keep('create_user_attribute') - [:hidden_value_domain_whitelist]).include? k
148
+ end
149
+ new_attr[:hidden_value_domain_whitelist] = source[:hidden_value_domain_whitelist] if source[:value_is_hidden] && source[:hidden_value_domain_whitelist]
150
+
151
+ return create_attribute(new_attr)
152
+ end
153
+ end
154
+ end
155
+ end
@@ -89,5 +89,44 @@ module Gzr
89
89
  end
90
90
  data
91
91
  end
92
+
93
+ def search_groups(name)
94
+ req = {:name => name }
95
+ begin
96
+ return @sdk.search_groups(req)
97
+ rescue LookerSDK::NotFound => e
98
+ return nil
99
+ rescue LookerSDK::ClientError => e
100
+ say_error "Unable to search_groups(#{JSON.pretty_generate(req)})"
101
+ say_error e.message
102
+ raise
103
+ end
104
+ end
105
+
106
+ def query_group(id, fields=nil)
107
+ req = Hash.new
108
+ req[:fields] = fields if fields
109
+ begin
110
+ return @sdk.group(id,req)
111
+ rescue LookerSDK::NotFound => e
112
+ return nil
113
+ rescue LookerSDK::ClientError => e
114
+ say_error "Unable to find group(#{id},#{JSON.pretty_generate(req)})"
115
+ say_error e.message
116
+ raise
117
+ end
118
+ end
119
+
120
+ def update_user_attribute_group_value(group_id, attr_id, value)
121
+ req = Hash.new
122
+ req[:value] = value
123
+ begin
124
+ return @sdk.update_user_attribute_group_value(group_id,attr_id, req)
125
+ rescue LookerSDK::ClientError => e
126
+ say_error "Unable to update_user_attribute_group_value(#{group_id},#{attr_id},#{JSON.pretty_generate(req)})"
127
+ say_error e.message
128
+ raise
129
+ end
130
+ end
92
131
  end
93
132
  end
@@ -20,5 +20,5 @@
20
20
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  module Gzr
23
- VERSION = "0.2.27"
23
+ VERSION = "0.2.28"
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.27
4
+ version: 0.2.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike DeAngelo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-21 00:00:00.000000000 Z
11
+ date: 2019-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-reader
@@ -204,6 +204,14 @@ files:
204
204
  - lib/gzr/cli.rb
205
205
  - lib/gzr/command.rb
206
206
  - lib/gzr/commands/.gitkeep
207
+ - lib/gzr/commands/attribute.rb
208
+ - lib/gzr/commands/attribute/cat.rb
209
+ - lib/gzr/commands/attribute/create.rb
210
+ - lib/gzr/commands/attribute/get_group_value.rb
211
+ - lib/gzr/commands/attribute/import.rb
212
+ - lib/gzr/commands/attribute/ls.rb
213
+ - lib/gzr/commands/attribute/rm.rb
214
+ - lib/gzr/commands/attribute/set_group_value.rb
207
215
  - lib/gzr/commands/connection.rb
208
216
  - lib/gzr/commands/connection/dialects.rb
209
217
  - lib/gzr/commands/connection/ls.rb
@@ -262,6 +270,7 @@ files:
262
270
  - lib/gzr/commands/user/enable.rb
263
271
  - lib/gzr/commands/user/ls.rb
264
272
  - lib/gzr/commands/user/me.rb
273
+ - lib/gzr/modules/attribute.rb
265
274
  - lib/gzr/modules/connection.rb
266
275
  - lib/gzr/modules/dashboard.rb
267
276
  - lib/gzr/modules/filehelper.rb
@@ -275,6 +284,13 @@ files:
275
284
  - lib/gzr/modules/space.rb
276
285
  - lib/gzr/modules/user.rb
277
286
  - lib/gzr/templates/.gitkeep
287
+ - lib/gzr/templates/attribute/cat/.gitkeep
288
+ - lib/gzr/templates/attribute/create/.gitkeep
289
+ - lib/gzr/templates/attribute/get_group_values/.gitkeep
290
+ - lib/gzr/templates/attribute/import/.gitkeep
291
+ - lib/gzr/templates/attribute/ls/.gitkeep
292
+ - lib/gzr/templates/attribute/rm/.gitkeep
293
+ - lib/gzr/templates/attribute/set_group_values/.gitkeep
278
294
  - lib/gzr/templates/connection/dialects/.gitkeep
279
295
  - lib/gzr/templates/connection/ls/.gitkeep
280
296
  - lib/gzr/templates/dashboard/cat/.gitkeep