fastly-ruby icon indicating copy to clipboard operation
fastly-ruby copied to clipboard

Configuration Error and Incorrect Docs Examples

Open kyleboe opened this issue 4 months ago • 1 comments

Version

fastly (13.1.0) Ruby 3.4.0

What happened

As stated in the README, I initialize the client with:

# Rails.application.credentials.fastly_api_token is a valid, confirmed-working API token
Fastly.configure do |config|
  config.api_token = Rails.application.credentials.fastly_api_token
end

This results in an error:

IndexError: string not matched
from .../fastly-13.1.0/lib/fastly/configuration.rb:60:in 'String#[]='

When setting api_key instead:

Fastly.configure do |config|
  config.api_key = Rails.application.credentials.fastly_api_token
end

There is no error and the value of Rails.application.credentials.fastly_api_token is the output.

However, with config.api_key set, all requests fail with a 401 response.

I can only get things working if I forcibly set the environment variable:

ENV["FASTLY_API_TOKEN"] = Rails.application.credentials.fastly_api_token

kyleboe avatar Jul 29 '25 16:07 kyleboe

I've deleted your comment which tagged an individual; there's no need to do that unless you've already talked with that individual about the issue and they've asked you to do so.

I'm no Ruby expert, but looking through the configuration.rb code the api_key accessor is for a hash, not a string. The keys of that hash are supposed to be the name used in the Authorization header (i.e. 'Token') and the values are the credential used in that header. Setting api_key to a string definitely will not work. You can try setting config.api_key['token'] = ... instead, although that's pretty much the same code that lives in config.api_token and so it should produce the same result.

It's very possible that Ruby's behavior related to adding new values in hashes has changed in recent versions and the code in this library has not been updated.

kpfleming avatar Jul 29 '25 18:07 kpfleming