awful 0.0.29 → 0.0.30

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
  SHA1:
3
- metadata.gz: 58326fca01b2146895915969cdff05f8ba598c1d
4
- data.tar.gz: 2016fc803bb3559537eb3f1699446b52b52a1a15
3
+ metadata.gz: de50bfb59c215fedd6732d5db9d20ababda674c4
4
+ data.tar.gz: fee0153a6bbc75fa1982ce51c3bc9411c7346da2
5
5
  SHA512:
6
- metadata.gz: a8ca8e2dcd0db733bd4b049596a45763e07501d78e86d5a07ab182b0fb7d082bfb4c76e7a48d0b55822d3af2d0972215ba1676900ef45371c04c5a16a96c7220
7
- data.tar.gz: 47cfd6a0c7580a60cd5d458284ec6d2e279e9ea9515eda136010138e7bde00c4b7da596c4be0c46c531ae0c31eb1e23b0d897e8d92732d9864b3861e25866fe3
6
+ metadata.gz: ff2e36715ba4dcd740de1a62314caf8dbe5e9a5df943bcb429711e87491485ae6293d83409a6c011c244cd4f8163519bd48b1b6a3feb18541522b9995b4d8086
7
+ data.tar.gz: e5bb40be4a4a6bbcb247735764c1b934bfaec3b0634debf8e8eda1a853e250c8047a528c9e172986c121147e8f2746a30b27db93aa379de62a8b43be13cd473a
data/lib/awful.rb CHANGED
@@ -34,10 +34,23 @@ module Awful
34
34
 
35
35
  ## to use dynamodb-local, set DYNAMO_ENDPOINT or DYNAMODB_ENDPOINT to e.g. http://localhost:8000
36
36
  def dynamodb
37
- options = { endpoint: ENV['DYNAMO_ENDPOINT'] || ENV['DYNAMODB_ENDPOINT'] }.reject { |_,v| v.nil? }
37
+ options = {endpoint: ENV['DYNAMO_ENDPOINT'] || ENV['DYNAMODB_ENDPOINT']}.reject { |_,v| v.nil? }
38
38
  @dynamodb ||= Aws::DynamoDB::Client.new(options)
39
39
  end
40
40
 
41
+ ## dynamodb client with parameter conversion turned off,
42
+ ## for getting result as Aws::Plugins::Protocols::JsonRpc;
43
+ ## see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataFormat.html;
44
+ ## client method calls need simple attributes in requests also (strings not symbols, etc)
45
+ def dynamodb_simple
46
+ options = {
47
+ simple_attributes: false,
48
+ simple_json: true,
49
+ endpoint: ENV['DYNAMO_ENDPOINT'] || ENV['DYNAMODB_ENDPOINT'],
50
+ }.reject { |_,v| v.nil? }
51
+ @dynamodb_simple ||= Aws::DynamoDB::Client.new(options)
52
+ end
53
+
41
54
  def s3
42
55
  @s3 ||= Aws::S3::Client.new
43
56
  end
@@ -27,31 +27,31 @@ module Awful
27
27
  end
28
28
  end
29
29
 
30
- desc 'scan NAME', 'scan table with NAME'
31
- def scan(name, start_key = nil)
32
- r = dynamodb.scan(table_name: name, exclusive_start_key: start_key) #.items.tap{ |x| p x.count }.tap do |table|
33
- puts r.items.map { |item| JSON.generate(item) }.join("\n")
34
- if r.last_evaluated_key # recurse if more data to get
35
- scan(name, r.last_evaluated_key)
36
- end
37
- end
38
-
39
30
  desc 'create_table NAME', 'create table with NAME'
40
31
  def create_table(name, file = nil)
41
32
  opt = load_cfg(options, file)
42
33
  params = only_keys_matching(opt, %i[attribute_definitions key_schema])
43
34
  params[:table_name] = name
44
35
  params[:provisioned_throughput] = only_keys_matching(opt[:provisioned_throughput], %i[read_capacity_units write_capacity_units])
45
- params[:local_secondary_indexes] = opt[:local_secondary_indexes].map do |lsi|
46
- only_keys_matching(lsi, %i[index_name key_schema projection])
36
+
37
+ ## scrub unwanted keys from LSIs
38
+ if opt.has_key?(:local_secondary_indexes)
39
+ params[:local_secondary_indexes] = opt[:local_secondary_indexes].map do |lsi|
40
+ only_keys_matching(lsi, %i[index_name key_schema projection])
41
+ end
47
42
  end
48
- params[:global_secondary_indexes] = opt[:global_secondary_indexes].map do |gsi|
49
- only_keys_matching(gsi, %i[index_name key_schema projection]).tap do |g|
50
- if gsi[:provisioned_throughput]
51
- g[:provisioned_throughput] = only_keys_matching(gsi[:provisioned_throughput], %i[read_capacity_units write_capacity_units])
43
+
44
+ ## scrub unwanted keys from GSIs
45
+ if opt.has_key?(:global_secondary_indexes)
46
+ params[:global_secondary_indexes] = opt[:global_secondary_indexes].map do |gsi|
47
+ only_keys_matching(gsi, %i[index_name key_schema projection]).tap do |g|
48
+ if gsi[:provisioned_throughput]
49
+ g[:provisioned_throughput] = only_keys_matching(gsi[:provisioned_throughput], %i[read_capacity_units write_capacity_units])
50
+ end
52
51
  end
53
52
  end
54
53
  end
54
+
55
55
  dynamodb.create_table(params)
56
56
  end
57
57
 
@@ -66,12 +66,25 @@ module Awful
66
66
  end
67
67
  end
68
68
 
69
+ ## uses simple_json to get Aws::Plugins::Protocols::JsonRpc output from scan;
70
+ ## this also means request params need to be raw strings and not symbols, etc
71
+ desc 'scan NAME', 'scan table with NAME'
72
+ def scan(name, exclusive_start_key = nil)
73
+ r = dynamodb_simple.scan('TableName' => name, 'ExclusiveStartKey' => exclusive_start_key)
74
+ puts r['Items'].map { |item| JSON.generate(item) }.join("\n")
75
+
76
+ ## recurse if more data to get
77
+ if r.has_key?('LastEvaluatedKey')
78
+ scan(name, r['LastEvaluatedKey'])
79
+ end
80
+ end
81
+
69
82
  desc 'put_items NAME', 'puts json items into the table with NAME'
70
83
  def put_items(name, file = nil)
71
84
  io = (file and File.open(file)) || ((not $stdin.tty?) and $stdin)
72
85
  count = 0
73
86
  io.each_line do |line|
74
- dynamodb.put_item(table_name: name, item: JSON.parse(line))
87
+ dynamodb_simple.put_item('TableName' => name, 'Item' => JSON.parse(line))
75
88
  count += 1
76
89
  end
77
90
  count.tap { |c| puts "put #{c} items" }
data/lib/awful/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = "0.0.29"
2
+ VERSION = "0.0.30"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ric Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-04 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler