uploadcare / uploadcare-ruby

Ruby API client that handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.
https://uploadcare.com
MIT License
39 stars 28 forks source link

Figaro: key not found: "UPLOADCARE_PUBLIC_KEY" #117

Closed georgesve closed 1 year ago

georgesve commented 1 year ago

key not found: "UPLOADCARE_PUBLIC_KEY"

When using Figaro for storing keys in application.yml I get the following error message when running rails c or rails s:

/Users/xx/.rvm/gems/ruby-3.1.2/gems/uploadcare-ruby-4.2.0/lib/uploadcare.rb:48:in `fetch': key not found: "UPLOADCARE_PUBLIC_KEY" (KeyError)

from /Users/xx/.rvm/gems/ruby-3.1.2/gems/uploadcare-ruby-4.2.0/lib/uploadcare.rb:48:in `<module:Uploadcare>'

It works when I manually import the keys like so

export UPLOADCARE_PUBLIC_KEY=your_public_key
export UPLOADCARE_SECRET_KEY=your_private_key

But I get the following warning + I have to manually export keys on every new terminal I work on:

WARNING: Skipping key "UPLOADCARE_PUBLIC_KEY". Already set in ENV.
WARNING: Skipping key "UPLOADCARE_SECRET_KEY". Already set in ENV.

uploadcare.rb

Uploadcare::Rails.configure do |config|
  config.public_key = ENV.fetch('UPLOADCARE_PUBLIC_KEY', 'demopublickey')
  config.secret_key = ENV.fetch('UPLOADCARE_SECRET_KEY', 'demosecretkey')
 ...
end

Expected behavior

I should be able to set the variables in application.yml

Code / screenshots

Environment

gemfile.lock

uploadcare-rails (3.2.0)
      rails (>= 4)
      uploadcare-ruby (>= 4.2)
uploadcare-ruby (4.2.0)
      api_struct (~> 1.0.1)
      mimemagic
      parallel
      retries
dry-configurable (= 0.13.0)

ruby-3.1.2

rails, 6.1.6

kraft001 commented 1 year ago

@georgesve Yes, indeed, ENV keys were fetched in the gem before Figaro initialized them. Fixed in the new version 4.3.1, you can find a sample application with Figjam here. I used Figjam as a new version of Figaro, as it's described in this comment Please, try it and let me know if you still experience the issue.

georgesve commented 1 year ago

@kraft001 problem solved with your fix ! thanks 👍