r2store.rb 0.1.0 → 0.2.0
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 +4 -4
- data/lib/r2store/storage.rb +14 -14
- data/lib/r2store/webhook.rb +3 -3
- 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: 2ac7b1310d2ee967d839ca1639d2c47d1f096206bffdb7d40da82e2926423bba
|
|
4
|
+
data.tar.gz: ce5de61fa0c2c3a36a05c88736024d913f8263c769b13ad5f55bc354e479b9d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27a0d2cb5123e55417a14164ca69aa5f6efc5eaa5adfdcac3ae208b842ef9213a8560d14e15b957fd17483d397939b817d5fc014ab24bd010d6e9f13e2bfab4d
|
|
7
|
+
data.tar.gz: 2ce6db1e267074d07c6a051ca09d66fc5f10013529b01f486981e03894a1a731080847f680ae9c09ccacfe6b0db5d9e2f7a06aa222ad10c97895f339fd679906
|
data/lib/r2store/storage.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module R2Store
|
|
2
2
|
module Storage
|
|
3
3
|
class << self
|
|
4
|
-
def presigned_put(
|
|
5
|
-
key = scoped_key(
|
|
4
|
+
def presigned_put(tenant:, path:, content_type:, max_size:, expires_in: 3600)
|
|
5
|
+
key = scoped_key(tenant, path)
|
|
6
6
|
presigner.presigned_url(:put_object,
|
|
7
7
|
bucket: config.bucket,
|
|
8
8
|
key: key,
|
|
@@ -12,8 +12,8 @@ module R2Store
|
|
|
12
12
|
)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def presigned_get(
|
|
16
|
-
key = scoped_key(
|
|
15
|
+
def presigned_get(tenant:, path:, expires_in: 3600)
|
|
16
|
+
key = scoped_key(tenant, path)
|
|
17
17
|
presigner.presigned_url(:get_object,
|
|
18
18
|
bucket: config.bucket,
|
|
19
19
|
key: key,
|
|
@@ -21,8 +21,8 @@ module R2Store
|
|
|
21
21
|
)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
def head(
|
|
25
|
-
key = scoped_key(
|
|
24
|
+
def head(tenant:, path:)
|
|
25
|
+
key = scoped_key(tenant, path)
|
|
26
26
|
resp = client.head_object(bucket: config.bucket, key: key)
|
|
27
27
|
{
|
|
28
28
|
size: resp.content_length,
|
|
@@ -33,19 +33,19 @@ module R2Store
|
|
|
33
33
|
nil
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
def fetch(
|
|
37
|
-
key = scoped_key(
|
|
36
|
+
def fetch(tenant:, path:)
|
|
37
|
+
key = scoped_key(tenant, path)
|
|
38
38
|
resp = client.get_object(bucket: config.bucket, key: key)
|
|
39
39
|
resp.body.read
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
def delete(
|
|
43
|
-
key = scoped_key(
|
|
42
|
+
def delete(tenant:, path:)
|
|
43
|
+
key = scoped_key(tenant, path)
|
|
44
44
|
client.delete_object(bucket: config.bucket, key: key)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
def list(
|
|
48
|
-
full_prefix = "
|
|
47
|
+
def list(tenant:, prefix: nil)
|
|
48
|
+
full_prefix = "tenants/#{tenant}/"
|
|
49
49
|
full_prefix += prefix if prefix
|
|
50
50
|
validate_path!(full_prefix)
|
|
51
51
|
|
|
@@ -57,9 +57,9 @@ module R2Store
|
|
|
57
57
|
|
|
58
58
|
private
|
|
59
59
|
|
|
60
|
-
def scoped_key(
|
|
60
|
+
def scoped_key(tenant, path)
|
|
61
61
|
validate_path!(path)
|
|
62
|
-
"
|
|
62
|
+
"tenants/#{tenant}/#{path}"
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def validate_path!(path)
|
data/lib/r2store/webhook.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
module R2Store
|
|
2
2
|
module Webhook
|
|
3
3
|
Event = Struct.new(:type, :key, :size, :etag, :bucket, keyword_init: true) do
|
|
4
|
-
def
|
|
4
|
+
def tenant
|
|
5
5
|
parts = key.split("/")
|
|
6
|
-
return parts[1] if parts[0] == "
|
|
6
|
+
return parts[1] if parts[0] == "tenants" && parts.length >= 3
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def path
|
|
10
10
|
parts = key.split("/")
|
|
11
|
-
return parts[2..].join("/") if parts[0] == "
|
|
11
|
+
return parts[2..].join("/") if parts[0] == "tenants" && parts.length >= 3
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def product_manifest?
|