@rockcarver/frodo-lib 0.16.1 → 0.16.2-1
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.
- package/CHANGELOG.md +16 -1
- package/cjs/ops/AuthenticateOps.js +5 -2
- package/cjs/ops/AuthenticateOps.js.map +1 -1
- package/cjs/ops/ConnectionProfileOps.js +38 -18
- package/cjs/ops/ConnectionProfileOps.js.map +1 -1
- package/cjs/ops/JourneyOps.js +43 -436
- package/cjs/ops/JourneyOps.js.map +1 -1
- package/cjs/ops/LogOps.js +5 -1
- package/cjs/ops/LogOps.js.map +1 -1
- package/cjs/ops/OpsTypes.js.map +1 -1
- package/cjs/storage/SessionStorage.js +2 -0
- package/cjs/storage/SessionStorage.js.map +1 -1
- package/esm/ops/AuthenticateOps.mjs +5 -2
- package/esm/ops/ConnectionProfileOps.mjs +38 -18
- package/esm/ops/JourneyOps.mjs +12 -321
- package/esm/ops/LogOps.mjs +5 -1
- package/esm/storage/SessionStorage.mjs +2 -0
- package/package.json +1 -1
- package/types/ops/AuthenticateOps.d.ts.map +1 -1
- package/types/ops/ConnectionProfileOps.d.ts.map +1 -1
- package/types/ops/JourneyOps.d.ts +14 -47
- package/types/ops/JourneyOps.d.ts.map +1 -1
- package/types/ops/LogOps.d.ts.map +1 -1
- package/types/ops/OpsTypes.d.ts +0 -8
- package/types/ops/OpsTypes.d.ts.map +1 -1
- package/types/storage/SessionStorage.d.ts +2 -0
- package/types/storage/SessionStorage.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.16.2-1] - 2022-10-24
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- \#137: Error fetching logs with txId
|
|
15
|
+
- rockcarver/frodo-cli#109: Suppress am version output
|
|
16
|
+
- rockcarver/frodo-cli#102: Verbosity of connection string used
|
|
17
|
+
- rockcarver/frodo-cli#106: Handle non-unique connection name used in cli
|
|
18
|
+
|
|
19
|
+
## [0.16.2-0] - 2022-10-22
|
|
20
|
+
|
|
10
21
|
## [0.16.1] - 2022-10-19
|
|
11
22
|
|
|
12
23
|
### Fixed
|
|
@@ -671,7 +682,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
671
682
|
- Fixed problem with adding connection profiles
|
|
672
683
|
- Miscellaneous bug fixes
|
|
673
684
|
|
|
674
|
-
[Unreleased]: https://github.com/rockcarver/frodo-lib/compare/v0.16.1...HEAD
|
|
685
|
+
[Unreleased]: https://github.com/rockcarver/frodo-lib/compare/v0.16.2-1...HEAD
|
|
686
|
+
|
|
687
|
+
[0.16.2-1]: https://github.com/rockcarver/frodo-lib/compare/v0.16.2-0...v0.16.2-1
|
|
688
|
+
|
|
689
|
+
[0.16.2-0]: https://github.com/rockcarver/frodo-lib/compare/v0.16.1...v0.16.2-0
|
|
675
690
|
|
|
676
691
|
[0.16.1]: https://github.com/rockcarver/frodo-lib/compare/v0.16.0...v0.16.1
|
|
677
692
|
|
|
@@ -254,8 +254,11 @@ function _authenticate() {
|
|
|
254
254
|
determineDefaultRealm(_SessionStorage.default.session.getDeploymentType());
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
var versionInfo = (yield (0, _ServerInfoApi.getServerVersionInfo)()).data;
|
|
258
|
-
|
|
257
|
+
var versionInfo = (yield (0, _ServerInfoApi.getServerVersionInfo)()).data; // https://github.com/rockcarver/frodo-cli/issues/109
|
|
258
|
+
// printMessage(`Connected to ${versionInfo.fullVersion}`);
|
|
259
|
+
// https://github.com/rockcarver/frodo-cli/issues/102
|
|
260
|
+
|
|
261
|
+
(0, _Console.printMessage)("Connected to [".concat(_SessionStorage.default.session.getTenant(), "], [").concat(!_SessionStorage.default.session.getRealm() ? 'alpha' : _SessionStorage.default.session.getRealm(), "] realm, as [").concat(_SessionStorage.default.session.getUsername(), "]"));
|
|
259
262
|
var version = yield getSemanticVersion(versionInfo);
|
|
260
263
|
|
|
261
264
|
_SessionStorage.default.session.setAmVersion(version);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticateOps.js","names":["adminClientPassword","redirectUrlTemplate","idmAdminScope","adminClientId","getCookieName","getServerInfo","data","cookieName","error","printMessage","checkAndHandle2FA","payload","element","callbacks","type","input","value","includes","need2fa","output","code","readlineSync","question","determineDefaultRealm","deploymentType","storage","session","getRealm","global","DEFAULT_REALM_KEY","setRealm","DEPLOYMENT_TYPE_REALM_MAP","determineDeploymentType","fidcClientId","forgeopsClientId","verifier","encodeBase64Url","randomBytes","challenge","createHash","update","digest","challengeMethod","redirectURL","url","resolve","getTenant","config","maxRedirects","bodyFormData","getCookieValue","CLASSIC_DEPLOYMENT_TYPE_KEY","authorize","e","response","status","headers","location","indexOf","CLOUD_DEPLOYMENT_TYPE_KEY","ex","FORGEOPS_DEPLOYMENT_TYPE_KEY","getSemanticVersion","versionInfo","versionString","version","rx","match","Error","authenticate","setCookieName","getUsername","getPassword","response1","step","skip2FA","response2","setCookieValue","getDeploymentType","setDeploymentType","getServerVersionInfo","fullVersion","setAmVersion","message","getAuthCode","codeChallenge","codeChallengeMethod","redirectLocationURL","request","res","responseUrl","queryObject","parse","query","getAccessToken","authCode","auth","username","password","accessToken","setBearerToken","access_token","getTokens","save","credsFromParameters","conn","getConnectionProfile","setTenant","tenant","setUsername","setPassword","setAuthenticationService","authenticationService","setAuthenticationHeaderOverrides","authenticationHeaderOverrides","getBearerToken","saveConnectionProfile"],"sources":["ops/AuthenticateOps.ts"],"sourcesContent":["import url from 'url';\nimport { createHash, randomBytes } from 'crypto';\nimport readlineSync from 'readline-sync';\nimport { encodeBase64Url } from '../api/utils/Base64';\nimport storage from '../storage/SessionStorage';\nimport * as global from '../storage/StaticStorage';\nimport { printMessage } from './utils/Console';\nimport { getServerInfo, getServerVersionInfo } from '../api/ServerInfoApi';\nimport { step } from '../api/AuthenticateApi';\nimport { accessToken, authorize } from '../api/OAuth2OIDCApi';\nimport {\n getConnectionProfile,\n saveConnectionProfile,\n} from './ConnectionProfileOps';\n\nconst adminClientPassword = 'doesnotmatter';\nconst redirectUrlTemplate = '/platform/appAuthHelperRedirect.html';\n\nconst idmAdminScope = 'fr:idm:* openid';\n\nlet adminClientId = 'idmAdminClient';\n\n/**\n * Helper function to get cookie name\n * @returns {String} cookie name\n */\nasync function getCookieName() {\n try {\n return (await getServerInfo()).data.cookieName;\n } catch (error) {\n printMessage(`Error getting cookie name: ${error}`, 'error');\n return null;\n }\n}\n\n/**\n * Helper function to determine if this is a setup mfa prompt in the ID Cloud tenant admin login journey\n * @param {Object} payload response from the previous authentication journey step\n * @returns {Object} an object indicating if 2fa is required and the original payload\n */\nfunction checkAndHandle2FA(payload) {\n // let skippable = false;\n if ('callbacks' in payload) {\n for (const element of payload.callbacks) {\n if (element.type === 'HiddenValueCallback') {\n if (element.input[0].value.includes('skip')) {\n // skippable = true;\n element.input[0].value = 'Skip';\n return {\n need2fa: true,\n payload,\n };\n }\n }\n if (element.type === 'NameCallback') {\n if (element.output[0].value.includes('code')) {\n // skippable = false;\n printMessage('2FA is enabled and required for this user...');\n const code = readlineSync.question(`${element.output[0].value}: `);\n element.input[0].value = code;\n return {\n need2fa: true,\n payload,\n };\n }\n }\n }\n // console.info(\"NO2FA\");\n return {\n need2fa: false,\n payload,\n };\n }\n // console.info(\"NO2FA\");\n return {\n need2fa: false,\n payload,\n };\n}\n\n/**\n * Helper function to set the default realm by deployment type\n * @param {String} deploymentType deployment type\n */\nfunction determineDefaultRealm(deploymentType) {\n if (storage.session.getRealm() === global.DEFAULT_REALM_KEY) {\n storage.session.setRealm(global.DEPLOYMENT_TYPE_REALM_MAP[deploymentType]);\n }\n}\n\n/**\n * Helper function to determine the deployment type\n * @returns {String} deployment type\n */\nasync function determineDeploymentType() {\n const fidcClientId = 'idmAdminClient';\n const forgeopsClientId = 'idm-admin-ui';\n\n const verifier = encodeBase64Url(randomBytes(32));\n const challenge = encodeBase64Url(\n createHash('sha256').update(verifier).digest()\n );\n const challengeMethod = 'S256';\n const redirectURL = url.resolve(\n storage.session.getTenant(),\n redirectUrlTemplate\n );\n\n const config = {\n maxRedirects: 0,\n };\n let bodyFormData = `redirect_uri=${redirectURL}&scope=${idmAdminScope}&response_type=code&client_id=${fidcClientId}&csrf=${storage.session.getCookieValue()}&decision=allow&code_challenge=${challenge}&code_challenge_method=${challengeMethod}`;\n\n let deploymentType = global.CLASSIC_DEPLOYMENT_TYPE_KEY;\n try {\n await authorize(bodyFormData, config);\n } catch (e) {\n if (\n e.response?.status === 302 &&\n e.response.headers?.location?.indexOf('code=') > -1\n ) {\n printMessage('ForgeRock Identity Cloud ', 'info', false);\n deploymentType = global.CLOUD_DEPLOYMENT_TYPE_KEY;\n } else {\n try {\n bodyFormData = `redirect_uri=${redirectURL}&scope=${idmAdminScope}&response_type=code&client_id=${forgeopsClientId}&csrf=${storage.session.getCookieValue()}&decision=allow&code_challenge=${challenge}&code_challenge_method=${challengeMethod}`;\n await authorize(bodyFormData, config);\n } catch (ex) {\n if (\n ex.response?.status === 302 &&\n ex.response.headers?.location?.indexOf('code=') > -1\n ) {\n adminClientId = forgeopsClientId;\n printMessage('ForgeOps deployment ', 'info', false);\n deploymentType = global.FORGEOPS_DEPLOYMENT_TYPE_KEY;\n } else {\n printMessage('Classic deployment ', 'info', false);\n }\n }\n }\n printMessage('detected.');\n }\n determineDefaultRealm(deploymentType);\n return deploymentType;\n}\n\n/**\n * Helper function to extract the semantic version string from a version info object\n * @param {Object} versionInfo version info object\n * @returns {String} semantic version\n */\nasync function getSemanticVersion(versionInfo) {\n if ('version' in versionInfo) {\n const versionString = versionInfo.version;\n const rx = /([\\d]\\.[\\d]\\.[\\d](\\.[\\d])*)/g;\n const version = versionString.match(rx);\n return version[0];\n }\n throw new Error('Cannot extract semantic version from version info object.');\n}\n\n/**\n * Helper function to authenticate and obtain and store session cookie\n * @returns {String} empty string or null\n */\nasync function authenticate() {\n storage.session.setCookieName(await getCookieName());\n try {\n const config = {\n headers: {\n 'X-OpenAM-Username': storage.session.getUsername(),\n 'X-OpenAM-Password': storage.session.getPassword(),\n },\n };\n const response1 = (await step({}, config)).data;\n const skip2FA = checkAndHandle2FA(response1);\n let response2 = {};\n if (skip2FA.need2fa) {\n response2 = (await step(skip2FA.payload)).data;\n } else {\n response2 = skip2FA.payload;\n }\n if ('tokenId' in response2) {\n storage.session.setCookieValue(response2['tokenId']);\n if (!storage.session.getDeploymentType()) {\n storage.session.setDeploymentType(await determineDeploymentType());\n } else {\n determineDefaultRealm(storage.session.getDeploymentType());\n }\n const versionInfo = (await getServerVersionInfo()).data;\n printMessage(`Connected to ${versionInfo.fullVersion}`);\n const version = await getSemanticVersion(versionInfo);\n storage.session.setAmVersion(version);\n return '';\n }\n printMessage(`error authenticating`, 'error');\n printMessage('+++ likely cause, bad credentials!!! +++', 'error');\n return null;\n } catch (e) {\n if (e.response?.status === 401) {\n printMessage(`error authenticating - ${e.message}`, 'error');\n printMessage('+++ likely cause, bad credentials +++', 'error');\n }\n if (e.message === 'self signed certificate') {\n printMessage(`error authenticating - ${e.message}`, 'error');\n printMessage('+++ use -k, --insecure option to allow +++', 'error');\n } else {\n printMessage(`error authenticating - ${e.message}`, 'error');\n printMessage(e.response?.data, 'error');\n }\n return null;\n }\n}\n\n/**\n * Helper function to obtain an oauth2 authorization code\n * @param {String} redirectURL oauth2 redirect uri\n * @param {String} codeChallenge PKCE code challenge\n * @param {String} codeChallengeMethod PKCE code challenge method\n * @returns {String} oauth2 authorization code or null\n */\nasync function getAuthCode(redirectURL, codeChallenge, codeChallengeMethod) {\n try {\n const bodyFormData = `redirect_uri=${redirectURL}&scope=${idmAdminScope}&response_type=code&client_id=${adminClientId}&csrf=${storage.session.getCookieValue()}&decision=allow&code_challenge=${codeChallenge}&code_challenge_method=${codeChallengeMethod}`;\n const config = {\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n };\n const response = await authorize(bodyFormData, config);\n if (response.status < 200 || response.status > 399) {\n printMessage('error getting auth code', 'error');\n printMessage(\n 'likely cause: mismatched parameters with OAuth client config',\n 'error'\n );\n return null;\n }\n const redirectLocationURL = response.request.res.responseUrl;\n const queryObject = url.parse(redirectLocationURL, true).query;\n if ('code' in queryObject) {\n return queryObject.code;\n }\n printMessage('auth code not found', 'error');\n return null;\n } catch (error) {\n printMessage(`error getting auth code - ${error.message}`, 'error');\n printMessage(error.response.data, 'error');\n return null;\n }\n}\n\n/**\n * Helper function to obtain oauth2 access token\n * @returns {String} empty string or null\n */\nasync function getAccessToken() {\n try {\n const verifier = encodeBase64Url(randomBytes(32));\n const challenge = encodeBase64Url(\n createHash('sha256').update(verifier).digest()\n );\n const challengeMethod = 'S256';\n const redirectURL = url.resolve(\n storage.session.getTenant(),\n redirectUrlTemplate\n );\n const authCode = await getAuthCode(redirectURL, challenge, challengeMethod);\n if (authCode == null) {\n printMessage('error getting auth code', 'error');\n return null;\n }\n let response = null;\n if (\n storage.session.getDeploymentType() === global.CLOUD_DEPLOYMENT_TYPE_KEY\n ) {\n const config = {\n auth: {\n username: adminClientId,\n password: adminClientPassword,\n },\n };\n const bodyFormData = `redirect_uri=${redirectURL}&grant_type=authorization_code&code=${authCode}&code_verifier=${verifier}`;\n response = await accessToken(bodyFormData, config);\n } else {\n const bodyFormData = `client_id=${adminClientId}&redirect_uri=${redirectURL}&grant_type=authorization_code&code=${authCode}&code_verifier=${verifier}`;\n response = await accessToken(bodyFormData);\n }\n if (response.status < 200 || response.status > 399) {\n printMessage(`access token call returned ${response.status}`, 'error');\n return null;\n }\n if ('access_token' in response.data) {\n storage.session.setBearerToken(response.data.access_token);\n return '';\n }\n printMessage(\"can't get access token\", 'error');\n return null;\n } catch (e) {\n printMessage('error getting access token - ', 'error');\n return null;\n }\n}\n\n/**\n * Get tokens\n * @param {boolean} save true to save a connection profile upon successful authentication, false otherwise\n * @returns {boolean} true if tokens were successfully obtained, false otherwise\n */\nexport async function getTokens(save = false) {\n let credsFromParameters = true;\n // if username/password on cli are empty, try to read from connections.json\n if (\n storage.session.getUsername() == null &&\n storage.session.getPassword() == null\n ) {\n credsFromParameters = false;\n const conn = await getConnectionProfile();\n if (conn) {\n storage.session.setTenant(conn.tenant);\n storage.session.setUsername(conn.username);\n storage.session.setPassword(conn.password);\n storage.session.setAuthenticationService(conn.authenticationService);\n storage.session.setAuthenticationHeaderOverrides(\n conn.authenticationHeaderOverrides\n );\n } else {\n return false;\n }\n }\n await authenticate();\n if (\n storage.session.getCookieValue() &&\n !storage.session.getBearerToken() &&\n (storage.session.getDeploymentType() === global.CLOUD_DEPLOYMENT_TYPE_KEY ||\n storage.session.getDeploymentType() ===\n global.FORGEOPS_DEPLOYMENT_TYPE_KEY)\n ) {\n await getAccessToken();\n }\n if (save && storage.session.getCookieValue() && credsFromParameters) {\n // valid cookie, which means valid username/password combo. Save it in connections.json\n saveConnectionProfile();\n return true;\n }\n if (!storage.session.getCookieValue()) {\n return false;\n }\n return true;\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAKA,IAAMA,mBAAmB,GAAG,eAA5B;AACA,IAAMC,mBAAmB,GAAG,sCAA5B;AAEA,IAAMC,aAAa,GAAG,iBAAtB;AAEA,IAAIC,aAAa,GAAG,gBAApB;AAEA;AACA;AACA;AACA;;SACeC,a;;;AASf;AACA;AACA;AACA;AACA;;;;qCAbA,aAA+B;IAC7B,IAAI;MACF,OAAO,OAAO,IAAAC,4BAAA,GAAP,EAAwBC,IAAxB,CAA6BC,UAApC;IACD,CAFD,CAEE,OAAOC,KAAP,EAAc;MACd,IAAAC,qBAAA,uCAA2CD,KAA3C,GAAoD,OAApD;MACA,OAAO,IAAP;IACD;EACF,C;;;;AAOD,SAASE,iBAAT,CAA2BC,OAA3B,EAAoC;EAClC;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C"}
|
|
1
|
+
{"version":3,"file":"AuthenticateOps.js","names":["adminClientPassword","redirectUrlTemplate","idmAdminScope","adminClientId","getCookieName","getServerInfo","data","cookieName","error","printMessage","checkAndHandle2FA","payload","element","callbacks","type","input","value","includes","need2fa","output","code","readlineSync","question","determineDefaultRealm","deploymentType","storage","session","getRealm","global","DEFAULT_REALM_KEY","setRealm","DEPLOYMENT_TYPE_REALM_MAP","determineDeploymentType","fidcClientId","forgeopsClientId","verifier","encodeBase64Url","randomBytes","challenge","createHash","update","digest","challengeMethod","redirectURL","url","resolve","getTenant","config","maxRedirects","bodyFormData","getCookieValue","CLASSIC_DEPLOYMENT_TYPE_KEY","authorize","e","response","status","headers","location","indexOf","CLOUD_DEPLOYMENT_TYPE_KEY","ex","FORGEOPS_DEPLOYMENT_TYPE_KEY","getSemanticVersion","versionInfo","versionString","version","rx","match","Error","authenticate","setCookieName","getUsername","getPassword","response1","step","skip2FA","response2","setCookieValue","getDeploymentType","setDeploymentType","getServerVersionInfo","setAmVersion","message","getAuthCode","codeChallenge","codeChallengeMethod","redirectLocationURL","request","res","responseUrl","queryObject","parse","query","getAccessToken","authCode","auth","username","password","accessToken","setBearerToken","access_token","getTokens","save","credsFromParameters","conn","getConnectionProfile","setTenant","tenant","setUsername","setPassword","setAuthenticationService","authenticationService","setAuthenticationHeaderOverrides","authenticationHeaderOverrides","getBearerToken","saveConnectionProfile"],"sources":["ops/AuthenticateOps.ts"],"sourcesContent":["import url from 'url';\nimport { createHash, randomBytes } from 'crypto';\nimport readlineSync from 'readline-sync';\nimport { encodeBase64Url } from '../api/utils/Base64';\nimport storage from '../storage/SessionStorage';\nimport * as global from '../storage/StaticStorage';\nimport { printMessage } from './utils/Console';\nimport { getServerInfo, getServerVersionInfo } from '../api/ServerInfoApi';\nimport { step } from '../api/AuthenticateApi';\nimport { accessToken, authorize } from '../api/OAuth2OIDCApi';\nimport {\n getConnectionProfile,\n saveConnectionProfile,\n} from './ConnectionProfileOps';\n\nconst adminClientPassword = 'doesnotmatter';\nconst redirectUrlTemplate = '/platform/appAuthHelperRedirect.html';\n\nconst idmAdminScope = 'fr:idm:* openid';\n\nlet adminClientId = 'idmAdminClient';\n\n/**\n * Helper function to get cookie name\n * @returns {String} cookie name\n */\nasync function getCookieName() {\n try {\n return (await getServerInfo()).data.cookieName;\n } catch (error) {\n printMessage(`Error getting cookie name: ${error}`, 'error');\n return null;\n }\n}\n\n/**\n * Helper function to determine if this is a setup mfa prompt in the ID Cloud tenant admin login journey\n * @param {Object} payload response from the previous authentication journey step\n * @returns {Object} an object indicating if 2fa is required and the original payload\n */\nfunction checkAndHandle2FA(payload) {\n // let skippable = false;\n if ('callbacks' in payload) {\n for (const element of payload.callbacks) {\n if (element.type === 'HiddenValueCallback') {\n if (element.input[0].value.includes('skip')) {\n // skippable = true;\n element.input[0].value = 'Skip';\n return {\n need2fa: true,\n payload,\n };\n }\n }\n if (element.type === 'NameCallback') {\n if (element.output[0].value.includes('code')) {\n // skippable = false;\n printMessage('2FA is enabled and required for this user...');\n const code = readlineSync.question(`${element.output[0].value}: `);\n element.input[0].value = code;\n return {\n need2fa: true,\n payload,\n };\n }\n }\n }\n // console.info(\"NO2FA\");\n return {\n need2fa: false,\n payload,\n };\n }\n // console.info(\"NO2FA\");\n return {\n need2fa: false,\n payload,\n };\n}\n\n/**\n * Helper function to set the default realm by deployment type\n * @param {String} deploymentType deployment type\n */\nfunction determineDefaultRealm(deploymentType) {\n if (storage.session.getRealm() === global.DEFAULT_REALM_KEY) {\n storage.session.setRealm(global.DEPLOYMENT_TYPE_REALM_MAP[deploymentType]);\n }\n}\n\n/**\n * Helper function to determine the deployment type\n * @returns {String} deployment type\n */\nasync function determineDeploymentType() {\n const fidcClientId = 'idmAdminClient';\n const forgeopsClientId = 'idm-admin-ui';\n\n const verifier = encodeBase64Url(randomBytes(32));\n const challenge = encodeBase64Url(\n createHash('sha256').update(verifier).digest()\n );\n const challengeMethod = 'S256';\n const redirectURL = url.resolve(\n storage.session.getTenant(),\n redirectUrlTemplate\n );\n\n const config = {\n maxRedirects: 0,\n };\n let bodyFormData = `redirect_uri=${redirectURL}&scope=${idmAdminScope}&response_type=code&client_id=${fidcClientId}&csrf=${storage.session.getCookieValue()}&decision=allow&code_challenge=${challenge}&code_challenge_method=${challengeMethod}`;\n\n let deploymentType = global.CLASSIC_DEPLOYMENT_TYPE_KEY;\n try {\n await authorize(bodyFormData, config);\n } catch (e) {\n if (\n e.response?.status === 302 &&\n e.response.headers?.location?.indexOf('code=') > -1\n ) {\n printMessage('ForgeRock Identity Cloud ', 'info', false);\n deploymentType = global.CLOUD_DEPLOYMENT_TYPE_KEY;\n } else {\n try {\n bodyFormData = `redirect_uri=${redirectURL}&scope=${idmAdminScope}&response_type=code&client_id=${forgeopsClientId}&csrf=${storage.session.getCookieValue()}&decision=allow&code_challenge=${challenge}&code_challenge_method=${challengeMethod}`;\n await authorize(bodyFormData, config);\n } catch (ex) {\n if (\n ex.response?.status === 302 &&\n ex.response.headers?.location?.indexOf('code=') > -1\n ) {\n adminClientId = forgeopsClientId;\n printMessage('ForgeOps deployment ', 'info', false);\n deploymentType = global.FORGEOPS_DEPLOYMENT_TYPE_KEY;\n } else {\n printMessage('Classic deployment ', 'info', false);\n }\n }\n }\n printMessage('detected.');\n }\n determineDefaultRealm(deploymentType);\n return deploymentType;\n}\n\n/**\n * Helper function to extract the semantic version string from a version info object\n * @param {Object} versionInfo version info object\n * @returns {String} semantic version\n */\nasync function getSemanticVersion(versionInfo) {\n if ('version' in versionInfo) {\n const versionString = versionInfo.version;\n const rx = /([\\d]\\.[\\d]\\.[\\d](\\.[\\d])*)/g;\n const version = versionString.match(rx);\n return version[0];\n }\n throw new Error('Cannot extract semantic version from version info object.');\n}\n\n/**\n * Helper function to authenticate and obtain and store session cookie\n * @returns {String} empty string or null\n */\nasync function authenticate() {\n storage.session.setCookieName(await getCookieName());\n try {\n const config = {\n headers: {\n 'X-OpenAM-Username': storage.session.getUsername(),\n 'X-OpenAM-Password': storage.session.getPassword(),\n },\n };\n const response1 = (await step({}, config)).data;\n const skip2FA = checkAndHandle2FA(response1);\n let response2 = {};\n if (skip2FA.need2fa) {\n response2 = (await step(skip2FA.payload)).data;\n } else {\n response2 = skip2FA.payload;\n }\n if ('tokenId' in response2) {\n storage.session.setCookieValue(response2['tokenId']);\n if (!storage.session.getDeploymentType()) {\n storage.session.setDeploymentType(await determineDeploymentType());\n } else {\n determineDefaultRealm(storage.session.getDeploymentType());\n }\n const versionInfo = (await getServerVersionInfo()).data;\n\n // https://github.com/rockcarver/frodo-cli/issues/109\n // printMessage(`Connected to ${versionInfo.fullVersion}`);\n\n // https://github.com/rockcarver/frodo-cli/issues/102\n printMessage(\n `Connected to [${storage.session.getTenant()}], [${\n !storage.session.getRealm() ? 'alpha' : storage.session.getRealm()\n }] realm, as [${storage.session.getUsername()}]`\n );\n const version = await getSemanticVersion(versionInfo);\n storage.session.setAmVersion(version);\n return '';\n }\n printMessage(`error authenticating`, 'error');\n printMessage('+++ likely cause, bad credentials!!! +++', 'error');\n return null;\n } catch (e) {\n if (e.response?.status === 401) {\n printMessage(`error authenticating - ${e.message}`, 'error');\n printMessage('+++ likely cause, bad credentials +++', 'error');\n }\n if (e.message === 'self signed certificate') {\n printMessage(`error authenticating - ${e.message}`, 'error');\n printMessage('+++ use -k, --insecure option to allow +++', 'error');\n } else {\n printMessage(`error authenticating - ${e.message}`, 'error');\n printMessage(e.response?.data, 'error');\n }\n return null;\n }\n}\n\n/**\n * Helper function to obtain an oauth2 authorization code\n * @param {String} redirectURL oauth2 redirect uri\n * @param {String} codeChallenge PKCE code challenge\n * @param {String} codeChallengeMethod PKCE code challenge method\n * @returns {String} oauth2 authorization code or null\n */\nasync function getAuthCode(redirectURL, codeChallenge, codeChallengeMethod) {\n try {\n const bodyFormData = `redirect_uri=${redirectURL}&scope=${idmAdminScope}&response_type=code&client_id=${adminClientId}&csrf=${storage.session.getCookieValue()}&decision=allow&code_challenge=${codeChallenge}&code_challenge_method=${codeChallengeMethod}`;\n const config = {\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n };\n const response = await authorize(bodyFormData, config);\n if (response.status < 200 || response.status > 399) {\n printMessage('error getting auth code', 'error');\n printMessage(\n 'likely cause: mismatched parameters with OAuth client config',\n 'error'\n );\n return null;\n }\n const redirectLocationURL = response.request.res.responseUrl;\n const queryObject = url.parse(redirectLocationURL, true).query;\n if ('code' in queryObject) {\n return queryObject.code;\n }\n printMessage('auth code not found', 'error');\n return null;\n } catch (error) {\n printMessage(`error getting auth code - ${error.message}`, 'error');\n printMessage(error.response.data, 'error');\n return null;\n }\n}\n\n/**\n * Helper function to obtain oauth2 access token\n * @returns {String} empty string or null\n */\nasync function getAccessToken() {\n try {\n const verifier = encodeBase64Url(randomBytes(32));\n const challenge = encodeBase64Url(\n createHash('sha256').update(verifier).digest()\n );\n const challengeMethod = 'S256';\n const redirectURL = url.resolve(\n storage.session.getTenant(),\n redirectUrlTemplate\n );\n const authCode = await getAuthCode(redirectURL, challenge, challengeMethod);\n if (authCode == null) {\n printMessage('error getting auth code', 'error');\n return null;\n }\n let response = null;\n if (\n storage.session.getDeploymentType() === global.CLOUD_DEPLOYMENT_TYPE_KEY\n ) {\n const config = {\n auth: {\n username: adminClientId,\n password: adminClientPassword,\n },\n };\n const bodyFormData = `redirect_uri=${redirectURL}&grant_type=authorization_code&code=${authCode}&code_verifier=${verifier}`;\n response = await accessToken(bodyFormData, config);\n } else {\n const bodyFormData = `client_id=${adminClientId}&redirect_uri=${redirectURL}&grant_type=authorization_code&code=${authCode}&code_verifier=${verifier}`;\n response = await accessToken(bodyFormData);\n }\n if (response.status < 200 || response.status > 399) {\n printMessage(`access token call returned ${response.status}`, 'error');\n return null;\n }\n if ('access_token' in response.data) {\n storage.session.setBearerToken(response.data.access_token);\n return '';\n }\n printMessage(\"can't get access token\", 'error');\n return null;\n } catch (e) {\n printMessage('error getting access token - ', 'error');\n return null;\n }\n}\n\n/**\n * Get tokens\n * @param {boolean} save true to save a connection profile upon successful authentication, false otherwise\n * @returns {boolean} true if tokens were successfully obtained, false otherwise\n */\nexport async function getTokens(save = false) {\n let credsFromParameters = true;\n // if username/password on cli are empty, try to read from connections.json\n if (\n storage.session.getUsername() == null &&\n storage.session.getPassword() == null\n ) {\n credsFromParameters = false;\n const conn = await getConnectionProfile();\n if (conn) {\n storage.session.setTenant(conn.tenant);\n storage.session.setUsername(conn.username);\n storage.session.setPassword(conn.password);\n storage.session.setAuthenticationService(conn.authenticationService);\n storage.session.setAuthenticationHeaderOverrides(\n conn.authenticationHeaderOverrides\n );\n } else {\n return false;\n }\n }\n await authenticate();\n if (\n storage.session.getCookieValue() &&\n !storage.session.getBearerToken() &&\n (storage.session.getDeploymentType() === global.CLOUD_DEPLOYMENT_TYPE_KEY ||\n storage.session.getDeploymentType() ===\n global.FORGEOPS_DEPLOYMENT_TYPE_KEY)\n ) {\n await getAccessToken();\n }\n if (save && storage.session.getCookieValue() && credsFromParameters) {\n // valid cookie, which means valid username/password combo. Save it in connections.json\n saveConnectionProfile();\n return true;\n }\n if (!storage.session.getCookieValue()) {\n return false;\n }\n return true;\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAKA,IAAMA,mBAAmB,GAAG,eAA5B;AACA,IAAMC,mBAAmB,GAAG,sCAA5B;AAEA,IAAMC,aAAa,GAAG,iBAAtB;AAEA,IAAIC,aAAa,GAAG,gBAApB;AAEA;AACA;AACA;AACA;;SACeC,a;;;AASf;AACA;AACA;AACA;AACA;;;;qCAbA,aAA+B;IAC7B,IAAI;MACF,OAAO,OAAO,IAAAC,4BAAA,GAAP,EAAwBC,IAAxB,CAA6BC,UAApC;IACD,CAFD,CAEE,OAAOC,KAAP,EAAc;MACd,IAAAC,qBAAA,uCAA2CD,KAA3C,GAAoD,OAApD;MACA,OAAO,IAAP;IACD;EACF,C;;;;AAOD,SAASE,iBAAT,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AAIS,IAAI,IAAI7E,uBAAA,CAAQC,OAAR,CAAgBwB,cAAhB,EAAR,IAA4CqD,mBAAhD,EAAqE;MACnE;MACA,IAAAY,2CAAA;MACA,OAAO,IAAP;IACD;;IACD,IAAI,CAAC1F,uBAAA,CAAQC,OAAR,CAAgBwB,cAAhB,EAAL,EAAuC;MACrC,OAAO,KAAP;IACD;;IACD,OAAO,IAAP;EACD,C"}
|
|
@@ -53,15 +53,17 @@ function getConnectionProfilesPath() {
|
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
function findConnectionProfile(connectionProfiles, host) {
|
|
56
|
+
var profiles = [];
|
|
57
|
+
|
|
56
58
|
for (var tenant in connectionProfiles) {
|
|
57
59
|
if (tenant.includes(host)) {
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
var foundProfile = connectionProfiles[tenant];
|
|
61
|
+
foundProfile.tenant = tenant;
|
|
62
|
+
profiles.push(foundProfile);
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
return
|
|
66
|
+
return profiles;
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
67
69
|
* List connection profiles
|
|
@@ -161,21 +163,30 @@ function _getConnectionProfileByHost() {
|
|
|
161
163
|
try {
|
|
162
164
|
var filename = getConnectionProfilesPath();
|
|
163
165
|
var connectionsData = JSON.parse(_fs.default.readFileSync(filename, 'utf8'));
|
|
164
|
-
var
|
|
166
|
+
var profiles = findConnectionProfile(connectionsData, host);
|
|
165
167
|
|
|
166
|
-
if (
|
|
168
|
+
if (profiles.length == 0) {
|
|
167
169
|
(0, _Console.printMessage)("Profile for ".concat(host, " not found. Please specify credentials on command line"), 'error');
|
|
168
170
|
return null;
|
|
169
171
|
}
|
|
170
172
|
|
|
173
|
+
if (profiles.length > 1) {
|
|
174
|
+
(0, _Console.printMessage)("Multiple matching profiles found.", 'error');
|
|
175
|
+
profiles.forEach(p => {
|
|
176
|
+
(0, _Console.printMessage)("- ".concat(p.tenant), 'error');
|
|
177
|
+
});
|
|
178
|
+
(0, _Console.printMessage)("Please specify a unique sub-string", 'error');
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
|
|
171
182
|
return {
|
|
172
|
-
tenant:
|
|
173
|
-
username:
|
|
174
|
-
password:
|
|
175
|
-
key:
|
|
176
|
-
secret:
|
|
177
|
-
authenticationService:
|
|
178
|
-
authenticationHeaderOverrides:
|
|
183
|
+
tenant: profiles[0].tenant,
|
|
184
|
+
username: profiles[0].username ? profiles[0].username : null,
|
|
185
|
+
password: profiles[0].encodedPassword ? yield dataProtection.decrypt(profiles[0].encodedPassword) : null,
|
|
186
|
+
key: profiles[0].logApiKey ? profiles[0].logApiKey : null,
|
|
187
|
+
secret: profiles[0].logApiSecret ? profiles[0].logApiSecret : null,
|
|
188
|
+
authenticationService: profiles[0].authenticationService ? profiles[0].authenticationService : null,
|
|
189
|
+
authenticationHeaderOverrides: profiles[0].authenticationHeaderOverrides ? profiles[0].authenticationHeaderOverrides : {}
|
|
179
190
|
};
|
|
180
191
|
} catch (e) {
|
|
181
192
|
(0, _Console.printMessage)("Can not read saved connection info, please specify credentials on command line: ".concat(e), 'error');
|
|
@@ -263,15 +274,24 @@ function deleteConnectionProfile(host) {
|
|
|
263
274
|
var data = _fs.default.readFileSync(filename, 'utf8');
|
|
264
275
|
|
|
265
276
|
connectionsData = JSON.parse(data);
|
|
266
|
-
var
|
|
277
|
+
var profiles = findConnectionProfile(connectionsData, host);
|
|
267
278
|
|
|
268
|
-
if (
|
|
269
|
-
(0, _Console.printMessage)("Deleting connection profile ".concat(
|
|
270
|
-
delete connectionsData[
|
|
279
|
+
if (profiles.length == 1) {
|
|
280
|
+
(0, _Console.printMessage)("Deleting connection profile ".concat(profiles[0].tenant));
|
|
281
|
+
delete connectionsData[profiles[0].tenant];
|
|
271
282
|
|
|
272
283
|
_fs.default.writeFileSync(filename, JSON.stringify(connectionsData, null, 2));
|
|
273
284
|
} else {
|
|
274
|
-
|
|
285
|
+
if (profiles.length > 1) {
|
|
286
|
+
(0, _Console.printMessage)("Multiple matching profiles found.", 'error');
|
|
287
|
+
profiles.forEach(p => {
|
|
288
|
+
(0, _Console.printMessage)("- ".concat(p.tenant), 'error');
|
|
289
|
+
});
|
|
290
|
+
(0, _Console.printMessage)("Please specify a unique sub-string", 'error');
|
|
291
|
+
return null;
|
|
292
|
+
} else {
|
|
293
|
+
(0, _Console.printMessage)("No connection profile ".concat(host, " found"));
|
|
294
|
+
}
|
|
275
295
|
}
|
|
276
296
|
} else if (err.code === 'ENOENT') {
|
|
277
297
|
(0, _Console.printMessage)("Connection profile file ".concat(filename, " not found"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionProfileOps.js","names":["dataProtection","DataProtection","fileOptions","indentation","getConnectionProfilesPath","storage","session","process","env","FRODO_CONNECTION_PROFILES_PATH_KEY","os","homedir","findConnectionProfile","connectionProfiles","host","tenant","includes","profile","listConnectionProfiles","long","filename","data","fs","readFileSync","connectionsData","JSON","parse","table","createTable","Object","keys","forEach","c","push","username","logApiKey","printMessage","toString","e","message","initConnectionProfiles","folderName","path","dirname","existsSync","mkdirSync","recursive","writeFileSync","stringify","convert","conn","password","encodedPassword","encrypt","getConnectionProfileByHost","decrypt","key","secret","logApiSecret","authenticationService","authenticationHeaderOverrides","getConnectionProfile","getTenant","saveConnectionProfile","existingData","statSync","getUsername","getPassword","getLogApiKey","getLogApiSecret","getAuthenticationService","getAuthenticationHeaderOverrides","deleteConnectionProfile","stat","err","code","describeConnectionProfile","showSecrets","keyMap","createObjectTable"],"sources":["ops/ConnectionProfileOps.ts"],"sourcesContent":["import fs from 'fs';\nimport os from 'os';\nimport path from 'path';\nimport storage from '../storage/SessionStorage';\nimport DataProtection from './utils/DataProtection';\nimport { createObjectTable, createTable, printMessage } from './utils/Console';\nimport { FRODO_CONNECTION_PROFILES_PATH_KEY } from '../storage/StaticStorage';\n\nconst dataProtection = new DataProtection();\n\nconst fileOptions = {\n indentation: 4,\n};\n\n/**\n * Get connection profiles file name\n * @returns {String} connection profiles file name\n */\nexport function getConnectionProfilesPath(): string {\n return (\n storage.session.getConnectionProfilesPath() ||\n process.env[FRODO_CONNECTION_PROFILES_PATH_KEY] ||\n `${os.homedir()}/.frodo/.frodorc`\n );\n}\n\n/**\n * Find connection profile\n * @param {Object} connectionProfiles connection profile object\n * @param {String} host tenant host url or unique substring\n * @returns {Object} connection profile object or null\n */\nfunction findConnectionProfile(connectionProfiles, host) {\n for (const tenant in connectionProfiles) {\n if (tenant.includes(host)) {\n const profile = connectionProfiles[tenant];\n profile.tenant = tenant;\n return profile;\n }\n }\n return null;\n}\n\n/**\n * List connection profiles\n * @param {boolean} long Long list format with details\n */\nexport function listConnectionProfiles(long = false) {\n const filename = getConnectionProfilesPath();\n try {\n const data = fs.readFileSync(filename, 'utf8');\n const connectionsData = JSON.parse(data);\n if (long) {\n const table = createTable(['Host', 'Username', 'Log API Key']);\n Object.keys(connectionsData).forEach((c) => {\n table.push([\n c,\n connectionsData[c].username,\n connectionsData[c].logApiKey,\n ]);\n });\n printMessage(table.toString(), 'data');\n } else {\n Object.keys(connectionsData).forEach((c) => {\n printMessage(`${c}`, 'data');\n });\n }\n printMessage(\n 'Any unique substring of a saved host can be used as the value for host parameter in all commands',\n 'info'\n );\n } catch (e) {\n printMessage(`No connections found in ${filename} (${e.message})`, 'error');\n }\n}\n\n/**\n * Initialize connection profiles\n */\nexport function initConnectionProfiles() {\n // create connections.json file if it doesn't exist\n const filename = getConnectionProfilesPath();\n const folderName = path.dirname(filename);\n if (!fs.existsSync(folderName)) {\n fs.mkdirSync(folderName, { recursive: true });\n if (!fs.existsSync(filename)) {\n fs.writeFileSync(\n filename,\n JSON.stringify({}, null, fileOptions.indentation)\n );\n }\n }\n // encrypt the password from clear text to aes-256-GCM\n else {\n const data = fs.readFileSync(filename, 'utf8');\n const connectionsData = JSON.parse(data);\n let convert = false;\n Object.keys(connectionsData).forEach(async (conn) => {\n if (connectionsData[conn].password) {\n convert = true;\n connectionsData[conn].encodedPassword = await dataProtection.encrypt(\n connectionsData[conn].password\n ); // Buffer.from(connectionsData[conn].password).toString('base64');\n delete connectionsData[conn].password;\n }\n });\n if (convert) {\n fs.writeFileSync(\n filename,\n JSON.stringify(connectionsData, null, fileOptions.indentation)\n );\n }\n }\n}\n\n/**\n * Get connection profile by host\n * @param {String} host host tenant host url or unique substring\n * @returns {Object} connection profile or null\n */\nexport async function getConnectionProfileByHost(host) {\n try {\n const filename = getConnectionProfilesPath();\n const connectionsData = JSON.parse(fs.readFileSync(filename, 'utf8'));\n const profile = findConnectionProfile(connectionsData, host);\n if (!profile) {\n printMessage(\n `Profile for ${host} not found. Please specify credentials on command line`,\n 'error'\n );\n return null;\n }\n return {\n tenant: profile.tenant,\n username: profile.username ? profile.username : null,\n password: profile.encodedPassword\n ? await dataProtection.decrypt(profile.encodedPassword)\n : null,\n key: profile.logApiKey ? profile.logApiKey : null,\n secret: profile.logApiSecret ? profile.logApiSecret : null,\n authenticationService: profile.authenticationService\n ? profile.authenticationService\n : null,\n authenticationHeaderOverrides: profile.authenticationHeaderOverrides\n ? profile.authenticationHeaderOverrides\n : {},\n };\n } catch (e) {\n printMessage(\n `Can not read saved connection info, please specify credentials on command line: ${e}`,\n 'error'\n );\n return null;\n }\n}\n\n/**\n * Get connection profile\n * @returns {Object} connection profile or null\n */\nexport async function getConnectionProfile() {\n return getConnectionProfileByHost(storage.session.getTenant());\n}\n\n/**\n * Save connection profile\n */\nexport async function saveConnectionProfile() {\n const filename = getConnectionProfilesPath();\n printMessage(`Saving creds in ${filename}...`);\n let connectionsData = {};\n let existingData = {};\n try {\n fs.statSync(filename);\n const data = fs.readFileSync(filename, 'utf8');\n connectionsData = JSON.parse(data);\n if (connectionsData[storage.session.getTenant()]) {\n existingData = connectionsData[storage.session.getTenant()];\n printMessage(\n `Updating connection profile ${storage.session.getTenant()}`\n );\n } else\n printMessage(`Adding connection profile ${storage.session.getTenant()}`);\n } catch (e) {\n printMessage(\n `Creating connection profiles file ${filename} with ${storage.session.getTenant()}`\n );\n }\n if (storage.session.getUsername())\n existingData['username'] = storage.session.getUsername();\n if (storage.session.getPassword())\n existingData['encodedPassword'] = await dataProtection.encrypt(\n storage.session.getPassword()\n );\n if (storage.session.getLogApiKey())\n existingData['logApiKey'] = storage.session.getLogApiKey();\n if (storage.session.getLogApiSecret())\n existingData['logApiSecret'] = storage.session.getLogApiSecret();\n\n // advanced settings\n if (storage.session.getAuthenticationService()) {\n existingData['authenticationService'] =\n storage.session.getAuthenticationService();\n printMessage(\n 'Advanced setting: Authentication Service: ' +\n storage.session.getAuthenticationService(),\n 'info'\n );\n }\n if (storage.session.getAuthenticationHeaderOverrides()) {\n existingData['authenticationHeaderOverrides'] =\n storage.session.getAuthenticationHeaderOverrides();\n printMessage('Advanced setting: Authentication Header Overrides: ', 'info');\n printMessage(storage.session.getAuthenticationHeaderOverrides(), 'info');\n }\n\n connectionsData[storage.session.getTenant()] = existingData;\n\n fs.writeFileSync(filename, JSON.stringify(connectionsData, null, 2));\n}\n\n/**\n * Delete connection profile\n * @param {String} host host tenant host url or unique substring\n */\nexport function deleteConnectionProfile(host) {\n const filename = getConnectionProfilesPath();\n let connectionsData = {};\n fs.stat(filename, (err) => {\n if (err == null) {\n const data = fs.readFileSync(filename, 'utf8');\n connectionsData = JSON.parse(data);\n const profile = findConnectionProfile(connectionsData, host);\n if (profile) {\n printMessage(`Deleting connection profile ${profile.tenant}`);\n delete connectionsData[profile.tenant];\n fs.writeFileSync(filename, JSON.stringify(connectionsData, null, 2));\n } else {\n printMessage(`No connection profile ${host} found`);\n }\n } else if (err.code === 'ENOENT') {\n printMessage(`Connection profile file ${filename} not found`);\n } else {\n printMessage(\n `Error in deleting connection profile: ${err.code}`,\n 'error'\n );\n }\n });\n}\n\nexport async function describeConnectionProfile(host, showSecrets) {\n const profile = await getConnectionProfileByHost(host);\n if (profile) {\n if (!showSecrets) {\n delete profile.password;\n delete profile.secret;\n }\n if (!profile.key) {\n delete profile.key;\n delete profile.secret;\n }\n const keyMap = {\n tenant: 'Host',\n username: 'Username',\n password: 'Password',\n key: 'Log API Key',\n secret: 'Log API Secret',\n authenticationService: 'Authentication Service',\n authenticationHeaderOverrides: 'Authentication Header Overrides',\n };\n const table = createObjectTable(profile, keyMap);\n printMessage(table.toString(), 'data');\n } else {\n printMessage(`No connection profile ${host} found`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,cAAc,GAAG,IAAIC,uBAAJ,EAAvB;AAEA,IAAMC,WAAW,GAAG;EAClBC,WAAW,EAAE;AADK,CAApB;AAIA;AACA;AACA;AACA;;AACO,SAASC,yBAAT,GAA6C;EAClD,OACEC,uBAAA,CAAQC,OAAR,CAAgBF,yBAAhB,MACAG,OAAO,CAACC,GAAR,CAAYC,iDAAZ,CADA,cAEGC,WAAA,CAAGC,OAAH,EAFH,qBADF;AAKD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,qBAAT,CAA+BC,kBAA/B,EAAmDC,IAAnD,EAAyD;EACvD,KAAK,IAAMC,MAAX,IAAqBF,kBAArB,EAAyC;IACvC,IAAIE,MAAM,CAACC,QAAP,CAAgBF,IAAhB,CAAJ,EAA2B;MACzB,IAAMG,OAAO,GAAGJ,kBAAkB,CAACE,MAAD,CAAlC;MACAE,OAAO,CAACF,MAAR,GAAiBA,MAAjB;MACA,OAAOE,OAAP;IACD;EACF;;EACD,OAAO,IAAP;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASC,sBAAT,GAA8C;EAAA,IAAdC,IAAc,uEAAP,KAAO;EACnD,IAAMC,QAAQ,GAAGhB,yBAAyB,EAA1C;;EACA,IAAI;IACF,IAAMiB,IAAI,GAAGC,WAAA,CAAGC,YAAH,CAAgBH,QAAhB,EAA0B,MAA1B,CAAb;;IACA,IAAMI,eAAe,GAAGC,IAAI,CAACC,KAAL,CAAWL,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"ConnectionProfileOps.js","names":["dataProtection","DataProtection","fileOptions","indentation","getConnectionProfilesPath","storage","session","process","env","FRODO_CONNECTION_PROFILES_PATH_KEY","os","homedir","findConnectionProfile","connectionProfiles","host","profiles","tenant","includes","foundProfile","push","listConnectionProfiles","long","filename","data","fs","readFileSync","connectionsData","JSON","parse","table","createTable","Object","keys","forEach","c","username","logApiKey","printMessage","toString","e","message","initConnectionProfiles","folderName","path","dirname","existsSync","mkdirSync","recursive","writeFileSync","stringify","convert","conn","password","encodedPassword","encrypt","getConnectionProfileByHost","length","p","decrypt","key","secret","logApiSecret","authenticationService","authenticationHeaderOverrides","getConnectionProfile","getTenant","saveConnectionProfile","existingData","statSync","getUsername","getPassword","getLogApiKey","getLogApiSecret","getAuthenticationService","getAuthenticationHeaderOverrides","deleteConnectionProfile","stat","err","code","describeConnectionProfile","showSecrets","profile","keyMap","createObjectTable"],"sources":["ops/ConnectionProfileOps.ts"],"sourcesContent":["import fs from 'fs';\nimport os from 'os';\nimport path from 'path';\nimport storage from '../storage/SessionStorage';\nimport DataProtection from './utils/DataProtection';\nimport { createObjectTable, createTable, printMessage } from './utils/Console';\nimport { FRODO_CONNECTION_PROFILES_PATH_KEY } from '../storage/StaticStorage';\nimport { profile } from 'console';\n\nconst dataProtection = new DataProtection();\n\nconst fileOptions = {\n indentation: 4,\n};\n\n/**\n * Get connection profiles file name\n * @returns {String} connection profiles file name\n */\nexport function getConnectionProfilesPath(): string {\n return (\n storage.session.getConnectionProfilesPath() ||\n process.env[FRODO_CONNECTION_PROFILES_PATH_KEY] ||\n `${os.homedir()}/.frodo/.frodorc`\n );\n}\n\n/**\n * Find connection profile\n * @param {Object} connectionProfiles connection profile object\n * @param {String} host tenant host url or unique substring\n * @returns {Object} connection profile object or null\n */\nfunction findConnectionProfile(connectionProfiles, host) {\n const profiles = [];\n for (const tenant in connectionProfiles) {\n if (tenant.includes(host)) {\n const foundProfile = connectionProfiles[tenant];\n foundProfile.tenant = tenant;\n profiles.push(foundProfile);\n }\n }\n return profiles;\n}\n\n/**\n * List connection profiles\n * @param {boolean} long Long list format with details\n */\nexport function listConnectionProfiles(long = false) {\n const filename = getConnectionProfilesPath();\n try {\n const data = fs.readFileSync(filename, 'utf8');\n const connectionsData = JSON.parse(data);\n if (long) {\n const table = createTable(['Host', 'Username', 'Log API Key']);\n Object.keys(connectionsData).forEach((c) => {\n table.push([\n c,\n connectionsData[c].username,\n connectionsData[c].logApiKey,\n ]);\n });\n printMessage(table.toString(), 'data');\n } else {\n Object.keys(connectionsData).forEach((c) => {\n printMessage(`${c}`, 'data');\n });\n }\n printMessage(\n 'Any unique substring of a saved host can be used as the value for host parameter in all commands',\n 'info'\n );\n } catch (e) {\n printMessage(`No connections found in ${filename} (${e.message})`, 'error');\n }\n}\n\n/**\n * Initialize connection profiles\n */\nexport function initConnectionProfiles() {\n // create connections.json file if it doesn't exist\n const filename = getConnectionProfilesPath();\n const folderName = path.dirname(filename);\n if (!fs.existsSync(folderName)) {\n fs.mkdirSync(folderName, { recursive: true });\n if (!fs.existsSync(filename)) {\n fs.writeFileSync(\n filename,\n JSON.stringify({}, null, fileOptions.indentation)\n );\n }\n }\n // encrypt the password from clear text to aes-256-GCM\n else {\n const data = fs.readFileSync(filename, 'utf8');\n const connectionsData = JSON.parse(data);\n let convert = false;\n Object.keys(connectionsData).forEach(async (conn) => {\n if (connectionsData[conn].password) {\n convert = true;\n connectionsData[conn].encodedPassword = await dataProtection.encrypt(\n connectionsData[conn].password\n ); // Buffer.from(connectionsData[conn].password).toString('base64');\n delete connectionsData[conn].password;\n }\n });\n if (convert) {\n fs.writeFileSync(\n filename,\n JSON.stringify(connectionsData, null, fileOptions.indentation)\n );\n }\n }\n}\n\n/**\n * Get connection profile by host\n * @param {String} host host tenant host url or unique substring\n * @returns {Object} connection profile or null\n */\nexport async function getConnectionProfileByHost(host) {\n try {\n const filename = getConnectionProfilesPath();\n const connectionsData = JSON.parse(fs.readFileSync(filename, 'utf8'));\n const profiles = findConnectionProfile(connectionsData, host);\n if (profiles.length == 0) {\n printMessage(\n `Profile for ${host} not found. Please specify credentials on command line`,\n 'error'\n );\n return null;\n }\n if (profiles.length > 1) {\n printMessage(`Multiple matching profiles found.`, 'error');\n profiles.forEach((p) => {\n printMessage(`- ${p.tenant}`, 'error');\n });\n printMessage(`Please specify a unique sub-string`, 'error');\n return null;\n }\n return {\n tenant: profiles[0].tenant,\n username: profiles[0].username ? profiles[0].username : null,\n password: profiles[0].encodedPassword\n ? await dataProtection.decrypt(profiles[0].encodedPassword)\n : null,\n key: profiles[0].logApiKey ? profiles[0].logApiKey : null,\n secret: profiles[0].logApiSecret ? profiles[0].logApiSecret : null,\n authenticationService: profiles[0].authenticationService\n ? profiles[0].authenticationService\n : null,\n authenticationHeaderOverrides: profiles[0].authenticationHeaderOverrides\n ? profiles[0].authenticationHeaderOverrides\n : {},\n };\n } catch (e) {\n printMessage(\n `Can not read saved connection info, please specify credentials on command line: ${e}`,\n 'error'\n );\n return null;\n }\n}\n\n/**\n * Get connection profile\n * @returns {Object} connection profile or null\n */\nexport async function getConnectionProfile() {\n return getConnectionProfileByHost(storage.session.getTenant());\n}\n\n/**\n * Save connection profile\n */\nexport async function saveConnectionProfile() {\n const filename = getConnectionProfilesPath();\n printMessage(`Saving creds in ${filename}...`);\n let connectionsData = {};\n let existingData = {};\n try {\n fs.statSync(filename);\n const data = fs.readFileSync(filename, 'utf8');\n connectionsData = JSON.parse(data);\n if (connectionsData[storage.session.getTenant()]) {\n existingData = connectionsData[storage.session.getTenant()];\n printMessage(\n `Updating connection profile ${storage.session.getTenant()}`\n );\n } else\n printMessage(`Adding connection profile ${storage.session.getTenant()}`);\n } catch (e) {\n printMessage(\n `Creating connection profiles file ${filename} with ${storage.session.getTenant()}`\n );\n }\n if (storage.session.getUsername())\n existingData['username'] = storage.session.getUsername();\n if (storage.session.getPassword())\n existingData['encodedPassword'] = await dataProtection.encrypt(\n storage.session.getPassword()\n );\n if (storage.session.getLogApiKey())\n existingData['logApiKey'] = storage.session.getLogApiKey();\n if (storage.session.getLogApiSecret())\n existingData['logApiSecret'] = storage.session.getLogApiSecret();\n\n // advanced settings\n if (storage.session.getAuthenticationService()) {\n existingData['authenticationService'] =\n storage.session.getAuthenticationService();\n printMessage(\n 'Advanced setting: Authentication Service: ' +\n storage.session.getAuthenticationService(),\n 'info'\n );\n }\n if (storage.session.getAuthenticationHeaderOverrides()) {\n existingData['authenticationHeaderOverrides'] =\n storage.session.getAuthenticationHeaderOverrides();\n printMessage('Advanced setting: Authentication Header Overrides: ', 'info');\n printMessage(storage.session.getAuthenticationHeaderOverrides(), 'info');\n }\n\n connectionsData[storage.session.getTenant()] = existingData;\n\n fs.writeFileSync(filename, JSON.stringify(connectionsData, null, 2));\n}\n\n/**\n * Delete connection profile\n * @param {String} host host tenant host url or unique substring\n */\nexport function deleteConnectionProfile(host) {\n const filename = getConnectionProfilesPath();\n let connectionsData = {};\n fs.stat(filename, (err) => {\n if (err == null) {\n const data = fs.readFileSync(filename, 'utf8');\n connectionsData = JSON.parse(data);\n const profiles = findConnectionProfile(connectionsData, host);\n if (profiles.length == 1) {\n printMessage(`Deleting connection profile ${profiles[0].tenant}`);\n delete connectionsData[profiles[0].tenant];\n fs.writeFileSync(filename, JSON.stringify(connectionsData, null, 2));\n } else {\n if (profiles.length > 1) {\n printMessage(`Multiple matching profiles found.`, 'error');\n profiles.forEach((p) => {\n printMessage(`- ${p.tenant}`, 'error');\n });\n printMessage(`Please specify a unique sub-string`, 'error');\n return null;\n } else {\n printMessage(`No connection profile ${host} found`);\n }\n }\n } else if (err.code === 'ENOENT') {\n printMessage(`Connection profile file ${filename} not found`);\n } else {\n printMessage(\n `Error in deleting connection profile: ${err.code}`,\n 'error'\n );\n }\n });\n}\n\nexport async function describeConnectionProfile(host, showSecrets) {\n const profile = await getConnectionProfileByHost(host);\n if (profile) {\n if (!showSecrets) {\n delete profile.password;\n delete profile.secret;\n }\n if (!profile.key) {\n delete profile.key;\n delete profile.secret;\n }\n const keyMap = {\n tenant: 'Host',\n username: 'Username',\n password: 'Password',\n key: 'Log API Key',\n secret: 'Log API Secret',\n authenticationService: 'Authentication Service',\n authenticationHeaderOverrides: 'Authentication Header Overrides',\n };\n const table = createObjectTable(profile, keyMap);\n printMessage(table.toString(), 'data');\n } else {\n printMessage(`No connection profile ${host} found`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAGA,IAAMA,cAAc,GAAG,IAAIC,uBAAJ,EAAvB;AAEA,IAAMC,WAAW,GAAG;EAClBC,WAAW,EAAE;AADK,CAApB;AAIA;AACA;AACA;AACA;;AACO,SAASC,yBAAT,GAA6C;EAClD,OACEC,uBAAA,CAAQC,OAAR,CAAgBF,yBAAhB,MACAG,OAAO,CAACC,GAAR,CAAYC,iDAAZ,CADA,cAEGC,WAAA,CAAGC,OAAH,EAFH,qBADF;AAKD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,qBAAT,CAA+BC,kBAA/B,EAAmDC,IAAnD,EAAyD;EACvD,IAAMC,QAAQ,GAAG,EAAjB;;EACA,KAAK,IAAMC,MAAX,IAAqBH,kBAArB,EAAyC;IACvC,IAAIG,MAAM,CAACC,QAAP,CAAgBH,IAAhB,CAAJ,EAA2B;MACzB,IAAMI,YAAY,GAAGL,kBAAkB,CAACG,MAAD,CAAvC;MACAE,YAAY,CAACF,MAAb,GAAsBA,MAAtB;MACAD,QAAQ,CAACI,IAAT,CAAcD,YAAd;IACD;EACF;;EACD,OAAOH,QAAP;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASK,sBAAT,GAA8C;EAAA,IAAdC,IAAc,uEAAP,KAAO;EACnD,IAAMC,QAAQ,GAAGlB,yBAAyB,EAA1C;;EACA,IAAI;IACF,IAAMmB,IAAI,GAAGC,WAAA,CAAGC,YAAH,CAAgBH,QAAhB,EAA0B,MAA1B,CAAb;;IACA,IAAMI,eAAe,GAAGC,IAAI,CA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