Skip to content

Commit

Permalink
fix(env): provide boolean env vars as boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
oyo committed Oct 11, 2024
1 parent 7d96cef commit 65cc352
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import {
PAGE_SIZE,
} from 'features/adminClearingHouseSD/adminClearingHouseSDApiSlice'
import { error } from 'services/NotifyService'
import { getClearinghouseConnectDisabled } from 'services/EnvironmentService'
import { isClearinghouseConnectDisabled } from 'services/EnvironmentService'

const AdminclearinghouseSDElements = () => {
const [checked, setChecked] = useState(getClearinghouseConnectDisabled())
const [checked, setChecked] = useState(isClearinghouseConnectDisabled())
const [triggerCompanyData] = useTriggerCompanyDataMutation()
const [triggerConnectors] = useTriggerConnectorsMutation()
const [triggerCDLoading, setTriggerCDLoading] = useState<boolean>(false)
Expand Down
12 changes: 6 additions & 6 deletions src/services/EnvironmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

declare const ENV: Record<string, string>

export const getRequireHttpsUrlPattern = () =>
ENV.REQUIRE_HTTPS_URL_PATTERN ?? 'true'
export const isRequireHttpsUrlPattern = () =>
ENV.REQUIRE_HTTPS_URL_PATTERN !== 'false'

export const getClearinghouseConnectDisabled = () =>
ENV.CLEARINGHOUSE_CONNECT_DISABLED ?? 'false'
export const isClearinghouseConnectDisabled = () =>
ENV.CLEARINGHOUSE_CONNECT_DISABLED === 'true'

export const getRealm = () => ENV.REALM ?? ''

Expand Down Expand Up @@ -58,8 +58,8 @@ export const getMiwBase = () => ENV.MANAGED_IDENTITY_WALLETS_NEW_URL ?? ''
export const getSSICredentialBase = () => ENV.SSI_CREDENTIAL_URL ?? ''

const EnvironmentService = {
getRequireHttpsUrlPattern,
getClearinghouseConnectDisabled,
isRequireHttpsUrlPattern,
isClearinghouseConnectDisabled,
getRealm,
getClientId,
getClientIdRegistration,
Expand Down
7 changes: 2 additions & 5 deletions src/types/Patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { getRequireHttpsUrlPattern } from '../services/EnvironmentService'

// check the REQUIRE_HTTPS_URL_PATTERN environment variable, defaulting to !== 'false' if not set
const requireHttpsUrlPattern = getRequireHttpsUrlPattern() !== 'false'
import { isRequireHttpsUrlPattern } from '../services/EnvironmentService'

const DOMAIN =
/([a-z0-9]|[a-z0-9][a-z0-9-]{0,61}[a-z0-9])(\.([a-z0-9]|[a-z0-9][a-z0-9-]{0,61}[a-z0-9])){1,10}/i
const URLPATH = /(\/[a-z0-9-._~:/?#[\]@!$&'()*+,;=%]{0,500}){0,20}/
// construct regex patterns for URL based on the REQUIRE_HTTPS_URL_PATTERN environment variable
const urlProtocol = requireHttpsUrlPattern ? 'https' : 'https?'
const urlProtocol = isRequireHttpsUrlPattern() ? 'https' : 'https?'
const urlPattern = new RegExp(
`^(${urlProtocol})://(${DOMAIN.source})(:\\d{1,5})?(${URLPATH.source})?$`,
'i'
Expand Down

0 comments on commit 65cc352

Please sign in to comment.