cloudflared 0.1.0 → 0.1.1

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: a70d9d3f9d8e49c536fb019c0bc5052e4cc900d65cd1a5f616a44a56d7c0636f
4
- data.tar.gz: e9351f030dc93db44391dd0685c3580a9269a0af63912da46a4051a710df945e
3
+ metadata.gz: 5d9bb494988767889b7a6389bfb73ab51cbbe0f0ff62ab769db00c2810fa47fc
4
+ data.tar.gz: 074b5ddbe705f87dfd346147c9a971842d649bb193f4aabd23a8db2217be5864
5
5
  SHA512:
6
- metadata.gz: 8e9d5fe29cdae2bb50acd520a58a7357bcf5b57075524a3034869cbe92424eeca0994c99680f10c275818dcda9d7b40a1d26abdb66ce612e9a4b9660a353547a
7
- data.tar.gz: d15e523393ce50cc5e6395e34ac8b4b06c22301268f0dcd0c9b497e79f84ed8cd22463a6f3d6cf29966dba3de66d0d936061cc1416f5b487d363cb230f03bbd2
6
+ metadata.gz: 8729793b880b6b03e1214493bdb895f2d7c7839c99e8df38669effe4592bd6aae13416ecdd541a21fa5172e3a8c9a48fc8830171e60a40c6dd83a019e9abcb13
7
+ data.tar.gz: 8a3987f4dc99b8bc29558884adffeb05165ef9e3f933bdf341838e16036537ff09869cc4c2df9f4dc7650c65e682ff3c865669acc2f8146662903922446de165
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudflared (0.1.3)
4
+ cloudflared (0.1.0)
5
5
  faraday (~> 2.1.0)
6
6
  faraday-multipart (~> 1.0, >= 1.0.3)
7
7
  marcel (~> 1.0, >= 1.0.2)
data/README.md CHANGED
@@ -23,23 +23,51 @@ Or install it yourself as:
23
23
 
24
24
  $ gem install cloudflared
25
25
 
26
+ ## Setup
27
+
28
+ You will need the following keys from your Cloudflare account:
29
+
30
+
26
31
  ## Usage
27
32
 
28
33
  Working with Cloudflare Images:
29
34
 
30
35
  ```ruby
31
- client = Cloudflared::Client.new(api_key: "foo", account_id: "bar", images_hash: "baz")
36
+ client = Cloudflared::Client.new(api_key: "foo", account_id: "bar", images_hash: "baz", images_default_hash: "foobar")
32
37
  client.images.delete(file_id: "1234")
33
38
  client.images.details(file_id: "1234")
34
39
  client.images.direct_upload_url
35
40
  client.images.download(file_id: "1234")
36
41
  client.images.list
37
- client.images.signed_url(file_id: "1234", key: "default_key", expiry_seconds: 60 * 15)
42
+ client.images.signed_url(file_id: "1234", expiry_seconds: 60 * 15)
38
43
  client.images.stats
39
44
  client.images.update(file_id: "1234", requireSignedURLs: true)
40
45
  client.images.upload(file: "/path/to/file", requireSignedURLs: true)
41
46
  ```
42
47
 
48
+ #### Rails and Pre-configured client settings
49
+
50
+ If you're using this in rails (or want to pre-configure settings), you can pre-configure the client settings via an initializer by adding the following:
51
+
52
+ ```ruby
53
+ # config/initializers/cloudflared.rb
54
+
55
+ Cloudflared.configure do |config|
56
+ config.api_key = "key"
57
+ config.account_id = "key"
58
+ config.images_hash = "key"
59
+ config.images_default_key = "key"
60
+ config.adapter = Faraday.default_adapter # optional, defaults to Faraday.default_adapter
61
+ end
62
+ ```
63
+
64
+ If pre-configured, the client is available via the following shortcut:
65
+
66
+ ```ruby
67
+ client = Cloudflared.client
68
+ client.images.details(file_id: "1234")
69
+ ```
70
+
43
71
  ## Development
44
72
 
45
73
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/bin/console CHANGED
@@ -11,7 +11,11 @@ require "cloudflared"
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- @client = Cloudflared::Client.new(account_id: ENV["CLOUDFLARE_IMAGES_ACCOUNT_ID"], api_key: ENV["CLOUDFLARE_IMAGES_API_KEY"])
14
+ @client = Cloudflared::Client.new(
15
+ account_id: ENV["CLOUDFLARE_IMAGES_ACCOUNT_ID"],
16
+ api_key: ENV["CLOUDFLARE_IMAGES_API_KEY"],
17
+ images_hash: ENV["CLOUDFLARE_IMAGES_HASH"],
18
+ images_default_key: ENV["CLOUDFLARE_IMAGES_DEFAULT_KEY"])
15
19
 
16
20
  require "irb"
17
21
  IRB.start(__FILE__)
@@ -4,7 +4,7 @@ module Cloudflared
4
4
  class Client
5
5
  BASE_URL = "https://api.cloudflare.com/client/v4/accounts"
6
6
 
7
- attr_reader :api_key, :account_id, :adapter, :images_hash
7
+ attr_reader :api_key, :account_id, :adapter, :images_hash, :images_default_key, :stubs
8
8
 
9
9
  # Initializes a new Cloudflare client.
10
10
  #
@@ -17,6 +17,9 @@ module Cloudflared
17
17
  # @!attribute images_hash
18
18
  # @return [String] The Cloudflare images hash found on the images dashboard. This is used for image delivery urls.
19
19
  #
20
+ # @!attribute images_default_key
21
+ # @return [String] The default key for signing private images
22
+ #
20
23
  # @!attribute adapter
21
24
  # @return [Symbol] The Faraday adapter to use
22
25
  #
@@ -24,11 +27,12 @@ module Cloudflared
24
27
  # @return [Symbol] Stubs for use in testing
25
28
  #
26
29
  # @return [Cloudflared]
27
- def initialize(api_key:, account_id:, images_hash: nil, adapter: Faraday.default_adapter, stubs: nil)
30
+ def initialize(api_key:, account_id:, images_hash:, images_default_key:, adapter: Faraday.default_adapter, stubs: nil)
28
31
  @api_key = api_key
29
32
  @adapter = adapter
30
33
  @account_id = account_id
31
34
  @images_hash = images_hash
35
+ @images_default_key = images_default_key
32
36
  @stubs = stubs
33
37
  end
34
38
 
@@ -0,0 +1,14 @@
1
+ module Cloudflared
2
+ # Class used to initialize configuration object.
3
+ class Config
4
+ attr_accessor :api_key
5
+ attr_accessor :account_id
6
+ attr_accessor :images_hash
7
+ attr_accessor :images_default_key
8
+ attr_accessor :adapter
9
+ attr_accessor :stubs
10
+
11
+ def initialize
12
+ end
13
+ end
14
+ end
@@ -34,13 +34,13 @@ module Cloudflared
34
34
  "#{IMAGE_DELIVERY_URL}/#{@client.images_hash}/#{path}"
35
35
  end
36
36
 
37
- def signed_url(path, key:, expiry_seconds: FIFTEEN_MINUTES)
37
+ def signed_url(path, expiry_seconds: FIFTEEN_MINUTES)
38
38
  # The path uses the image + the file_id (and a variant if passed through)
39
39
  path = path[1..] if path[0] == "/"
40
40
  path = "#{@client.images_hash}/#{path}"
41
41
 
42
42
  # Calculate the hexdigest with the leading slash
43
- sig = OpenSSL::HMAC.hexdigest("SHA256", key, "/#{path}")
43
+ sig = OpenSSL::HMAC.hexdigest("SHA256", @client.images_default_key, "/#{path}")
44
44
 
45
45
  # Calculate the seconds since the epoch in the future
46
46
  exp = Time.new.to_i + expiry_seconds
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudflared
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/cloudflared.rb CHANGED
@@ -4,11 +4,43 @@ require_relative "cloudflared/version"
4
4
 
5
5
  module Cloudflared
6
6
  autoload :Client, "cloudflared/client"
7
- autoload :Error, "cloudflared/error"
8
7
  autoload :Collection, "cloudflared/collection"
8
+ autoload :Config, "cloudflared/config"
9
+ autoload :Error, "cloudflared/error"
9
10
  autoload :Object, "cloudflared/object"
10
11
  autoload :Resource, "cloudflared/resource"
11
12
 
12
13
  autoload :Image, "cloudflared/objects/image"
13
14
  autoload :ImagesResource, "cloudflared/resources/images"
15
+
16
+ # Returns Cloudflared's configuration object.
17
+ def self.config
18
+ @config ||= Cloudflared::Config.new
19
+ end
20
+
21
+ # Creates a client instance with pre-configured values
22
+ def self.client
23
+ Cloudflared::Client.new(
24
+ api_key: config.api_key,
25
+ account_id: config.account_id,
26
+ images_hash: config.images_hash,
27
+ images_default_key: config.images_default_key,
28
+ adapter: config.adapter || Faraday.default_adapter
29
+ )
30
+ end
31
+
32
+ # Lets you set global configuration options.
33
+ #
34
+ # All available options and their defaults are in the example below:
35
+ # @example Initializer for Rails
36
+ # Cloudflared.configure do |config|
37
+ # config.api_key = "key"
38
+ # config.account_id = "secret"
39
+ # config.images_hash = "hash"
40
+ # config.images_default_key = "key"
41
+ # config.adapter = Faraday.default_adapter
42
+ # end
43
+ def self.configure(&block)
44
+ yield(config) if block
45
+ end
14
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - devynbit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-31 00:00:00.000000000 Z
11
+ date: 2022-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -87,6 +87,7 @@ files:
87
87
  - lib/cloudflared.rb
88
88
  - lib/cloudflared/client.rb
89
89
  - lib/cloudflared/collection.rb
90
+ - lib/cloudflared/config.rb
90
91
  - lib/cloudflared/error.rb
91
92
  - lib/cloudflared/object.rb
92
93
  - lib/cloudflared/objects/image.rb