imageomatic 0.1.0 → 0.1.1
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/config/initializers/mime_types.rb +1 -1
- data/lib/imageomatic/url_signature.rb +44 -0
- data/lib/imageomatic/version.rb +1 -1
- data/lib/imageomatic.rb +1 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7903eeab14e261a76042cba4e2a2127dc84bf4d1bb1c88d3cec3b2e8fddafa87
         | 
| 4 | 
            +
              data.tar.gz: 336a739324d3dc2216e9089bebff9e1a47f513cc3049906a3b036d4a73529ab9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e47c991db4e2d284a28853ab375864dc6d8a5cf12743c629694045ad7be2c822362797ebc3bc7afa15189c5154c7d98d68dc3f9ad4b97002781248e8134d0da5
         | 
| 7 | 
            +
              data.tar.gz: 91a59cce1f7a876d4fec576c6f7560e043ff0ac996308370abad4403fe392594383a869bf77506bb19d37b5818451522565efded925a9d774a457879756fa6f1
         | 
| @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            require "openssl"
         | 
| 2 | 
            +
            require "uri"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Imageomatic
         | 
| 5 | 
            +
              class UrlSignature
         | 
| 6 | 
            +
                # Use for `OpenSSL::HMAC`
         | 
| 7 | 
            +
                DIGEST = "SHA256".freeze
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                attr_reader :secret_key, :public_key, :path_prefix
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def initialize(secret_key:, public_key:)
         | 
| 12 | 
            +
                  @secret_key = secret_key
         | 
| 13 | 
            +
                  @public_key = public_key
         | 
| 14 | 
            +
                  @path_prefix = File.join("/", "v1", public_key)
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def signed_url(path)
         | 
| 18 | 
            +
                  URI.join("https://www.imageomatic.com/", signed_path(path))
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def valid?(url)
         | 
| 22 | 
            +
                  path = URI(url).request_uri
         | 
| 23 | 
            +
                  version, account_key, signature, path = Regexp.new("/(v1)/(.+?)/(.+?)(/.+)").match(path).captures
         | 
| 24 | 
            +
                  signature == sign(path)
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                def url_for(path, **query)
         | 
| 28 | 
            +
                  path = URI(path).tap do |url|
         | 
| 29 | 
            +
                    url.path = path
         | 
| 30 | 
            +
                    url.query = query.to_query
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                  signed_url path
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                private
         | 
| 36 | 
            +
                  def signed_path(path)
         | 
| 37 | 
            +
                    File.join(path_prefix, sign(File.join("/", path.to_s)), path.to_s)
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def sign(data)
         | 
| 41 | 
            +
                    OpenSSL::HMAC.hexdigest(DIGEST, secret_key, data)
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
            end
         | 
    
        data/lib/imageomatic/version.rb
    CHANGED
    
    
    
        data/lib/imageomatic.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: imageomatic
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Brad Gessler
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022-06- | 
| 11 | 
            +
            date: 2022-06-17 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         | 
| @@ -53,6 +53,7 @@ files: | |
| 53 53 | 
             
            - lib/generators/imageomatic/install/templates/application.opengraph.erb
         | 
| 54 54 | 
             
            - lib/imageomatic.rb
         | 
| 55 55 | 
             
            - lib/imageomatic/engine.rb
         | 
| 56 | 
            +
            - lib/imageomatic/url_signature.rb
         | 
| 56 57 | 
             
            - lib/imageomatic/version.rb
         | 
| 57 58 | 
             
            - lib/tasks/imageomatic_tasks.rake
         | 
| 58 59 | 
             
            homepage: https://www.imageomatic.com/
         |