-
Notifications
You must be signed in to change notification settings - Fork 25
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
[#171703313] SAML certs and Startup IDP metadata from ENV #595
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9bf8978
[#171703313] SAML certs and Startup IDP metadata from ENV
BurnedMarshal 1da4e94
[#171703313] Shutdown the program if no one idp is configured
BurnedMarshal b8e835b
Fix comment text
BurnedMarshal d875c26
Fix error log text
BurnedMarshal 53626f2
[#171703313] Add README info for new ENV
BurnedMarshal d8af1a4
[#171703313] Fix conflict
BurnedMarshal ee660bf
[#171703313] More readable condition for empty object check
BurnedMarshal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,16 @@ | |
* Defines services and register them to the Service Container. | ||
*/ | ||
import * as dotenv from "dotenv"; | ||
import { isLeft } from "fp-ts/lib/Either"; | ||
import { isLeft, parseJSON, toError } from "fp-ts/lib/Either"; | ||
import { fromNullable, isSome } from "fp-ts/lib/Option"; | ||
import { | ||
getNodeEnvironmentFromProcessEnv, | ||
NodeEnvironmentEnum | ||
} from "italia-ts-commons/lib/environment"; | ||
import { ReadableReporter } from "italia-ts-commons/lib/reporters"; | ||
import { | ||
errorsToReadableMessages, | ||
ReadableReporter | ||
} from "italia-ts-commons/lib/reporters"; | ||
import { CIDR } from "italia-ts-commons/lib/strings"; | ||
import { UrlFromString } from "italia-ts-commons/lib/url"; | ||
|
||
|
@@ -28,6 +31,7 @@ import { | |
} from "@pagopa/io-spid-commons"; | ||
|
||
import RedisSessionStorage from "./services/redisSessionStorage"; | ||
import { STRINGS_RECORD } from "./types/commons"; | ||
import { | ||
createClusterRedisClient, | ||
createSimpleRedisClient | ||
|
@@ -57,18 +61,19 @@ export const CACHE_MAX_AGE_SECONDS: number = parseInt( | |
|
||
// Private key used in SAML authentication to a SPID IDP. | ||
const samlKey = () => { | ||
return readFile( | ||
process.env.SAML_KEY_PATH || "./certs/key.pem", | ||
"SAML private key" | ||
return fromNullable(process.env.SAML_KEY).getOrElse( | ||
readFile(process.env.SAML_KEY_PATH || "./certs/key.pem", "SAML private key") | ||
); | ||
}; | ||
export const SAML_KEY = samlKey(); | ||
|
||
// Public certificate used in SAML authentication to a SPID IDP. | ||
const samlCert = () => { | ||
return readFile( | ||
process.env.SAML_CERT_PATH || "./certs/cert.pem", | ||
"SAML certificate" | ||
return fromNullable(process.env.SAML_CERT).getOrElse( | ||
readFile( | ||
process.env.SAML_CERT_PATH || "./certs/cert.pem", | ||
"SAML certificate" | ||
) | ||
); | ||
}; | ||
|
||
|
@@ -104,6 +109,20 @@ const SPID_TESTENV_URL = | |
export const IDP_METADATA_URL = getRequiredENVVar("IDP_METADATA_URL"); | ||
const CIE_METADATA_URL = getRequiredENVVar("CIE_METADATA_URL"); | ||
|
||
export const STARTUP_IDPS_METADATA: | ||
| Record<string, string> | ||
| undefined = fromNullable(process.env.STARTUP_IDPS_METADATA) | ||
.map(_ => | ||
parseJSON(_, toError) | ||
.chain<Record<string, string> | undefined>(_1 => | ||
STRINGS_RECORD.decode(_1).mapLeft( | ||
err => new Error(errorsToReadableMessages(err).join(" / ")) | ||
) | ||
) | ||
.getOrElse(undefined) | ||
) | ||
.getOrElse(undefined); | ||
|
||
export const CLIENT_ERROR_REDIRECTION_URL = | ||
process.env.CLIENT_ERROR_REDIRECTION_URL || "/error.html"; | ||
|
||
|
@@ -116,7 +135,8 @@ export const appConfig: IApplicationConfig = { | |
clientLoginRedirectionUrl: CLIENT_REDIRECTION_URL, | ||
loginPath: "/login", | ||
metadataPath: "/metadata", | ||
sloPath: "/slo" | ||
sloPath: "/slo", | ||
startupIdpsMetadata: STARTUP_IDPS_METADATA | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please document this var into th readme ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 53626f2 |
||
}; | ||
|
||
const maybeSpidValidatorUrlOption = fromNullable( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we must ensure that this code never throws
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all static methods inside the Task that should never throw. I think that
tryCatch
before andnew Task
now, are only for chaining purposes withwithSpid
.