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

DRY up config for consumers of this gem #241

Merged
merged 6 commits into from
Oct 26, 2020
Merged

Conversation

benthorner
Copy link
Contributor

@benthorner benthorner commented Oct 22, 2020

@benthorner
Copy link
Contributor Author

Tested switching to new.external_url_for on email-alert-api in Integration ✅

Copy link
Member

@kevindew kevindew left a comment

Choose a reason for hiding this comment

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

This looks good, nice idea and approach 👍

I do wonder if we could go the whole hog and use the Rails.cache with this, as it feels a shame if we need to have the same GDS::SSO.config { |c| c.cache = Rails.cache } in most apps. I appreciate that's a bit of a pain though since it's not available at class parsing time. Though if we solve that (I recall you suggest a railstie which would do the trick) we could also clean up the api_only config which looks a bit logic heavy:

def self.api_only?
config = Rails.configuration
default = config.respond_to?(:api_only) ? config.api_only : false
@@api_only.nil? ? default : @@api_only
end
(I imagine I am to blame).

@@ -11,13 +12,15 @@ module Config

# OAuth ID
mattr_accessor :oauth_id
@@oauth_id = ENV.fetch("OAUTH_ID", "test-oauth-id")
Copy link
Member

Choose a reason for hiding this comment

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

I feel like the environment variables are rather generically named - which was a pre-existing problem but feels a bit worse now you couldn't find usage in the codebase with a grep. It'd be more conventional for them to be prefixed with GDS_SSO_ but can understand that'd be a bit of puppet pain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree the naming is short-sighted and could be more precise. I do think it's out-of-scope for the purpose of this change, since we don't currently have a clear conflict with these variables (until...accounts).

The naming doesn't seem to affect their discoverability, but they will become more hidden as a consequence of this change. I've added a couple of commits to refresh the README to help, which I also forgot to do earlier.

Copy link
Member

Choose a reason for hiding this comment

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

Sure no worries and agree it was out of scope for here. While it's fresh in minds I think I'm going to have a go at switching them to have a GDS_SSO prefix - unless you have reason to object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that's fine with me. I guess it's not too hard to do, although you'll need to do a fair few app deployments!

Ben Thorner added 2 commits October 26, 2020 10:11
Previously we required each consumer of this gem to have similar
initializers, with the following code:

    GDS::SSO.config do |config|
      config.user_model = "User"
      config.oauth_id = ENV.fetch("OAUTH_ID", "abcdefg")
      config.oauth_secret = ENV.fetch("OAUTH_SECRET", "secret")
      config.oauth_root_url = Plek.new.external_url_for("signon")*
    end

This updates the default config to match the common case for our
initializers, so that a given app only needs to specify additional
config, such as Rails caching.

Making this change removes a body of untested code that we would
otherwise need to consider testing before we could enable automatic
deployment for an app.

*Note that some apps use "Plek.find", which returns the internal
hostname for Signon. Since the external domain works for all apps,
this will switch all of them to use it.
This refreshes the installation instructions by removing the new
defaults from the suggested initializer, consolidating the layout,
and replacing the field list for the user table with a link to an
example migration field with them all in.
@benthorner
Copy link
Contributor Author

Tested switching to new initializer on email-alert-api locally:

  • Cache setting is indeed honoured ✅
  • API only setting is indeed honoured ✅

@benthorner
Copy link
Contributor Author

@kevindew I was wondering the same. Since centralising and DRYing up config is the overall aim of this change, I had a go at automating the cache config, as well as simplifying the api_only config like you mentioned.

This works, and I've added a few more commits for it.

Copy link
Contributor

@ChrisBAshton ChrisBAshton left a comment

Choose a reason for hiding this comment

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

LGTM 👍 a couple of snag comments, but nothing blocking the PR.

README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Ben Thorner added 4 commits October 26, 2020 14:05
This is to call some attention to it being necessary to define the
two environment variables.
Previously we required each API app to use efficient caching practices.
This DRYs up the manual, repetitive caching config, so that we always
cache bearer token responses unless configured otherwise.
Previously this involved a confusing mixture of two variables and
conditionals. This simplifies the logic to be equivalent to writing
the initializer inline, while still allowing it to be overridden.
@benthorner benthorner merged commit afdf773 into master Oct 26, 2020
@benthorner benthorner deleted the predefine-config branch October 26, 2020 14:46
benthorner pushed a commit to alphagov/content-publisher that referenced this pull request Oct 26, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/content-publisher that referenced this pull request Oct 26, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/email-alert-api that referenced this pull request Oct 26, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/whitehall that referenced this pull request Oct 27, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/travel-advice-publisher that referenced this pull request Oct 27, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/publishing-api that referenced this pull request Nov 5, 2020
benthorner pushed a commit to alphagov/release that referenced this pull request Nov 5, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/publisher that referenced this pull request Nov 6, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/maslow that referenced this pull request Nov 6, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/manuals-publisher that referenced this pull request Nov 6, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/local-links-manager that referenced this pull request Nov 9, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/link-checker-api that referenced this pull request Nov 9, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/places-manager that referenced this pull request Nov 9, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/hmrc-manuals-api that referenced this pull request Nov 9, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/content-tagger that referenced this pull request Nov 9, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/content-store that referenced this pull request Nov 9, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/content-data-api that referenced this pull request Nov 9, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/content-data-admin that referenced this pull request Nov 9, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/contacts-admin that referenced this pull request Nov 9, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
benthorner pushed a commit to alphagov/support that referenced this pull request Nov 10, 2020
This was made redundant in [1].

[1]: alphagov/gds-sso#241
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.

None yet

3 participants