publishing_platform_location 0.1.0 → 0.3.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 +4 -4
- data/README.md +1 -1
- data/lib/publishing_platform_location/version.rb +1 -1
- data/lib/publishing_platform_location.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8da954c6a842996e1f2370c2ed643ec42b622ec35310da7072a49543516d5d80
|
4
|
+
data.tar.gz: 4cb904a614d96f2618acd421796d14378f8160f429422d6abd967cca7cba6a62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aca0dfc3d388204cc20068b53f52f9af149ebbaa6f246f96b9b3ce4dc239dd91ffc032d8375020c81c886621be9008f4998b7e04f0a33c98650aedaec16e3c86
|
7
|
+
data.tar.gz: 3271cc714158443ec3bbc810c3d5bc6dcd3448811b5983ed271cd2183948722654a7f86edc631fcf6bc5f52ea9bfd50db285f83b062f8da337e675a3d2b67c2c
|
data/README.md
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
#
|
1
|
+
# Publishing Platform Location
|
2
2
|
Generates URLs for publishing platform services based on environment.
|
@@ -16,12 +16,20 @@ class PublishingPlatformLocation
|
|
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", "")
|
20
|
+
@unprefixable_hosts = ENV.fetch("PUBLISHING_PLATFORM_LOCATION_UNPREFIXABLE_HOSTS", "").split(",").map(&:strip)
|
19
21
|
end
|
20
22
|
|
21
23
|
# Find the base URL for a service/application.
|
22
24
|
def find(service, options = {})
|
23
25
|
name = valid_service_name(service)
|
24
26
|
|
27
|
+
if (service_uri = defined_service_uri_for(name))
|
28
|
+
return service_uri
|
29
|
+
end
|
30
|
+
|
31
|
+
name = "#{host_prefix}#{name}" unless unprefixable_hosts.include?(name)
|
32
|
+
|
25
33
|
domain = options[:external] ? external_domain : parent_domain
|
26
34
|
domain_suffix = domain.empty? ? "" : ".#{domain}" # empty string for internal services
|
27
35
|
|
@@ -52,6 +60,8 @@ class PublishingPlatformLocation
|
|
52
60
|
|
53
61
|
private
|
54
62
|
|
63
|
+
attr_reader :host_prefix, :unprefixable_hosts
|
64
|
+
|
55
65
|
def valid_service_name(name)
|
56
66
|
service_name = name.to_s
|
57
67
|
return service_name if service_name.match?(/\A[a-z1-9.-]+\z/)
|
@@ -74,4 +84,16 @@ private
|
|
74
84
|
fallback_str
|
75
85
|
end
|
76
86
|
end
|
87
|
+
|
88
|
+
# Overrides the URL for a given service via a corresponding
|
89
|
+
# environment variable.
|
90
|
+
#
|
91
|
+
# e.g. if PUBLISHING_PLATFORM_LOCATION_SERVICE_CHEESE_THING_URI
|
92
|
+
# was set, +PublishingPlatformLocation.new.find('cheese-thing')+
|
93
|
+
# would return the value of that variable.
|
94
|
+
def defined_service_uri_for(service)
|
95
|
+
service_name = service.upcase.tr("-", "_")
|
96
|
+
uri = ENV.fetch("PUBLISHING_PLATFORM_LOCATION_SERVICE_#{service_name}_URI", "")
|
97
|
+
uri.empty? ? nil : uri
|
98
|
+
end
|
77
99
|
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.
|
4
|
+
version: 0.3.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-
|
11
|
+
date: 2024-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: climate_control
|