Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional configuration without environment variables #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

trusche
Copy link

@trusche trusche commented Aug 7, 2024

Hi @coorasse,

we just started using your gem in our Rails app, it's working great, so thank you, first of all!

We ran into a bit of trouble deploying this, though. If any of the required env variables is not set, not only will the gem not work (expected and acceptable), but the rails app will fail to start (not so good 😁 ).

This PR adds a couple of configuration changes, and might help addressing both #34 and #5.

  • A configuration option for the check on required configuration attributes (defaults to true, so no behaviour change on upgrade, it must be set to false explicitly in an initializer)
  • Replaced the use of all env variables with the equivalent configuration option - they're already assigned from env vars on startup, so might as well use them. This allows users to configure the gem completely from within an initalizer, with env variables or other mechanisms like Rails secrets.

Tests are still passing, but I didn't add any new ones since I'm more familiar with rspec and a bit short on time right now. Happy to amend that sometime later if needed.

Cheers,
Thilo

@@ -20,18 +20,35 @@ def self.configure
yield(configuration) if block_given?
end

def self.configured?
self.configuration&.configured?
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thrown that in here since we use it in our app to conditionally display passkit-related view code only if the gem is properly configured.

@@ -123,14 +121,18 @@ def generate_json_manifest
File.write(@manifest_url, manifest.to_json)
end

CERTIFICATE = Rails.root.join(ENV["PASSKIT_PRIVATE_P12_CERTIFICATE"])
INTERMEDIATE_CERTIFICATE = Rails.root.join(ENV["PASSKIT_APPLE_INTERMEDIATE_CERTIFICATE"])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants are evaluated at load time, not runtime, so if those envs are nil, this will raise an error at startup of a rails app with eager_load = true. This bit us in production no less, because in staging we had everything configured correctly, and in local environment classes are not eager loaded, so it didn't manifest there.

@trusche trusche force-pushed the main branch 5 times, most recently from e34a641 to 1ecc0c2 Compare August 8, 2024 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant