brutalismbot 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brutalismbot/posts/client.rb +8 -8
- data/lib/brutalismbot/posts/stub.rb +0 -1
- data/lib/brutalismbot/s3/client.rb +20 -14
- data/lib/brutalismbot/slack/auth.rb +10 -6
- data/lib/brutalismbot/slack/client.rb +9 -9
- data/lib/brutalismbot/slack/stub.rb +0 -1
- data/lib/brutalismbot/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b1a53227321c1d498e19fadd19c6672765235e10de63d5182028ef88e97f6ea
|
4
|
+
data.tar.gz: 7412d9894367b09119948295333c7e5d40444b1cdca4e686a045de33bcabd20a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52ee57689c45dd034e4660ebe2923edd424ee3bf47181d3e858ad023d12ca7937fef43a0f2acb2eeedf2b7bc350675b945c1ed5da24abadd440531091aa6ecd1
|
7
|
+
data.tar.gz: 1df7a1413841387e689078238a2ee786ea06a682b39a80865d856f408f91aa2419647def2ba33910f32e37dd91b589690867dc386234631103b3005768bcea2b
|
@@ -18,8 +18,8 @@ module Brutalismbot
|
|
18
18
|
File.join(@prefix, post.path)
|
19
19
|
end
|
20
20
|
|
21
|
-
def get(
|
22
|
-
super {|object| Reddit::Post.parse(object.
|
21
|
+
def get(**options)
|
22
|
+
super {|object| Reddit::Post.parse(object.body.read) }
|
23
23
|
end
|
24
24
|
|
25
25
|
def last
|
@@ -28,7 +28,7 @@ module Brutalismbot
|
|
28
28
|
|
29
29
|
def list(**options)
|
30
30
|
super(**options) do |object|
|
31
|
-
Brutalismbot.logger.info("GET s3://#{@bucket
|
31
|
+
Brutalismbot.logger.info("GET s3://#{@bucket}/#{object.key}")
|
32
32
|
Reddit::Post.parse(object.get.body.read)
|
33
33
|
end
|
34
34
|
end
|
@@ -36,12 +36,12 @@ module Brutalismbot
|
|
36
36
|
def max_key
|
37
37
|
# Dig for max key
|
38
38
|
prefix = Time.now.utc.strftime("#{@prefix}year=%Y/month=%Y-%m/day=%Y-%m-%d/")
|
39
|
-
Brutalismbot.logger.info("GET s3://#{@bucket
|
39
|
+
Brutalismbot.logger.info("GET s3://#{@bucket}/#{prefix}*")
|
40
40
|
|
41
41
|
# Go up a level in prefix if no keys found
|
42
|
-
until (keys =
|
42
|
+
until (keys = bucket.objects(prefix: prefix)).any? || prefix == @prefix
|
43
43
|
prefix = prefix.split(/[^\/]+\/\z/).first
|
44
|
-
Brutalismbot.logger.info("GET s3://#{@bucket
|
44
|
+
Brutalismbot.logger.info("GET s3://#{@bucket}/#{prefix}*")
|
45
45
|
end
|
46
46
|
|
47
47
|
# Return max by key
|
@@ -54,9 +54,9 @@ module Brutalismbot
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def push(post, dryrun:nil)
|
57
|
-
options = post.to_s3(bucket: @bucket
|
57
|
+
options = post.to_s3(bucket: @bucket, prefix: @prefix)
|
58
58
|
Brutalismbot.logger.info("PUT #{"DRYRUN " if dryrun}s3://#{options[:bucket]}/#{options[:key]}")
|
59
|
-
@
|
59
|
+
@client.put_object(**options) unless dryrun
|
60
60
|
options.slice(:bucket, :key, :metadata)
|
61
61
|
end
|
62
62
|
end
|
@@ -10,7 +10,6 @@ module Brutalismbot
|
|
10
10
|
items = items.map{|x| [key_for(x), x.to_h] }.to_h
|
11
11
|
|
12
12
|
@client = Aws::S3::Client.new(stub_responses: true)
|
13
|
-
@bucket = Aws::S3::Bucket.new(name: @bucket.name, client: @client)
|
14
13
|
|
15
14
|
@client.stub_responses :list_objects_v2, -> (context) do
|
16
15
|
keys = items.keys.select{|x| x.start_with? context.params[:prefix] }
|
@@ -3,27 +3,33 @@ require "aws-sdk-s3"
|
|
3
3
|
module Brutalismbot
|
4
4
|
module S3
|
5
5
|
class Client
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :prefix, :client
|
7
7
|
|
8
8
|
def initialize(bucket:nil, prefix:nil, client:nil)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@bucket = Aws::S3::Bucket.new(name: bucket, client: client)
|
13
|
-
@client = client
|
14
|
-
@prefix = prefix
|
9
|
+
@client = client || Aws::S3::Client.new
|
10
|
+
@bucket = bucket || ENV["S3_BUCKET"] || "brutalismbot"
|
11
|
+
@prefix = prefix || ENV["S3_PREFIX"] || "data/v1/"
|
15
12
|
end
|
16
13
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
14
|
+
def bucket(**options)
|
15
|
+
options[:name] ||= @bucket
|
16
|
+
options[:client] ||= @client
|
17
|
+
Aws::S3::Bucket.new(**options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(key:, bucket:nil, **options, &block)
|
21
|
+
bucket ||= @bucket
|
22
|
+
Brutalismbot.logger.info("GET s3://#{@bucket}/#{key}")
|
23
|
+
object = @client.get_object(bucket: bucket, key: key, **options)
|
20
24
|
block_given? ? yield(object) : object
|
21
25
|
end
|
22
26
|
|
23
|
-
def list(**options, &block)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
def list(bucket:nil, prefix:nil, **options, &block)
|
28
|
+
bucket ||= @bucket
|
29
|
+
prefix ||= @prefix
|
30
|
+
Brutalismbot.logger.info("LIST s3://#{@bucket}/#{prefix}*")
|
31
|
+
result = self.bucket(name: bucket).objects(prefix: prefix, **options)
|
32
|
+
Prefix.new(result, &block)
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
@@ -12,12 +12,8 @@ module Brutalismbot
|
|
12
12
|
@item.dig("incoming_webhook", "channel_id")
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def webhook_url
|
20
|
-
@item.dig("incoming_webhook", "url")
|
15
|
+
def inspect
|
16
|
+
"#<#{self.class} #{team_id}/#{channel_id}>"
|
21
17
|
end
|
22
18
|
|
23
19
|
def path
|
@@ -39,6 +35,14 @@ module Brutalismbot
|
|
39
35
|
Net::HTTPOK.new("1.1", "204", "ok")
|
40
36
|
end
|
41
37
|
end
|
38
|
+
|
39
|
+
def team_id
|
40
|
+
@item.dig("team_id")
|
41
|
+
end
|
42
|
+
|
43
|
+
def webhook_url
|
44
|
+
@item.dig("incoming_webhook", "url")
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
@@ -16,21 +16,21 @@ module Brutalismbot
|
|
16
16
|
|
17
17
|
def install(auth, dryrun:nil)
|
18
18
|
key = key_for(auth)
|
19
|
-
Brutalismbot.logger.info("PUT #{"DRYRUN " if dryrun}s3://#{@bucket
|
20
|
-
@
|
19
|
+
Brutalismbot.logger.info("PUT #{"DRYRUN " if dryrun}s3://#{@bucket}/#{key}")
|
20
|
+
@client.put_object(bucket: @bucket, key: key, body: auth.to_json) unless dryrun
|
21
21
|
end
|
22
22
|
|
23
23
|
def key_for(auth)
|
24
24
|
File.join(@prefix, auth.path)
|
25
25
|
end
|
26
26
|
|
27
|
-
def get(
|
28
|
-
super {|object| Auth.parse(object.
|
27
|
+
def get(**options)
|
28
|
+
super {|object| Auth.parse(object.body.read) }
|
29
29
|
end
|
30
30
|
|
31
31
|
def list(**options)
|
32
32
|
super(**options) do |object|
|
33
|
-
Brutalismbot.logger.info("GET s3://#{@bucket
|
33
|
+
Brutalismbot.logger.info("GET s3://#{@bucket}/#{object.key}")
|
34
34
|
Auth.parse(object.get.body.read)
|
35
35
|
end
|
36
36
|
end
|
@@ -38,16 +38,16 @@ module Brutalismbot
|
|
38
38
|
def push(post, dryrun:nil)
|
39
39
|
list.map do |auth|
|
40
40
|
key = key_for(auth)
|
41
|
-
Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}s3://#{@bucket
|
41
|
+
Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}s3://#{@bucket}/#{key}")
|
42
42
|
auth.push(post, dryrun: dryrun)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def uninstall(auth, dryrun:nil)
|
47
47
|
prefix = File.join(@prefix, "team=#{auth.team_id}/")
|
48
|
-
Brutalismbot.logger.info("LIST s3://#{@bucket
|
49
|
-
|
50
|
-
Brutalismbot.logger.info("DELETE #{"DRYRUN " if dryrun}s3://#{@bucket
|
48
|
+
Brutalismbot.logger.info("LIST s3://#{@bucket}/#{prefix}*")
|
49
|
+
bucket.objects(prefix: prefix).map do |object|
|
50
|
+
Brutalismbot.logger.info("DELETE #{"DRYRUN " if dryrun}s3://#{@bucket}/#{object.key}")
|
51
51
|
object.delete unless dryrun
|
52
52
|
end
|
53
53
|
end
|
@@ -12,7 +12,6 @@ module Brutalismbot
|
|
12
12
|
items = items.map{|x| [key_for(x), x.to_h] }.to_h
|
13
13
|
|
14
14
|
@client = Aws::S3::Client.new(stub_responses: true)
|
15
|
-
@bucket = Aws::S3::Bucket.new(name: @bucket.name, client: @client)
|
16
15
|
|
17
16
|
@client.stub_responses :list_objects_v2, -> (context) do
|
18
17
|
keys = items.keys.select{|x| x.start_with? context.params[:prefix] }
|
data/lib/brutalismbot/version.rb
CHANGED