swa 0.7.6 → 0.8.0

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: 515c45df8339e1e9c4168bc6ab96311385a0dcdac85e65d3425311c859ffef95
4
- data.tar.gz: 827af0b7cd21516b46fa4f06eb751e934e752e4becd071aa1d750ce54244ba4d
3
+ metadata.gz: 36e1c1b0403a6cdb2a09bce49b2cc378f6b67f8abfbded1d6baf41d46e70504e
4
+ data.tar.gz: 91755af27947ed3028f7da36e44e1e2a53ed0555ce99a0107a557ee4767e6632
5
5
  SHA512:
6
- metadata.gz: e2d5ca76c3a0acd50514e778d89da6992b7b217a23b69e19e8c6c74ed8b0c0987d3417d93376905b49446c581c1ca6d5a4aaaa221319b82057735f9cba81d76b
7
- data.tar.gz: 4c6a89e273eac6ad8be3092292710ddafda571c70cc78ff0ed39f938bf212f80c4a9d1d7af142b2afbdc26da99b77ff3d1c717a7c55c38be57f45ac7f8d8a766
6
+ metadata.gz: 2c93335b35ff3b0e070847deee928481a77634d295dfe2e2240308fec7c8f776cfa8f6ab9658bfface70dfcb124f7b10ec55ae75c5375be98ce0161b3f8d1b1e
7
+ data.tar.gz: 1e64bf3fe18ba6398dc7d3af897a0223099b85a7112464a112a662d2caa763d35aa14c05d19de042ccdd35b36d4b78707938c720d8c5066504ca94c99fa21f57
@@ -91,24 +91,25 @@ module Swa
91
91
 
92
92
  end
93
93
 
94
- subcommand ["executions", "query-executions"], "List query executions" do
94
+ subcommand ["query", "q", "execute", "exec"], "Run a query" do
95
95
 
96
- include CollectionBehaviour
96
+ option ["--database", "-D"], "NAME", "Database name"
97
+ option ["--output-location", "-O"], "S3_URL", "S3 output location for query results"
97
98
 
98
- private
99
-
100
- def collection
101
- query_for(:list_query_executions, :query_execution_ids, Swa::Athena::QueryExecution, work_group: workgroup)
102
- end
103
-
104
- end
105
-
106
- subcommand ["query", "q", "run"], "Run a query" do
107
-
108
- parameter "QUERY", "SQL query"
99
+ parameter "[QUERY]", "SQL query", :default => "STDIN"
109
100
 
110
101
  def execute
111
- start_query_response = athena_client.start_query_execution(query_string: query, work_group: workgroup)
102
+ start_query_response = athena_client.start_query_execution(
103
+ query_execution_context: {
104
+ catalog: catalog,
105
+ database: database
106
+ },
107
+ query_string: query,
108
+ result_configuration: {
109
+ output_location: output_location
110
+ },
111
+ work_group: workgroup
112
+ )
112
113
  wait_for_query(start_query_response.query_execution_id)
113
114
  query_results = athena_client.get_query_results(query_execution_id: start_query_response.query_execution_id)
114
115
  output_results_as_csv(query_results.result_set)
@@ -116,6 +117,10 @@ module Swa
116
117
 
117
118
  private
118
119
 
120
+ def default_query
121
+ $stdin.read
122
+ end
123
+
119
124
  def wait_for_query(query_execution_id)
120
125
  QueryCompletionWaiter.new(client: athena_client).wait(query_execution_id: query_execution_id)
121
126
  rescue Aws::Waiters::Errors::FailureStateError => error
@@ -0,0 +1,69 @@
1
+ require "aws-sdk-lakeformation"
2
+ require "swa/cli/base_command"
3
+ require "swa/cli/collection_behaviour"
4
+ require "swa/cli/item_behaviour"
5
+ require "swa/lake_formation/resource_info"
6
+
7
+ module Swa
8
+ module CLI
9
+
10
+ class LakeFormationCommand < BaseCommand
11
+
12
+ subcommand ["permissions"], "Show permissions" do
13
+
14
+ self.description = <<-EOF
15
+ List permissions.
16
+ EOF
17
+
18
+ include CollectionBehaviour
19
+
20
+ private
21
+
22
+ def collection
23
+ query_for(:list_permissions, :principal_resource_permissions, Swa::LakeFormation::Permission)
24
+ end
25
+
26
+ end
27
+
28
+ protected
29
+
30
+ def lf_client
31
+ ::Aws::LakeFormation::Client.new(aws_config)
32
+ end
33
+
34
+ def query_for(query_method, response_key, model)
35
+ records = lf_client.public_send(query_method).public_send(response_key)
36
+ model.list(records)
37
+ end
38
+
39
+ subcommand ["resources"], "Show resources" do
40
+
41
+ self.description = <<-EOF
42
+ List resources.
43
+ EOF
44
+
45
+ include CollectionBehaviour
46
+
47
+ private
48
+
49
+ def collection
50
+ query_for(:list_resources, :resource_info_list, Swa::LakeFormation::ResourceInfo)
51
+ end
52
+
53
+ end
54
+
55
+ protected
56
+
57
+ def lf_client
58
+ ::Aws::LakeFormation::Client.new(aws_config)
59
+ end
60
+
61
+ def query_for(query_method, response_key, model)
62
+ records = lf_client.public_send(query_method).public_send(response_key)
63
+ model.list(records)
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
@@ -6,6 +6,7 @@ require "swa/cli/elb_command"
6
6
  require "swa/cli/glue_command"
7
7
  require "swa/cli/iam_command"
8
8
  require "swa/cli/kms_command"
9
+ require "swa/cli/lake_formation_command"
9
10
  require "swa/cli/s3_command"
10
11
 
11
12
  module Swa
@@ -20,6 +21,7 @@ module Swa
20
21
  subcommand "glue", "Glue stuff", GlueCommand
21
22
  subcommand "iam", "IAM stuff", IamCommand
22
23
  subcommand "kms", "KMS stuff", KmsCommand
24
+ subcommand ["lf", "lakeformation"], "LakeFormation stuff", LakeFormationCommand
23
25
  subcommand "s3", "S3 stuff", S3Command
24
26
 
25
27
  protected
@@ -0,0 +1,32 @@
1
+ require "swa/record"
2
+
3
+ module Swa
4
+ module LakeFormation
5
+
6
+ class Permission < Record
7
+
8
+ def summary
9
+ [
10
+ principal_id,
11
+ permissions.join(","),
12
+ resource_summary
13
+ ].join(" ")
14
+ end
15
+
16
+ delegate :permissions
17
+ delegate :principal
18
+
19
+ def principal_id
20
+ aws_record.principal.data_lake_principal_identifier
21
+ end
22
+
23
+ def resource_summary
24
+ h = aws_record.resource.to_hash.compact
25
+ type, details = h.first
26
+ "#{type}:#{details.values.join("/")}"
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ require "swa/record"
2
+
3
+ module Swa
4
+ module LakeFormation
5
+
6
+ class ResourceInfo < Record
7
+
8
+ def summary
9
+ [
10
+ resource_arn,
11
+ role_arn
12
+ ].join(" ")
13
+ end
14
+
15
+ delegate :resource_arn
16
+ delegate :role_arn
17
+
18
+ end
19
+
20
+ end
21
+ end
data/lib/swa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Swa
2
- VERSION = "0.7.6"
2
+ VERSION = "0.8.0"
3
3
  end
data/swa.gemspec CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_runtime_dependency "aws-sdk-glue", "~> 1"
31
31
  spec.add_runtime_dependency "aws-sdk-iam", "~> 1"
32
32
  spec.add_runtime_dependency "aws-sdk-kms", "~> 1"
33
+ spec.add_runtime_dependency "aws-sdk-lakeformation", "~> 1"
33
34
  spec.add_runtime_dependency "aws-sdk-s3", "~> 1"
34
35
  spec.add_runtime_dependency "pry"
35
36
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-16 00:00:00.000000000 Z
11
+ date: 2024-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: aws-sdk-lakeformation
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: aws-sdk-s3
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -282,6 +296,7 @@ files:
282
296
  - lib/swa/cli/iam_command.rb
283
297
  - lib/swa/cli/item_behaviour.rb
284
298
  - lib/swa/cli/kms_command.rb
299
+ - lib/swa/cli/lake_formation_command.rb
285
300
  - lib/swa/cli/main_command.rb
286
301
  - lib/swa/cli/s3_command.rb
287
302
  - lib/swa/cli/selector.rb
@@ -315,6 +330,8 @@ files:
315
330
  - lib/swa/iam/user.rb
316
331
  - lib/swa/kms/alias.rb
317
332
  - lib/swa/kms/key.rb
333
+ - lib/swa/lake_formation/permission.rb
334
+ - lib/swa/lake_formation/resource_info.rb
318
335
  - lib/swa/polyfill.rb
319
336
  - lib/swa/record.rb
320
337
  - lib/swa/resource.rb
@@ -343,7 +360,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
343
360
  - !ruby/object:Gem::Version
344
361
  version: '0'
345
362
  requirements: []
346
- rubygems_version: 3.4.10
363
+ rubygems_version: 3.5.3
347
364
  signing_key:
348
365
  specification_version: 4
349
366
  summary: AWS, backwards