cloudflare_storage 0.1.0 → 0.1.2
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/README.md +2 -4
- data/lib/cloudflare_storage/client.rb +42 -0
- data/lib/cloudflare_storage/error.rb +7 -0
- data/lib/{workers_kv → cloudflare_storage}/keys.rb +2 -2
- data/lib/{workers_kv → cloudflare_storage}/values.rb +2 -2
- data/lib/cloudflare_storage/version.rb +3 -0
- data/lib/cloudflare_storage.rb +44 -35
- metadata +23 -7
- data/lib/workers_kv/client.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 318cee73402c3107f230b6d46531935e6fb8bfae9a7b74ba18f6b7615683aa7a
|
4
|
+
data.tar.gz: ff3816282d78df06af6627cbefd8c3b428edd1ece0e58c38ef19b498a9d11b80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5f4f147aa8dcce0b7d076c66b184f40d4766ee1e8cac338abb0edba332573914a8bd77ff529e501f6847d4ae621cf1ec30cf3346aafe82360e28d1d67eb2150
|
7
|
+
data.tar.gz: 62c39d580db6a23864869f78df1db196333e57921754066371917dc609b4155465b992cc4624ad2f4831bac627c0cff496aed60cfdf9e2928461db28cb7a46e6
|
data/README.md
CHANGED
@@ -6,11 +6,9 @@ It was designed to let you get started with minimal configuration.
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
9
|
Add this line to your application's Gemfile:
|
12
10
|
|
13
|
-
|
11
|
+
```
|
14
12
|
gem 'cloudflare_storage'
|
15
13
|
```
|
16
14
|
|
@@ -43,7 +41,7 @@ end
|
|
43
41
|
|
44
42
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
43
|
|
46
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`,
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, then create a new git tag and push it. Github actions will take care of the rest.
|
47
45
|
|
48
46
|
## Contributing
|
49
47
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
module CloudflareStorage
|
3
|
+
class Client
|
4
|
+
def initialize(account_id, namespace_id, token, connection = nil)
|
5
|
+
raise MissingCredentialsError, "Please configure account_id" if account_id.nil?
|
6
|
+
raise MissingCredentialsError, "Please configure namespace_id" if namespace_id.nil?
|
7
|
+
raise MissingCredentialsError, "Please configure token" if token.nil?
|
8
|
+
|
9
|
+
@conn = connection || Faraday.new(url: "https://api.cloudflare.com/client/v4/accounts/#{account_id}/storage/kv/namespaces/#{namespace_id}/" ) do |builder|
|
10
|
+
builder.request :authorization, "Bearer", token
|
11
|
+
builder.request :json
|
12
|
+
builder.response :json
|
13
|
+
builder.response :raise_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def values
|
18
|
+
@values ||= Values.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def keys
|
22
|
+
@keys ||= Keys.new(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def get(path, params = nil)
|
27
|
+
@conn.get path do |req|
|
28
|
+
req.params = params if params && !params.empty?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def put(path, body)
|
33
|
+
@conn.put path do |req|
|
34
|
+
req.body = body
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def conn_delete(path)
|
39
|
+
@conn.delete path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module CloudflareStorage
|
2
2
|
class Keys < Client
|
3
3
|
|
4
4
|
def initialize(client)
|
@@ -6,7 +6,7 @@ module WorkersKV
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def list(prefix)
|
9
|
-
if prefix.
|
9
|
+
if prefix && !prefix.empty?
|
10
10
|
@client.get("keys", { "prefix": prefix })
|
11
11
|
else
|
12
12
|
@client.get("keys")
|
data/lib/cloudflare_storage.rb
CHANGED
@@ -1,43 +1,52 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require_relative "
|
3
|
-
require_relative "
|
4
|
-
require_relative "
|
2
|
+
require_relative "cloudflare_storage/client"
|
3
|
+
require_relative "cloudflare_storage/values"
|
4
|
+
require_relative "cloudflare_storage/keys"
|
5
|
+
require_relative "cloudflare_storage/version"
|
6
|
+
require_relative "cloudflare_storage/error"
|
5
7
|
|
6
8
|
|
7
|
-
|
9
|
+
module CloudflareStorage
|
8
10
|
class << self
|
9
|
-
attr_accessor :
|
11
|
+
attr_accessor :configuration
|
12
|
+
|
13
|
+
def configure(&block)
|
14
|
+
self.configuration ||= Configuration.new
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
|
18
|
+
def conn
|
19
|
+
raise MissingCredentialsError, "CloudflareStorage not configured" if CloudflareStorage.configuration.nil?
|
20
|
+
@connection ||= Client.new(
|
21
|
+
CloudflareStorage.configuration.account_id,
|
22
|
+
CloudflareStorage.configuration.namespace_id,
|
23
|
+
CloudflareStorage.configuration.token,
|
24
|
+
CloudflareStorage.configuration.connection
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def list(prefix = nil)
|
29
|
+
resp = conn.keys.list(prefix)
|
30
|
+
resp.body.dig("result").pluck("name")
|
31
|
+
end
|
32
|
+
|
33
|
+
def read(key)
|
34
|
+
resp = conn.values.read(key)
|
35
|
+
resp.body
|
36
|
+
end
|
37
|
+
|
38
|
+
def write(key, value)
|
39
|
+
resp = conn.values.write(key, value)
|
40
|
+
resp.body
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete(key)
|
44
|
+
resp = conn.values.delete(key)
|
45
|
+
resp.body
|
46
|
+
end
|
10
47
|
end
|
11
48
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def conn
|
17
|
-
@connection ||= WorkersKV::Client.new(
|
18
|
-
CloudflareStorage.account_id,
|
19
|
-
CloudflareStorage.namespace_id,
|
20
|
-
CloudflareStorage.token
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
def list(prefix = nil)
|
25
|
-
resp = conn.keys.list(prefix)
|
26
|
-
resp.body.dig("result").pluck("name")
|
27
|
-
end
|
28
|
-
|
29
|
-
def read(key)
|
30
|
-
resp = conn.values.read(key)
|
31
|
-
resp.body
|
32
|
-
end
|
33
|
-
|
34
|
-
def write(key, value)
|
35
|
-
resp = conn.values.write(key, value)
|
36
|
-
resp.body
|
37
|
-
end
|
38
|
-
|
39
|
-
def delete(key)
|
40
|
-
resp = conn.values.delete(key)
|
41
|
-
resp.body
|
49
|
+
class Configuration
|
50
|
+
attr_accessor :account_id, :namespace_id, :token, :connection
|
42
51
|
end
|
43
52
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudflare_storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- "@geetotes"
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
12
|
-
dependencies:
|
11
|
+
date: 2025-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
13
27
|
description: Library for interacting with Cloudflare Workers KV Storage and configuring
|
14
28
|
connection from a Rails application.
|
15
29
|
email:
|
@@ -24,9 +38,11 @@ files:
|
|
24
38
|
- README.md
|
25
39
|
- Rakefile
|
26
40
|
- lib/cloudflare_storage.rb
|
27
|
-
- lib/
|
28
|
-
- lib/
|
29
|
-
- lib/
|
41
|
+
- lib/cloudflare_storage/client.rb
|
42
|
+
- lib/cloudflare_storage/error.rb
|
43
|
+
- lib/cloudflare_storage/keys.rb
|
44
|
+
- lib/cloudflare_storage/values.rb
|
45
|
+
- lib/cloudflare_storage/version.rb
|
30
46
|
- sig/cloudflare_storage.rbs
|
31
47
|
homepage: https://github.com/geetotes/cloudflare_storage
|
32
48
|
licenses:
|
data/lib/workers_kv/client.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module WorkersKV
|
2
|
-
class Client
|
3
|
-
def initialize(account_id, namespace_id, token)
|
4
|
-
@conn = Faraday.new(url: "https://api.cloudflare.com/client/v4/accounts/#{account_id}/storage/kv/namespaces/#{namespace_id}/" ) do |builder|
|
5
|
-
builder.request :authorization, "Bearer", token
|
6
|
-
builder.request :json
|
7
|
-
builder.response :json
|
8
|
-
builder.response :raise_error
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def values
|
13
|
-
@values ||= Values.new(self)
|
14
|
-
end
|
15
|
-
|
16
|
-
def keys
|
17
|
-
@keys ||= Keys.new(self)
|
18
|
-
end
|
19
|
-
|
20
|
-
protected
|
21
|
-
def get(path, params = nil)
|
22
|
-
@conn.get path do |req|
|
23
|
-
req.params = params if params.present?
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def put(path, body)
|
28
|
-
@conn.put path do |req|
|
29
|
-
req.body = body
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def conn_delete(path)
|
34
|
-
@conn.delete path
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|