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

Subdomains #1786

Closed
wants to merge 10 commits into from
Closed

Subdomains #1786

wants to merge 10 commits into from

Conversation

murny
Copy link
Contributor

@murny murny commented Jul 29, 2020

This PR wraps all current routes under an "ERA" subdomain. Which sets up the foundation for allowing multiple front doors going forward.


class Aip::V1::CollectionsControllerTest < ActionDispatch::IntegrationTest

include AipHelper

def setup
setup do
Copy link
Contributor Author

@murny murny Jul 29, 2020

Choose a reason for hiding this comment

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

Slight difference here. setup do hooks into all setup blocks in the inheritance where as def setup doesn't.

As a result, this was flaking if this test ran first as our host configuration never ran yet.

@@ -1,11 +1,11 @@
require 'test_helper'
require Rails.root.join('test/support/aip_helper')
require 'support/aip_helper'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use a relative require here instead (no different then require 'test_helper')

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried that so many times with no luck ¯_(ツ)_/¯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha yeah not sure. Seems to work on my local and CI likes it 🤷

@murny murny changed the title Subdomains WIP: Subdomains Jul 29, 2020
@@ -6,11 +6,11 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://localhost/aip/v1/items/2107bfb6-2670-4ffc-94a1-aeb4f8c1fd81> a pcdm:Object;
<<%= url %>/aip/v1/items/2107bfb6-2670-4ffc-94a1-aeb4f8c1fd81> a pcdm: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.

url is no longer http://localhost, so need to override this url in for all these files

@murny murny changed the title WIP: Subdomains Subdomains Aug 5, 2020
Copy link
Contributor

@lagoan lagoan left a comment

Choose a reason for hiding this comment

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

Nice clean changes. Just a question on documentation.

README.md Outdated
@@ -159,7 +170,7 @@ Now everything should be up and running!
## Step 3: Open and view Jupiter!
Now everything is ready, you can go and view Jupiter! Just open your favorite browser and go to the following url:

[localhost:3000](http://localhost:3000)
[era.ualberta.localhost:3000](http://era.ualberta.localhost:3000)

(Note: ip address may be different if you are using `docker-machine`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment regarding different ip address when using docker-machine still valid now that we are using subdomains?

Copy link
Contributor Author

@murny murny Aug 5, 2020

Choose a reason for hiding this comment

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

That's a really good point. If someone's using docker-machine they would probably have to add/edit their own /etc/hosts to map to their ip address that docker-machine is providing.

But this is probably old instructions and I doubt anyone is using docker-machine? Since docker has come along way since v1.12 and Docker Desktop is the best way to run docker on Mac/Windows now.

We probably should just delete this note 🤔

Copy link
Member

@pgwillia pgwillia left a comment

Choose a reason for hiding this comment

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

Works great! Just a few questions.
image

@@ -211,7 +222,7 @@ modifying the config files, set the environment variable `RUN_FITS_CHARACTERIZAT

* Update `secrets.yml` (and maybe `omniauth.rb`) for the SAML implementation (you may need to generate a certificate/key for certain environments)
* Give IST's Identity Provider (uat-login or login) the metadata for our service provider
* Quick way to view this metadata is to the start the Rails server and navigate to `http://localhost:3000/auth/saml/metadata` (feel free to edit this metadata accordingly for example adding Organization and ContactPerson metadata)
* Quick way to view this metadata is to the start the Rails server and navigate to `http://era.ualberta.localhost:3000/auth/saml/metadata` (feel free to edit this metadata accordingly for example adding Organization and ContactPerson metadata)
Copy link
Member

Choose a reason for hiding this comment

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

Will subdomains impact the metadata that we've already sent to IST for authentication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't. URL for production/staging is unchanged, so should be no impact.

This is just instructions on retrieving the metadata on your local development environment which we need to update as everything in jupiter now is nested under "era" subdomain

@@ -67,4 +67,6 @@

# Action on unpermitted parameters
config.action_controller.action_on_unpermitted_parameters = :raise

config.hosts << 'era.lvh.me'
Copy link
Member

Choose a reason for hiding this comment

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

Is this related to

Rails.application.routes.default_url_options = { host: 'localhost' }

Copy link
Contributor Author

@murny murny Aug 6, 2020

Choose a reason for hiding this comment

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

This line is for whitelisting this host. As documented in the spike:

#1707 (comment) under the "Whitelisting hosts"

Without this, era.lvh.me:3000 will end up with a 500 error exception.

But you raise a very interesting question about our default_url_options in environments and might answer some of my troubles I was having in our test suite 🤔. Will look into maybe a better way of doing things now that I've seen this, so thank you for raising that point 👍


setup do
host = URI(Jupiter::TEST_URL).host
host! host
Copy link
Member

Choose a reason for hiding this comment

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

What does this line do?

Copy link
Contributor Author

@murny murny Aug 6, 2020

Choose a reason for hiding this comment

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

This sets the host that our tests run on to be era.ualberta.localhost. So when we use get '/' the @request.host is being set as era.ualberta.localhost. This allows our code to work as the constraints(subdomain: 'era') do returns true, allowing traffic to flow into our routes.

The next line, configures our url_helpers to set our host properly (so root_url returns era.ualberta.localhost). But as you highlighted in your review, we are setting this in environment/test.rb, so may not need this anymore if I just set it properly in test.rb 🎉 . Will play around with this

mount Sidekiq::Web => '/sidekiq', constraints: AdminConstraint.new
end
post '/logout_as_user', to: 'sessions#logout_as_user'
match '/auth/:provider/callback', to: 'sessions#create', via: [:get, :post], as: :login
Copy link
Member

Choose a reason for hiding this comment

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

We could use the login_url helper elsewhere now too! Clever 👍

<% else %>
<li role="presentation" class="nav-item">
<%= link_to t('.links.login'), '/auth/saml', class: 'nav-item nav-link text-nowrap', method: :post %>
</li>
<% if Rails.env.development? || Rails.env.uat? %>
<%# TODO: Temporary login form for local development or UAT %>
<li role="presentation" class="nav-item">
<%= link_to t('.links.login_as_dev'), '/auth/developer', class: 'nav-item nav-link text-nowrap', method: :post %>
</li>
<% end %>
<% end %>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah absolutely. Not sure why we never named it before 😆. But should allow us to reuse this elsewhere instead of hardcoding the path

@@ -32,6 +32,7 @@ shared:
fits_path: <%= ENV['FITS_PATH'] || 'fits.sh' %>
rack_attack_safelisted_ips: <%= ENV['RACK_ATTACK_SAFELISTED_IPS'] || '""' %>
system_user_api_key: <%= ENV['SYSTEM_USER_API_KEY'] %>
tld_length: <%= ENV['TLD_LENGTH'] || 1 %>
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will only need to be overridden when we have host/domains that have multiple subdomains.

So UAT may need it? I assume UAT might be era.uat.library.ualberta.ca in which case this value needs to be set for 3 as we have 3 subdomains.

We will need this for production especially since our url is era.library.ualberta.ca and we will need to set this value to be 2

@@ -1,3 +1,4 @@
module Jupiter
PRODUCTION_URL = 'https://era.library.ualberta.ca'.freeze
TEST_URL = 'http://era.ualberta.localhost'.freeze
Copy link
Member

Choose a reason for hiding this comment

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

Is this module just for tests? Is it related to Rails.application.routes.default_url_options?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This module is a generic place to store global configuration.

Examples of other apps in the wild with similar modules:
https://github.com/gitlabhq/gitlabhq/blob/master/lib/gitlab.rb
https://github.com/discourse/discourse/blob/master/lib/discourse.rb

I just need a place to stick this TEST_URL constant without having to copy and paste it all around the codebase. This TEST_URL is used in various places in our test suite to configure the tests to run on this url (so code works as code is now under an "era" subdomain)

Is there a better place for this? Maybe 🤔

pgwillia
pgwillia previously approved these changes Aug 10, 2020
Copy link
Member

@pgwillia pgwillia left a comment

Choose a reason for hiding this comment

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

mbarnett
mbarnett previously approved these changes Aug 10, 2020
Copy link
Contributor

@mbarnett mbarnett left a comment

Choose a reason for hiding this comment

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

@murny murny dismissed stale reviews from mbarnett and pgwillia via 68c7b77 September 3, 2020 17:51
@mbarnett mbarnett closed this Oct 7, 2020
@mbarnett mbarnett mentioned this pull request Oct 7, 2020
@murny murny mentioned this pull request Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants