publishing_platform_location 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cea489133b10f18be67c20af744c161aa686bf4c73e204b3098ea64a2420179e
4
- data.tar.gz: d5c354319edcb0c9bbd6ef5a21097f3fc62218cbe7086e10c0445d2042a262ac
3
+ metadata.gz: 77c35943b03cb4e040b83b274fd950ac14eda328a0931a72dc442897009bf38c
4
+ data.tar.gz: 77a17a9950dc7ccef0db815343b06cc88ad45f7484c63e2344d6987de9c75847
5
5
  SHA512:
6
- metadata.gz: 4bc9629278aadbfc40ac6528ce68be1b8a01ab93bfa124a93a37764b04c26d23e345e795e562d3364319dca22a669887469cf50cb287ab91f94990c9ec2ca9ad
7
- data.tar.gz: cb498ea0b259573b7e359b697de94a5bd5fc7a92ddef343828b88ca68cb98e4b56baa68275c77ad8696499c72a7bf9b490303b90b9d983199f60415cd6c76bbc
6
+ metadata.gz: 17182fe6879038f28913b772f58700c20de117f891d0aeefd64b7b5d7e6bcb7d2d216b584b42f4740a5c348120c0276726ebb4e3f75451cea46632aba4ac5e43
7
+ data.tar.gz: 605844317f619c688c4d2b7deb83501e88cb13b4cc5e6685a561d250a3c4a718adeaa2eeb3b8d0db4ca585f13fdf28e5e6b5b6ba721978445801ac4170ba550e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PublishingPlatformLocation
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -10,18 +10,25 @@ class PublishingPlatformLocation
10
10
  # The fallback parent domain to use in development mode.
11
11
  DEV_DOMAIN = "dev.publishing-platform.co.uk"
12
12
 
13
- attr_reader :parent_domain, :external_domain
13
+ attr_reader :parent_domain, :external_domain, :host_prefix
14
14
 
15
15
  # Construct a new PublishingPlatformLocation instance.
16
16
  def initialize(domain_to_use = nil, external_domain = nil)
17
17
  @parent_domain = domain_to_use || env_var_or_fallback("PUBLISHING_PLATFORM_APP_DOMAIN", DEV_DOMAIN) # empty string for internal services
18
18
  @external_domain = external_domain || ENV.fetch("PUBLISHING_PLATFORM_APP_DOMAIN_EXTERNAL", @parent_domain)
19
+ @host_prefix = ENV.fetch("PUBLISHING_PLATFORM_LOCATION_HOSTNAME_PREFIX", "")
19
20
  end
20
21
 
21
22
  # Find the base URL for a service/application.
22
23
  def find(service, options = {})
23
24
  name = valid_service_name(service)
24
25
 
26
+ name = "#{host_prefix}#{name}"
27
+
28
+ if (service_uri = defined_service_uri_for(name))
29
+ return service_uri
30
+ end
31
+
25
32
  domain = options[:external] ? external_domain : parent_domain
26
33
  domain_suffix = domain.empty? ? "" : ".#{domain}" # empty string for internal services
27
34
 
@@ -74,4 +81,16 @@ private
74
81
  fallback_str
75
82
  end
76
83
  end
84
+
85
+ # Overrides the URL for a given service via a corresponding
86
+ # environment variable.
87
+ #
88
+ # e.g. if PUBLISHING_PLATFORM_LOCATION_SERVICE_CHEESE_THING_URI
89
+ # was set, +PublishingPlatformLocation.new.find('cheese-thing')+
90
+ # would return the value of that variable.
91
+ def defined_service_uri_for(service)
92
+ service_name = service.upcase.tr("-", "_")
93
+ uri = ENV.fetch("PUBLISHING_PLATFORM_LOCATION_SERVICE_#{service_name}_URI", "")
94
+ uri.empty? ? nil : uri
95
+ end
77
96
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publishing_platform_location
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Publishing Platform
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-03 00:00:00.000000000 Z
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: climate_control