Skip to content

Commit

Permalink
refactor url concern
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Jul 31, 2024
1 parent d909970 commit 2a208bf
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
2 changes: 0 additions & 2 deletions app/controllers/auth/sso_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

module Auth
KEYGEN_PORTAL_HOST = ENV.fetch('KEYGEN_PORTAL_HOST') { 'portal.keygen.sh' }

class SsoController < Api::V1::BaseController
include ActionController::Cookies

Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Application < Rails::Application

# Use cookies for sessions
config.session_store :cookie_store, key: '_keygen_session',
domain: ENV.fetch('KEYGEN_PORTAL_HOST') { 'portal.keygen.sh' },
domain: Keygen::PORTAL_HOST,
expire_after: 1.day,
httponly: true,
secure: true
Expand Down
12 changes: 3 additions & 9 deletions config/initializers/zietwork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
# FIXME(ezekg) Should we rename these to follow conventions?
autoloader.inflector.inflect(
'digest_io' => 'DigestIO',
'jsonapi' => 'JSONAPI',
'ee' => 'EE',
'ldap' => 'LDAP',
'saml' => 'SAML',
'sso' => 'SSO',
'idp' => 'IdP',
'sp' => 'SP',
'uri' => 'URI',
'url' => 'URL',
'jsonapi' => 'JSONAPI',
'ee' => 'EE',
'sso' => 'SSO',
)
end
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,12 @@

# Route helper for redirecting to Portal
direct :portal do |segment, options|
Keygen::URL.portal_url(segment, **options)
Keygen.portal_url(segment, **options)
end

# Route helpers for redirecting to docs
direct :docs do |segment, options|
Keygen::URL.docs_url(segment, **options)
Keygen.docs_url(segment, **options)
end

%w[500 503].each do |code|
Expand Down
4 changes: 3 additions & 1 deletion lib/keygen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
require_relative 'keygen/exporter'
require_relative 'keygen/importer'
require_relative 'keygen/sso'
require_relative 'keygen/url'
require_relative 'keygen/url_for'

module Keygen
include UrlFor

PUBLIC_KEY = %(\xB8\xF3\xEBL\xD2`\x13_g\xA5\tn\x8D\xC1\xC9\xB9\xDC\xB8\x1E\xE9\xFEP\xD1,\xDC\xD9A\xF6`z\x901).freeze

class << self
Expand Down
9 changes: 6 additions & 3 deletions lib/keygen/url.rb → lib/keygen/url_for.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# frozen_string_literal: true

module Keygen
module URL
PORTAL_BASE_URL = 'https://portal.keygen.sh'.freeze
module UrlFor
extend ActiveSupport::Concern

PORTAL_HOST = ENV.fetch('KEYGEN_PORTAL_HOST') { 'portal.keygen.sh' }.freeze
PORTAL_BASE_URL = "https://#{PORTAL_HOST}".freeze
DOCS_BASE_URL = 'https://keygen.sh/docs/api'.freeze

class << self
class_methods do
def portal_url(record_or_path = nil, **) = case record_or_path
in Account => account
url_for(PORTAL_BASE_URL, path: account.slug, **)
Expand Down

0 comments on commit 2a208bf

Please sign in to comment.