@rockcarver/frodo-lib 2.0.0-3 → 2.0.0-4
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 +5 -1
- package/cjs/api/AgentApi.js +64 -16
- package/cjs/api/AgentApi.js.map +1 -1
- package/cjs/api/ApiTypes.js +0 -55
- package/cjs/api/ApiTypes.js.map +1 -1
- package/cjs/api/BaseApi.js +21 -11
- package/cjs/api/BaseApi.js.map +1 -1
- package/cjs/api/cloud/SecretsApi.js +7 -14
- package/cjs/api/cloud/SecretsApi.js.map +1 -1
- package/cjs/api/cloud/SecretsApi.test.js.map +1 -1
- package/cjs/ops/AdminOps.js +254 -60
- package/cjs/ops/AdminOps.js.map +1 -1
- package/cjs/ops/AgentOps.js +352 -108
- package/cjs/ops/AgentOps.js.map +1 -1
- package/cjs/ops/AuthenticateOps.js +253 -60
- package/cjs/ops/AuthenticateOps.js.map +1 -1
- package/cjs/ops/CirclesOfTrustOps.js +16 -4
- package/cjs/ops/CirclesOfTrustOps.js.map +1 -1
- package/cjs/ops/ConnectionProfileOps.js +163 -40
- package/cjs/ops/ConnectionProfileOps.js.map +1 -1
- package/cjs/ops/EmailTemplateOps.js +7 -1
- package/cjs/ops/EmailTemplateOps.js.map +1 -1
- package/cjs/ops/IdpOps.js +55 -12
- package/cjs/ops/IdpOps.js.map +1 -1
- package/cjs/ops/JourneyOps.js +645 -136
- package/cjs/ops/JourneyOps.js.map +1 -1
- package/cjs/ops/NodeOps.js +96 -24
- package/cjs/ops/NodeOps.js.map +1 -1
- package/cjs/ops/OAuth2ClientOps.js +45 -11
- package/cjs/ops/OAuth2ClientOps.js.map +1 -1
- package/cjs/ops/OpsTypes.js +0 -23
- package/cjs/ops/OpsTypes.js.map +1 -1
- package/cjs/ops/OrganizationOps.js +44 -10
- package/cjs/ops/OrganizationOps.js.map +1 -1
- package/cjs/ops/PolicyOps.js +86 -24
- package/cjs/ops/PolicyOps.js.map +1 -1
- package/cjs/ops/PolicySetOps.js +72 -18
- package/cjs/ops/PolicySetOps.js.map +1 -1
- package/cjs/ops/ResourceTypeOps.js +24 -6
- package/cjs/ops/ResourceTypeOps.js.map +1 -1
- package/cjs/ops/Saml2Ops.js +120 -33
- package/cjs/ops/Saml2Ops.js.map +1 -1
- package/cjs/ops/Saml2Ops.test.js.map +1 -1
- package/cjs/ops/ScriptOps.js +73 -17
- package/cjs/ops/ScriptOps.js.map +1 -1
- package/cjs/ops/ServiceOps.js +152 -35
- package/cjs/ops/ServiceOps.js.map +1 -1
- package/cjs/ops/ThemeOps.js +20 -5
- package/cjs/ops/ThemeOps.js.map +1 -1
- package/cjs/ops/cloud/FeatureOps.js +4 -1
- package/cjs/ops/cloud/FeatureOps.js.map +1 -1
- package/cjs/ops/cloud/SecretsOps.js.map +1 -1
- package/cjs/ops/cloud/ServiceAccountOps.js +24 -6
- package/cjs/ops/cloud/ServiceAccountOps.js.map +1 -1
- package/cjs/ops/cloud/StartupOps.js +55 -11
- package/cjs/ops/cloud/StartupOps.js.map +1 -1
- package/cjs/ops/utils/Console.js +47 -22
- package/cjs/ops/utils/Console.js.map +1 -1
- package/cjs/ops/utils/DataProtection.js +12 -5
- package/cjs/ops/utils/DataProtection.js.map +1 -1
- package/cjs/ops/utils/DataProtection.test.js.map +1 -1
- package/cjs/ops/utils/ExportImportUtils.js +15 -8
- package/cjs/ops/utils/ExportImportUtils.js.map +1 -1
- package/cjs/ops/utils/ScriptValidationUtils.js +33 -8
- package/cjs/ops/utils/ScriptValidationUtils.js.map +1 -1
- package/cjs/ops/utils/ScriptValidationUtils.test.js.map +1 -1
- package/cjs/utils/SetupPollyForFrodoLib.js +67 -19
- package/cjs/utils/SetupPollyForFrodoLib.js.map +1 -1
- package/esm/api/AgentApi.mjs +64 -16
- package/esm/api/ApiTypes.mjs +1 -50
- package/esm/api/BaseApi.mjs +21 -11
- package/esm/api/cloud/SecretsApi.mjs +0 -5
- package/esm/api/cloud/SecretsApi.test.mjs +3 -3
- package/esm/ops/AdminOps.mjs +254 -60
- package/esm/ops/AgentOps.mjs +352 -104
- package/esm/ops/AuthenticateOps.mjs +253 -60
- package/esm/ops/CirclesOfTrustOps.mjs +16 -4
- package/esm/ops/ConnectionProfileOps.mjs +163 -40
- package/esm/ops/EmailTemplateOps.mjs +5 -0
- package/esm/ops/IdpOps.mjs +55 -12
- package/esm/ops/JourneyOps.mjs +639 -132
- package/esm/ops/NodeOps.mjs +90 -19
- package/esm/ops/OAuth2ClientOps.mjs +45 -11
- package/esm/ops/OpsTypes.mjs +1 -22
- package/esm/ops/OrganizationOps.mjs +44 -10
- package/esm/ops/PolicyOps.mjs +86 -24
- package/esm/ops/PolicySetOps.mjs +72 -18
- package/esm/ops/ResourceTypeOps.mjs +24 -6
- package/esm/ops/Saml2Ops.mjs +120 -33
- package/esm/ops/Saml2Ops.test.mjs +10 -11
- package/esm/ops/ScriptOps.mjs +73 -17
- package/esm/ops/ServiceOps.mjs +152 -35
- package/esm/ops/ThemeOps.mjs +20 -5
- package/esm/ops/cloud/FeatureOps.mjs +4 -1
- package/esm/ops/cloud/ServiceAccountOps.mjs +24 -6
- package/esm/ops/cloud/StartupOps.mjs +55 -11
- package/esm/ops/utils/Console.mjs +33 -9
- package/esm/ops/utils/DataProtection.mjs +9 -2
- package/esm/ops/utils/DataProtection.test.mjs +8 -2
- package/esm/ops/utils/ExportImportUtils.mjs +15 -8
- package/esm/ops/utils/ScriptValidationUtils.mjs +30 -8
- package/esm/ops/utils/ScriptValidationUtils.test.mjs +14 -3
- package/esm/utils/SetupPollyForFrodoLib.mjs +64 -18
- package/package.json +1 -1
- package/types/api/AgentApi.d.ts +6 -6
- package/types/api/AgentApi.d.ts.map +1 -1
- package/types/api/ApiTypes.d.ts +12 -49
- package/types/api/ApiTypes.d.ts.map +1 -1
- package/types/api/BaseApi.d.ts.map +1 -1
- package/types/api/cloud/SecretsApi.d.ts +1 -4
- package/types/api/cloud/SecretsApi.d.ts.map +1 -1
- package/types/ops/AdminOps.d.ts.map +1 -1
- package/types/ops/AgentOps.d.ts +3 -6
- package/types/ops/AgentOps.d.ts.map +1 -1
- package/types/ops/AuthenticateOps.d.ts.map +1 -1
- package/types/ops/CirclesOfTrustOps.d.ts.map +1 -1
- package/types/ops/ConnectionProfileOps.d.ts.map +1 -1
- package/types/ops/EmailTemplateOps.d.ts +4 -0
- package/types/ops/EmailTemplateOps.d.ts.map +1 -1
- package/types/ops/IdpOps.d.ts.map +1 -1
- package/types/ops/JourneyOps.d.ts +10 -4
- package/types/ops/JourneyOps.d.ts.map +1 -1
- package/types/ops/NodeOps.d.ts +10 -4
- package/types/ops/NodeOps.d.ts.map +1 -1
- package/types/ops/OAuth2ClientOps.d.ts.map +1 -1
- package/types/ops/OpsTypes.d.ts +2 -12
- package/types/ops/OpsTypes.d.ts.map +1 -1
- package/types/ops/OrganizationOps.d.ts.map +1 -1
- package/types/ops/PolicyOps.d.ts.map +1 -1
- package/types/ops/PolicySetOps.d.ts.map +1 -1
- package/types/ops/ResourceTypeOps.d.ts.map +1 -1
- package/types/ops/Saml2Ops.d.ts.map +1 -1
- package/types/ops/ScriptOps.d.ts.map +1 -1
- package/types/ops/ServiceOps.d.ts.map +1 -1
- package/types/ops/ThemeOps.d.ts.map +1 -1
- package/types/ops/cloud/FeatureOps.d.ts.map +1 -1
- package/types/ops/cloud/SecretsOps.d.ts +1 -1
- package/types/ops/cloud/SecretsOps.d.ts.map +1 -1
- package/types/ops/cloud/ServiceAccountOps.d.ts.map +1 -1
- package/types/ops/cloud/StartupOps.d.ts.map +1 -1
- package/types/ops/utils/Console.d.ts +34 -7
- package/types/ops/utils/Console.d.ts.map +1 -1
- package/types/ops/utils/DataProtection.d.ts +5 -1
- package/types/ops/utils/DataProtection.d.ts.map +1 -1
- package/types/ops/utils/ExportImportUtils.d.ts.map +1 -1
- package/types/ops/utils/ScriptValidationUtils.d.ts +14 -4
- package/types/ops/utils/ScriptValidationUtils.d.ts.map +1 -1
- package/types/utils/S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;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,iBAY7D;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,EAChC,OAAO,EACP,KAAK,GACN,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;CACd,iBAgBA;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,iBAY5E;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,OAAO,EACP,KAAK,GACN,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;CACd,iBAoBA;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,iBAYjE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,EACpC,OAAO,EACP,KAAK,GACN,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;CACd,iBAoBA;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,iBAYhE;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,KAAK,GACN,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;CACd,iBAoBA","file":"AgentOps.d.ts","sourcesContent":["import { debugMessage, printMessage } from './utils/Console';\nimport {\n getAgentsByType,\n getAgentByTypeAndId as _getAgentByTypeAndId,\n putAgentByTypeAndId,\n findAgentById,\n deleteAgentByTypeAndId,\n findAgentByTypeAndId,\n} from '../api/AgentApi';\nimport { AgentSkeleton } from '../api/ApiTypes';\nimport { AgentExportInterface } from './OpsTypes';\nimport { validateImport } from './utils/ExportImportUtils';\nimport State from '../shared/State';\n\nexport const AGENT_TYPE_IG = 'IdentityGatewayAgent';\nexport const AGENT_TYPE_JAVA = 'J2EEAgent';\nexport const AGENT_TYPE_WEB = 'WebAgent';\n\nexport default class AgentOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Create an empty agent export template\n * @returns {AgentExportInterface} an empty agent export template\n */\n createAgentExportTemplate(): AgentExportInterface {\n return createAgentExportTemplate();\n }\n\n /**\n * Get all agents. Results are sorted aphabetically.\n * @returns {Promise<TreeSkeleton[]>} a promise that resolves to an array of agent objects\n */\n async getAgents(): Promise<AgentSkeleton[]> {\n return getAgents({ state: this.state });\n }\n\n /**\n * Get agent\n * @param {string} agentId agent id/name\n * @returns {Promise} a promise that resolves to an agent object\n */\n async getAgent(agentId: string) {\n return getAgent({ agentId, state: this.state });\n }\n\n /**\n * Get agent by type and id\n * @param {string} agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)\n * @param {string} agentId agent id/name\n * @returns {Promise} a promise that resolves to an agent object\n */\n async getAgentByTypeAndId(agentType: string, agentId: string) {\n return getAgentByTypeAndId({ agentType, agentId, state: this.state });\n }\n\n /**\n * Get identity gateway agents\n * @returns {Promise} a promise that resolves to an array of IdentityGatewayAgent objects\n */\n async getIdentityGatewayAgents() {\n return getIdentityGatewayAgents({ state: this.state });\n }\n\n /**\n * Get identity gateway agent\n * @param {string} gatewayId gateway id\n * @returns {Promise} a promise that resolves to an object containing an IdentityGatewayAgent object\n */\n async getIdentityGatewayAgent(gatewayId: string) {\n return getIdentityGatewayAgent({ gatewayId, state: this.state });\n }\n\n /**\n * Put identity gateway agent\n * @param {string} gatewayId gateway id\n * @param {Object} gatewayData IdentityGatewayAgent object\n * @returns {Promise} a promise that resolves to an object containing an IdentityGatewayAgent object\n */\n async putIdentityGatewayAgent(gatewayId: string, gatewayData: AgentSkeleton) {\n return putIdentityGatewayAgent({\n gatewayId,\n gatewayData,\n state: this.state,\n });\n }\n\n /**\n * Get java agents\n * @returns {Promise} a promise that resolves to an array of J2EEAgent objects\n */\n async getJavaAgents() {\n return getJavaAgents({ state: this.state });\n }\n\n /**\n * Get java agent\n * @param {string} agentId java agent id\n * @returns {Promise} a promise that resolves to an object containing an J2EEAgent object\n */\n async getJavaAgent(agentId: string) {\n return getJavaAgent({ agentId, state: this.state });\n }\n\n /**\n * Put java agent\n * @param {string} agentId java agent id\n * @param {Object} agentData java agent object\n * @returns {Promise} a promise that resolves to an object containing an java agent object\n */\n async putJavaAgent(agentId: string, agentData: AgentSkeleton) {\n return putJavaAgent({ agentId, agentData, state: this.state });\n }\n\n /**\n * Get web agents\n * @returns {Promise} a promise that resolves to an array of WebAgent objects\n */\n async getWebAgents() {\n return getWebAgents({ state: this.state });\n }\n\n /**\n * Get web agent\n * @param {string} agentId web agent id\n * @returns {Promise} a promise that resolves to an object containing an WebAgent object\n */\n async getWebAgent(agentId: string) {\n return getWebAgent({ agentId, state: this.state });\n }\n\n /**\n * Put web agent\n * @param {string} agentId web agent id\n * @param {Object} agentData WebAgent object\n * @returns {Promise} a promise that resolves to an object containing an WebAgent object\n */\n async putWebAgent(agentId: string, agentData: AgentSkeleton) {\n return putWebAgent({ agentId, agentData, state: this.state });\n }\n\n /**\n * Export all agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface>} Promise resolving to an AgentExportInterface object.\n */\n async exportAgents(): Promise<AgentExportInterface> {\n return exportAgents({ state: this.state });\n }\n\n /**\n * Export all identity gateway agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportIdentityGatewayAgents(): Promise<AgentExportInterface> {\n return exportIdentityGatewayAgents({ state: this.state });\n }\n\n /**\n * Export all java agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportJavaAgents(): Promise<AgentExportInterface> {\n return exportJavaAgents({ state: this.state });\n }\n\n /**\n * Export all web agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportWebAgents(): Promise<AgentExportInterface> {\n return exportWebAgents({ state: this.state });\n }\n\n /**\n * Export agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportAgent(agentId: string): Promise<AgentExportInterface> {\n return exportAgent({ agentId, state: this.state });\n }\n\n /**\n * Export identity gateway agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportIdentityGatewayAgent(\n agentId: string\n ): Promise<AgentExportInterface> {\n return exportIdentityGatewayAgent({ agentId, state: this.state });\n }\n\n /**\n * Export java agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportJavaAgent(agentId: string): Promise<AgentExportInterface> {\n return exportJavaAgent({ agentId, state: this.state });\n }\n\n /**\n * Export web agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportWebAgent(agentId: string): Promise<AgentExportInterface> {\n return exportWebAgent({ agentId, state: this.state });\n }\n\n /**\n * Import agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\n async importAgents(importData: AgentExportInterface): Promise<void> {\n return importAgents({ importData, state: this.state });\n }\n\n /**\n * Import identity gateway agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\n async importIdentityGatewayAgents(\n importData: AgentExportInterface\n ): Promise<void> {\n return importIdentityGatewayAgents({ importData, state: this.state });\n }\n\n /**\n * Import java agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\n async importJavaAgents(importData: AgentExportInterface): Promise<void> {\n return importJavaAgents({ importData, state: this.state });\n }\n\n /**\n * Import web agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\n async importWebAgents(importData: AgentExportInterface): Promise<void> {\n return importWebAgents({ importData, state: this.state });\n }\n\n /**\n * Import agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\n async importAgent(agentId: string, importData: AgentExportInterface) {\n return importAgent({ agentId, importData, state: this.state });\n }\n\n /**\n * Import identity gateway agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\n async importIdentityGatewayAgent(\n agentId: string,\n importData: AgentExportInterface\n ) {\n return importIdentityGatewayAgent({\n agentId,\n importData,\n state: this.state,\n });\n }\n\n /**\n * Import java agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\n async importJavaAgent(agentId: string, importData: AgentExportInterface) {\n return importJavaAgent({ agentId, importData, state: this.state });\n }\n\n /**\n * Import java agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\n async importWebAgent(agentId: string, importData: AgentExportInterface) {\n return importWebAgent({ agentId, importData, state: this.state });\n }\n\n /**\n * Delete all agents\n */\n async deleteAgents() {\n return deleteAgents({ state: this.state });\n }\n\n /**\n * Delete agent\n * @param agentId agent id/name\n */\n async deleteAgent(agentId: string) {\n return deleteAgent({ agentId, state: this.state });\n }\n\n /**\n * Delete all identity gateway agents\n */\n async deleteIdentityGatewayAgents() {\n return deleteIdentityGatewayAgents({ state: this.state });\n }\n\n /**\n * Delete identity gateway agent\n * @param agentId agent id/name\n */\n async deleteIdentityGatewayAgent(agentId: string) {\n return deleteIdentityGatewayAgent({ agentId, state: this.state });\n }\n\n /**\n * Delete all java agents\n */\n async deleteJavaAgents() {\n return deleteJavaAgents({ state: this.state });\n }\n\n /**\n * Delete java agent\n * @param agentId agent id/name\n */\n async deleteJavaAgent(agentId: string) {\n return deleteJavaAgent({ agentId, state: this.state });\n }\n\n /**\n * Delete all web agents\n */\n async deleteWebAgents() {\n return deleteWebAgents({ state: this.state });\n }\n\n /**\n * Delete web agent\n * @param agentId agent id/name\n */\n async deleteWebAgent(agentId: string) {\n return deleteWebAgent({ agentId, state: this.state });\n }\n}\n\n/**\n * Create an empty agent export template\n * @returns {AgentExportInterface} an empty agent export template\n */\nexport function createAgentExportTemplate(): AgentExportInterface {\n return {\n meta: {},\n agents: {},\n } as AgentExportInterface;\n}\n\n/**\n * Get all agents. Results are sorted aphabetically.\n * @returns {Promise<TreeSkeleton[]>} a promise that resolves to an array of agent objects\n */\nexport async function getAgents({\n state,\n}: {\n state: State;\n}): Promise<AgentSkeleton[]> {\n debugMessage(`AgentOps.getAgents: start`);\n let agents = [];\n try {\n const resolved = await Promise.all([\n getAgentsByType({ agentType: 'IdentityGatewayAgent', state }),\n getAgentsByType({ agentType: 'J2EEAgent', state }),\n getAgentsByType({ agentType: 'WebAgent', state }),\n ]);\n agents = agents.concat(resolved[0].result);\n agents = agents.concat(resolved[1].result);\n agents = agents.concat(resolved[2].result);\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n printMessage(error.response.data, 'error');\n }\n agents.sort((a, b) => a._id.localeCompare(b._id));\n debugMessage(`AgentOps.getAgents: end`);\n return agents;\n}\n\n/**\n * Get agent\n * @param {string} agentId agent id/name\n * @returns {Promise} a promise that resolves to an agent object\n */\nexport async function getAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage(`AgentOps.getAgent: start`);\n const agents = await findAgentById({ agentId, state });\n if (agents.length === 1) {\n const result = await _getAgentByTypeAndId({\n agentType: agents[0]._type,\n agentId: agents[0]._id,\n state,\n });\n debugMessage(`AgentOps.getAgent: end`);\n return result;\n } else if (agents.length === 0) {\n throw new Error(`Agent '${agentId}' not found`);\n } else {\n throw new Error(`${agents.length} agents '${agentId}' found`);\n }\n}\n\n/**\n * Get agent by type and id\n * @param {string} agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)\n * @param {string} agentId agent id/name\n * @returns {Promise} a promise that resolves to an agent object\n */\nexport async function getAgentByTypeAndId({\n agentType,\n agentId,\n state,\n}: {\n agentType: string;\n agentId: string;\n state: State;\n}) {\n debugMessage(`AgentOps.getAgentByTypeAndId: start`);\n const result = await _getAgentByTypeAndId({ agentType, agentId, state });\n debugMessage(`AgentOps.getAgentByTypeAndId: start`);\n return result;\n}\n\n/**\n * Get identity gateway agents\n * @returns {Promise} a promise that resolves to an array of IdentityGatewayAgent objects\n */\nexport async function getIdentityGatewayAgents({ state }: { state: State }) {\n debugMessage(`AgentOps.getIdentityGatewayAgents: start`);\n const { result } = await getAgentsByType({ agentType: AGENT_TYPE_IG, state });\n debugMessage(`AgentOps.getIdentityGatewayAgents: end`);\n return result;\n}\n\n/**\n * Get identity gateway agent\n * @param {string} gatewayId gateway id\n * @returns {Promise} a promise that resolves to an object containing an IdentityGatewayAgent object\n */\nexport async function getIdentityGatewayAgent({\n gatewayId,\n state,\n}: {\n gatewayId: string;\n state: State;\n}) {\n debugMessage(`AgentOps.getIdentityGatewayAgent: start`);\n const result = await getAgentByTypeAndId({\n agentType: AGENT_TYPE_IG,\n agentId: gatewayId,\n state,\n });\n debugMessage(`AgentOps.getIdentityGatewayAgent: end`);\n return result;\n}\n\n/**\n * Put identity gateway agent\n * @param {string} gatewayId gateway id\n * @param {Object} gatewayData IdentityGatewayAgent object\n * @returns {Promise} a promise that resolves to an object containing an IdentityGatewayAgent object\n */\nexport async function putIdentityGatewayAgent({\n gatewayId,\n gatewayData,\n state,\n}: {\n gatewayId: string;\n gatewayData: AgentSkeleton;\n state: State;\n}) {\n debugMessage(`AgentOps.putIdentityGatewayAgent: start`);\n const result = await putAgentByTypeAndId({\n agentType: AGENT_TYPE_IG,\n agentId: gatewayId,\n agentData: gatewayData,\n state,\n });\n debugMessage(`AgentOps.putIdentityGatewayAgent: end`);\n return result;\n}\n\n/**\n * Get java agents\n * @returns {Promise} a promise that resolves to an array of J2EEAgent objects\n */\nexport async function getJavaAgents({ state }: { state: State }) {\n debugMessage(`AgentOps.getJavaAgents: start`);\n const { result } = await getAgentsByType({\n agentType: AGENT_TYPE_JAVA,\n state,\n });\n debugMessage(`AgentOps.getJavaAgents: end`);\n return result;\n}\n\n/**\n * Get java agent\n * @param {string} agentId java agent id\n * @returns {Promise} a promise that resolves to an object containing an J2EEAgent object\n */\nexport async function getJavaAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage(`AgentOps.getJavaAgent: start`);\n const result = await getAgentByTypeAndId({\n agentType: AGENT_TYPE_JAVA,\n agentId,\n state,\n });\n debugMessage(`AgentOps.getJavaAgent: end`);\n return result;\n}\n\n/**\n * Put java agent\n * @param {string} agentId java agent id\n * @param {Object} agentData java agent object\n * @returns {Promise} a promise that resolves to an object containing an java agent object\n */\nexport async function putJavaAgent({\n agentId,\n agentData,\n state,\n}: {\n agentId: string;\n agentData: AgentSkeleton;\n state: State;\n}) {\n debugMessage(`AgentOps.putJavaAgent: start`);\n const result = await putAgentByTypeAndId({\n agentType: AGENT_TYPE_JAVA,\n agentId,\n agentData,\n state,\n });\n debugMessage(`AgentOps.putJavaAgent: end`);\n return result;\n}\n\n/**\n * Get web agents\n * @returns {Promise} a promise that resolves to an array of WebAgent objects\n */\nexport async function getWebAgents({ state }: { state: State }) {\n debugMessage(`AgentOps.getWebAgents: start`);\n const { result } = await getAgentsByType({\n agentType: AGENT_TYPE_WEB,\n state,\n });\n debugMessage(`AgentOps.getWebAgents: end`);\n return result;\n}\n\n/**\n * Get web agent\n * @param {string} agentId web agent id\n * @returns {Promise} a promise that resolves to an object containing an WebAgent object\n */\nexport async function getWebAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage(`AgentOps.getWebAgent: start`);\n const result = await getAgentByTypeAndId({\n agentType: AGENT_TYPE_WEB,\n agentId,\n state,\n });\n debugMessage(`AgentOps.getWebAgent: end`);\n return result;\n}\n\n/**\n * Put web agent\n * @param {string} agentId web agent id\n * @param {Object} agentData WebAgent object\n * @returns {Promise} a promise that resolves to an object containing an WebAgent object\n */\nexport async function putWebAgent({\n agentId,\n agentData,\n state,\n}: {\n agentId: string;\n agentData: AgentSkeleton;\n state: State;\n}) {\n debugMessage(`AgentOps.putWebAgent: start`);\n const result = await putAgentByTypeAndId({\n agentType: AGENT_TYPE_WEB,\n agentId,\n agentData,\n state,\n });\n debugMessage(`AgentOps.putWebAgent: end`);\n return result;\n}\n\n/**\n * Export all agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface>} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportAgents({\n state,\n}: {\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage(`AgentOps.exportAgents: start`);\n const exportData = createAgentExportTemplate();\n const agents = await getAgents({ state });\n for (const agent of agents) {\n exportData.agents[agent._id] = agent;\n }\n debugMessage(`AgentOps.exportAgents: end`);\n return exportData;\n}\n\n/**\n * Export all identity gateway agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportIdentityGatewayAgents({\n state,\n}: {\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage(`AgentOps.exportIdentityGatewayAgents: start`);\n const exportData = createAgentExportTemplate();\n const agents = await getIdentityGatewayAgents({ state });\n for (const agent of agents) {\n exportData.agents[agent._id] = agent;\n }\n debugMessage(`AgentOps.exportIdentityGatewayAgents: end`);\n return exportData;\n}\n\n/**\n * Export all java agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportJavaAgents({\n state,\n}: {\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage(`AgentOps.exportJavaAgents: start`);\n const exportData = createAgentExportTemplate();\n const agents = await getJavaAgents({ state });\n for (const agent of agents) {\n exportData.agents[agent._id] = agent;\n }\n debugMessage(`AgentOps.exportJavaAgents: end`);\n return exportData;\n}\n\n/**\n * Export all web agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportWebAgents({\n state,\n}: {\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage(`AgentOps.exportWebAgents: start`);\n const exportData = createAgentExportTemplate();\n const agents = await getWebAgents({ state });\n for (const agent of agents) {\n exportData.agents[agent._id] = agent;\n }\n debugMessage(`AgentOps.exportWebAgents: end`);\n return exportData;\n}\n\n/**\n * Export agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage(`AgentOps.exportAgent: start`);\n const exportData = createAgentExportTemplate();\n const agentObject = await getAgent({ agentId, state });\n exportData.agents[agentId] = agentObject;\n debugMessage(`AgentOps.exportAgent: end`);\n return exportData;\n}\n\n/**\n * Export identity gateway agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportIdentityGatewayAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage(`AgentOps.exportIdentityGatewayAgent: start`);\n const exportData = createAgentExportTemplate();\n const agentObject = await getIdentityGatewayAgent({\n gatewayId: agentId,\n state,\n });\n exportData.agents[agentId] = agentObject;\n debugMessage(`AgentOps.exportIdentityGatewayAgent: end`);\n return exportData;\n}\n\n/**\n * Export java agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportJavaAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage(`AgentOps.exportJavaAgent: start`);\n const exportData = createAgentExportTemplate();\n const agentObject = await getJavaAgent({ agentId, state });\n exportData.agents[agentId] = agentObject;\n debugMessage(`AgentOps.exportJavaAgent: end`);\n return exportData;\n}\n\n/**\n * Export web agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportWebAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage(`AgentOps.exportWebAgent: start`);\n const exportData = createAgentExportTemplate();\n const agentObject = await getWebAgent({ agentId, state });\n exportData.agents[agentId] = agentObject;\n debugMessage(`AgentOps.exportWebAgent: end`);\n return exportData;\n}\n\n/**\n * Import agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\nexport async function importAgents({\n importData,\n state,\n}: {\n importData: AgentExportInterface;\n state: State;\n}): Promise<void> {\n debugMessage(`AgentOps.importAgents: start`);\n if (validateImport(importData.meta)) {\n for (const agentId of Object.keys(importData.agents)) {\n const agentType = importData.agents[agentId]._type._id;\n debugMessage(`AgentOps.importAgents: ${agentId} [${agentType}]`);\n await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n }\n } else {\n throw new Error('Invalid meta data.');\n }\n debugMessage(`AgentOps.importAgents: end`);\n}\n\n/**\n * Import identity gateway agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\nexport async function importIdentityGatewayAgents({\n importData,\n state,\n}: {\n importData: AgentExportInterface;\n state: State;\n}): Promise<void> {\n debugMessage(`AgentOps.importIdentityGatewayAgents: start`);\n if (validateImport(importData.meta)) {\n for (const agentId of Object.keys(importData.agents)) {\n const agentType = importData.agents[agentId]._type._id;\n if (agentType !== AGENT_TYPE_IG)\n throw new Error(\n `Wrong agent type! Expected '${AGENT_TYPE_IG}' but got '${agentType}'.`\n );\n await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n }\n } else {\n throw new Error('Invalid meta data.');\n }\n debugMessage(`AgentOps.importIdentityGatewayAgents: end`);\n}\n\n/**\n * Import java agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\nexport async function importJavaAgents({\n importData,\n state,\n}: {\n importData: AgentExportInterface;\n state: State;\n}): Promise<void> {\n debugMessage(`AgentOps.importJavaAgents: start`);\n if (validateImport(importData.meta)) {\n for (const agentId of Object.keys(importData.agents)) {\n const agentType = importData.agents[agentId]._type._id;\n if (agentType !== AGENT_TYPE_JAVA)\n throw new Error(\n `Wrong agent type! Expected '${AGENT_TYPE_JAVA}' but got '${agentType}'.`\n );\n await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n }\n } else {\n throw new Error('Invalid meta data.');\n }\n debugMessage(`AgentOps.importJavaAgents: end`);\n}\n\n/**\n * Import web agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\nexport async function importWebAgents({\n importData,\n state,\n}: {\n importData: AgentExportInterface;\n state: State;\n}): Promise<void> {\n debugMessage(`AgentOps.importWebAgents: start`);\n if (validateImport(importData.meta)) {\n for (const agentId of Object.keys(importData.agents)) {\n const agentType = importData.agents[agentId]._type._id;\n if (agentType !== AGENT_TYPE_WEB)\n throw new Error(\n `Wrong agent type! Expected '${AGENT_TYPE_WEB}' but got '${agentType}'.`\n );\n await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n }\n } else {\n throw new Error('Invalid meta data.');\n }\n debugMessage(`AgentOps.importWebAgents: end`);\n}\n\n/**\n * Import agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\nexport async function importAgent({\n agentId,\n importData,\n state,\n}: {\n agentId: string;\n importData: AgentExportInterface;\n state: State;\n}) {\n debugMessage(`AgentOps.importAgent: start`);\n if (validateImport(importData.meta)) {\n const agentType = importData.agents[agentId]?._type._id;\n const result = await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n debugMessage(`AgentOps.importAgent: end`);\n return result;\n } else {\n throw new Error('Invalid meta data.');\n }\n}\n\n/**\n * Import identity gateway agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\nexport async function importIdentityGatewayAgent({\n agentId,\n importData,\n state,\n}: {\n agentId: string;\n importData: AgentExportInterface;\n state: State;\n}) {\n debugMessage(`AgentOps.importIdentityGatewayAgent: start`);\n if (validateImport(importData.meta)) {\n const agentType = importData.agents[agentId]?._type._id;\n if (agentType !== AGENT_TYPE_IG)\n throw new Error(\n `Wrong agent type! Expected '${AGENT_TYPE_IG}' but got '${agentType}'.`\n );\n const result = await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n debugMessage(`AgentOps.importIdentityGatewayAgent: end`);\n return result;\n } else {\n throw new Error('Invalid meta data.');\n }\n}\n\n/**\n * Import java agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\nexport async function importJavaAgent({\n agentId,\n importData,\n state,\n}: {\n agentId: string;\n importData: AgentExportInterface;\n state: State;\n}) {\n debugMessage(`AgentOps.importJavaAgent: start`);\n if (validateImport(importData.meta)) {\n const agentType = importData.agents[agentId]?._type._id;\n if (agentType !== AGENT_TYPE_JAVA)\n throw new Error(\n `Wrong agent type! Expected '${AGENT_TYPE_JAVA}' but got '${agentType}'.`\n );\n const result = await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n debugMessage(`AgentOps.importJavaAgent: end`);\n return result;\n } else {\n throw new Error('Invalid meta data.');\n }\n}\n\n/**\n * Import java agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\nexport async function importWebAgent({\n agentId,\n importData,\n state,\n}: {\n agentId: string;\n importData: AgentExportInterface;\n state: State;\n}) {\n debugMessage(`AgentOps.importWebAgent: start`);\n if (validateImport(importData.meta)) {\n const agentType = importData.agents[agentId]?._type._id;\n if (agentType !== AGENT_TYPE_WEB)\n throw new Error(\n `Wrong agent type! Expected '${AGENT_TYPE_WEB}' but got '${agentType}'.`\n );\n const result = await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n debugMessage(`AgentOps.importWebAgent: end`);\n return result;\n } else {\n throw new Error('Invalid meta data.');\n }\n}\n\n/**\n * Delete all agents\n */\nexport async function deleteAgents({ state }: { state: State }) {\n debugMessage(`AgentOps.deleteAgents: start`);\n const agents = await getAgents({ state });\n for (const agent of agents) {\n debugMessage(`AgentOps.deleteAgent: '${agent['_id']}'`);\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n debugMessage(`AgentOps.deleteAgents: end`);\n}\n\n/**\n * Delete agent\n * @param agentId agent id/name\n */\nexport async function deleteAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage(`AgentOps.deleteAgent: start`);\n const agents = await findAgentById({ agentId, state });\n if (agents.length) {\n for (const agent of agents) {\n debugMessage(`AgentOps.deleteAgent: '${agent['_id']}'`);\n await deleteAgentByTypeAndId({\n agentType: agent['_type'],\n agentId: agent['_id'],\n state,\n });\n }\n } else {\n throw new Error(`Agent '${agentId}' not found!`);\n }\n debugMessage(`AgentOps.deleteAgent: end`);\n}\n\n/**\n * Delete all identity gateway agents\n */\nexport async function deleteIdentityGatewayAgents({ state }: { state: State }) {\n debugMessage(`AgentOps.deleteIdentityGatewayAgents: start`);\n const agents = await getIdentityGatewayAgents({ state });\n for (const agent of agents) {\n debugMessage(`AgentOps.deleteIdentityGatewayAgent: '${agent['_id']}'`);\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n debugMessage(`AgentOps.deleteIdentityGatewayAgents: end`);\n}\n\n/**\n * Delete identity gateway agent\n * @param agentId agent id/name\n */\nexport async function deleteIdentityGatewayAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage(`AgentOps.deleteIdentityGatewayAgent: start`);\n const agents = await findAgentByTypeAndId({\n agentType: AGENT_TYPE_IG,\n agentId,\n state,\n });\n if (agents.length) {\n for (const agent of agents) {\n debugMessage(`AgentOps.deleteIdentityGatewayAgent: '${agent['_id']}'`);\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n } else {\n throw new Error(`Identity gateway agent '${agentId}' not found!`);\n }\n debugMessage(`AgentOps.deleteIdentityGatewayAgent: end`);\n}\n\n/**\n * Delete all java agents\n */\nexport async function deleteJavaAgents({ state }: { state: State }) {\n debugMessage(`AgentOps.deleteJavaAgents: start`);\n const agents = await getJavaAgents({ state });\n for (const agent of agents) {\n debugMessage(`AgentOps.deleteJavaAgent: '${agent['_id']}'`);\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n debugMessage(`AgentOps.deleteJavaAgents: end`);\n}\n\n/**\n * Delete java agent\n * @param agentId agent id/name\n */\nexport async function deleteJavaAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage(`AgentOps.deleteJavaAgent: start`);\n const agents = await findAgentByTypeAndId({\n agentType: AGENT_TYPE_JAVA,\n agentId,\n state,\n });\n if (agents.length) {\n for (const agent of agents) {\n debugMessage(`AgentOps.deleteJavaAgent: '${agent['_id']}'`);\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n } else {\n throw new Error(`Java agent '${agentId}' not found!`);\n }\n debugMessage(`AgentOps.deleteJavaAgent: end`);\n}\n\n/**\n * Delete all web agents\n */\nexport async function deleteWebAgents({ state }: { state: State }) {\n debugMessage(`AgentOps.deleteWebAgents: start`);\n const agents = await getWebAgents({ state });\n for (const agent of agents) {\n debugMessage(`AgentOps.deleteWebAgent: '${agent['_id']}'`);\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n debugMessage(`AgentOps.deleteWebAgents: end`);\n}\n\n/**\n * Delete web agent\n * @param agentId agent id/name\n */\nexport async function deleteWebAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage(`AgentOps.deleteWebAgent: start`);\n const agents = await findAgentByTypeAndId({\n agentType: AGENT_TYPE_WEB,\n agentId,\n state,\n });\n if (agents.length) {\n for (const agent of agents) {\n debugMessage(`AgentOps.deleteWebAgent: '${agent['_id']}'`);\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n } else {\n throw new Error(`Web agent '${agentId}' not found!`);\n }\n debugMessage(`AgentOps.deleteWebAgent: end`);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ops/AgentOps.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACH,yBAAyB,IAAI,oBAAoB;IAIjD;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAI3C;;;;OAIG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM;IAI9B;;;;;OAKG;IACG,mBAAmB,CAAC,SAAS,EAAE,SAAS,EAAE,OA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H,wBAAsB,eAAe,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,iBAehE;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,KAAK,GACN,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;CACd,iBAuBA","file":"AgentOps.d.ts","sourcesContent":["import { debugMessage, printMessage } from './utils/Console';\nimport {\n getAgentsByType,\n getAgentByTypeAndId as _getAgentByTypeAndId,\n putAgentByTypeAndId,\n findAgentById,\n deleteAgentByTypeAndId,\n findAgentByTypeAndId,\n} from '../api/AgentApi';\nimport { AgentSkeleton, AgentType } from '../api/ApiTypes';\nimport { AgentExportInterface } from './OpsTypes';\nimport { validateImport } from './utils/ExportImportUtils';\nimport State from '../shared/State';\n\nexport default class AgentOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Create an empty agent export template\n * @returns {AgentExportInterface} an empty agent export template\n */\n createAgentExportTemplate(): AgentExportInterface {\n return createAgentExportTemplate();\n }\n\n /**\n * Get all agents. Results are sorted aphabetically.\n * @returns {Promise<TreeSkeleton[]>} a promise that resolves to an array of agent objects\n */\n async getAgents(): Promise<AgentSkeleton[]> {\n return getAgents({ state: this.state });\n }\n\n /**\n * Get agent\n * @param {string} agentId agent id/name\n * @returns {Promise} a promise that resolves to an agent object\n */\n async getAgent(agentId: string) {\n return getAgent({ agentId, state: this.state });\n }\n\n /**\n * Get agent by type and id\n * @param {string} agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)\n * @param {string} agentId agent id/name\n * @returns {Promise} a promise that resolves to an agent object\n */\n async getAgentByTypeAndId(agentType: AgentType, agentId: string) {\n return getAgentByTypeAndId({ agentType, agentId, state: this.state });\n }\n\n /**\n * Get identity gateway agents\n * @returns {Promise} a promise that resolves to an array of IdentityGatewayAgent objects\n */\n async getIdentityGatewayAgents() {\n return getIdentityGatewayAgents({ state: this.state });\n }\n\n /**\n * Get identity gateway agent\n * @param {string} gatewayId gateway id\n * @returns {Promise} a promise that resolves to an object containing an IdentityGatewayAgent object\n */\n async getIdentityGatewayAgent(gatewayId: string) {\n return getIdentityGatewayAgent({ gatewayId, state: this.state });\n }\n\n /**\n * Put identity gateway agent\n * @param {string} gatewayId gateway id\n * @param {Object} gatewayData IdentityGatewayAgent object\n * @returns {Promise} a promise that resolves to an object containing an IdentityGatewayAgent object\n */\n async putIdentityGatewayAgent(gatewayId: string, gatewayData: AgentSkeleton) {\n return putIdentityGatewayAgent({\n gatewayId,\n gatewayData,\n state: this.state,\n });\n }\n\n /**\n * Get java agents\n * @returns {Promise} a promise that resolves to an array of J2EEAgent objects\n */\n async getJavaAgents() {\n return getJavaAgents({ state: this.state });\n }\n\n /**\n * Get java agent\n * @param {string} agentId java agent id\n * @returns {Promise} a promise that resolves to an object containing an J2EEAgent object\n */\n async getJavaAgent(agentId: string) {\n return getJavaAgent({ agentId, state: this.state });\n }\n\n /**\n * Put java agent\n * @param {string} agentId java agent id\n * @param {Object} agentData java agent object\n * @returns {Promise} a promise that resolves to an object containing an java agent object\n */\n async putJavaAgent(agentId: string, agentData: AgentSkeleton) {\n return putJavaAgent({ agentId, agentData, state: this.state });\n }\n\n /**\n * Get web agents\n * @returns {Promise} a promise that resolves to an array of WebAgent objects\n */\n async getWebAgents() {\n return getWebAgents({ state: this.state });\n }\n\n /**\n * Get web agent\n * @param {string} agentId web agent id\n * @returns {Promise} a promise that resolves to an object containing an WebAgent object\n */\n async getWebAgent(agentId: string) {\n return getWebAgent({ agentId, state: this.state });\n }\n\n /**\n * Put web agent\n * @param {string} agentId web agent id\n * @param {Object} agentData WebAgent object\n * @returns {Promise} a promise that resolves to an object containing an WebAgent object\n */\n async putWebAgent(agentId: string, agentData: AgentSkeleton) {\n return putWebAgent({ agentId, agentData, state: this.state });\n }\n\n /**\n * Export all agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface>} Promise resolving to an AgentExportInterface object.\n */\n async exportAgents(): Promise<AgentExportInterface> {\n return exportAgents({ state: this.state });\n }\n\n /**\n * Export all identity gateway agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportIdentityGatewayAgents(): Promise<AgentExportInterface> {\n return exportIdentityGatewayAgents({ state: this.state });\n }\n\n /**\n * Export all java agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportJavaAgents(): Promise<AgentExportInterface> {\n return exportJavaAgents({ state: this.state });\n }\n\n /**\n * Export all web agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportWebAgents(): Promise<AgentExportInterface> {\n return exportWebAgents({ state: this.state });\n }\n\n /**\n * Export agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportAgent(agentId: string): Promise<AgentExportInterface> {\n return exportAgent({ agentId, state: this.state });\n }\n\n /**\n * Export identity gateway agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportIdentityGatewayAgent(\n agentId: string\n ): Promise<AgentExportInterface> {\n return exportIdentityGatewayAgent({ agentId, state: this.state });\n }\n\n /**\n * Export java agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportJavaAgent(agentId: string): Promise<AgentExportInterface> {\n return exportJavaAgent({ agentId, state: this.state });\n }\n\n /**\n * Export web agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\n async exportWebAgent(agentId: string): Promise<AgentExportInterface> {\n return exportWebAgent({ agentId, state: this.state });\n }\n\n /**\n * Import agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\n async importAgents(importData: AgentExportInterface): Promise<void> {\n return importAgents({ importData, state: this.state });\n }\n\n /**\n * Import identity gateway agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\n async importIdentityGatewayAgents(\n importData: AgentExportInterface\n ): Promise<void> {\n return importIdentityGatewayAgents({ importData, state: this.state });\n }\n\n /**\n * Import java agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\n async importJavaAgents(importData: AgentExportInterface): Promise<void> {\n return importJavaAgents({ importData, state: this.state });\n }\n\n /**\n * Import web agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\n async importWebAgents(importData: AgentExportInterface): Promise<void> {\n return importWebAgents({ importData, state: this.state });\n }\n\n /**\n * Import agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\n async importAgent(agentId: string, importData: AgentExportInterface) {\n return importAgent({ agentId, importData, state: this.state });\n }\n\n /**\n * Import identity gateway agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\n async importIdentityGatewayAgent(\n agentId: string,\n importData: AgentExportInterface\n ) {\n return importIdentityGatewayAgent({\n agentId,\n importData,\n state: this.state,\n });\n }\n\n /**\n * Import java agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\n async importJavaAgent(agentId: string, importData: AgentExportInterface) {\n return importJavaAgent({ agentId, importData, state: this.state });\n }\n\n /**\n * Import java agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\n async importWebAgent(agentId: string, importData: AgentExportInterface) {\n return importWebAgent({ agentId, importData, state: this.state });\n }\n\n /**\n * Delete all agents\n */\n async deleteAgents() {\n return deleteAgents({ state: this.state });\n }\n\n /**\n * Delete agent\n * @param agentId agent id/name\n */\n async deleteAgent(agentId: string) {\n return deleteAgent({ agentId, state: this.state });\n }\n\n /**\n * Delete all identity gateway agents\n */\n async deleteIdentityGatewayAgents() {\n return deleteIdentityGatewayAgents({ state: this.state });\n }\n\n /**\n * Delete identity gateway agent\n * @param agentId agent id/name\n */\n async deleteIdentityGatewayAgent(agentId: string) {\n return deleteIdentityGatewayAgent({ agentId, state: this.state });\n }\n\n /**\n * Delete all java agents\n */\n async deleteJavaAgents() {\n return deleteJavaAgents({ state: this.state });\n }\n\n /**\n * Delete java agent\n * @param agentId agent id/name\n */\n async deleteJavaAgent(agentId: string) {\n return deleteJavaAgent({ agentId, state: this.state });\n }\n\n /**\n * Delete all web agents\n */\n async deleteWebAgents() {\n return deleteWebAgents({ state: this.state });\n }\n\n /**\n * Delete web agent\n * @param agentId agent id/name\n */\n async deleteWebAgent(agentId: string) {\n return deleteWebAgent({ agentId, state: this.state });\n }\n}\n\n/**\n * Create an empty agent export template\n * @returns {AgentExportInterface} an empty agent export template\n */\nexport function createAgentExportTemplate(): AgentExportInterface {\n return {\n meta: {},\n agents: {},\n } as AgentExportInterface;\n}\n\n/**\n * Get all agents. Results are sorted aphabetically.\n * @returns {Promise<TreeSkeleton[]>} a promise that resolves to an array of agent objects\n */\nexport async function getAgents({\n state,\n}: {\n state: State;\n}): Promise<AgentSkeleton[]> {\n debugMessage({ message: `AgentOps.getAgents: start`, state });\n let agents = [];\n try {\n const resolved = await Promise.all([\n getAgentsByType({ agentType: 'IdentityGatewayAgent', state }),\n getAgentsByType({ agentType: 'J2EEAgent', state }),\n getAgentsByType({ agentType: 'WebAgent', state }),\n ]);\n agents = agents.concat(resolved[0].result);\n agents = agents.concat(resolved[1].result);\n agents = agents.concat(resolved[2].result);\n } catch (error) {\n printMessage({ message: `${error.message}`, type: 'error', state });\n printMessage({ message: error.response.data, type: 'error', state });\n }\n agents.sort((a, b) => a._id.localeCompare(b._id));\n debugMessage({ message: `AgentOps.getAgents: end`, state });\n return agents;\n}\n\n/**\n * Get agent\n * @param {string} agentId agent id/name\n * @returns {Promise} a promise that resolves to an agent object\n */\nexport async function getAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.getAgent: start`, state });\n const agents = await findAgentById({ agentId, state });\n if (agents.length === 1) {\n const result = await _getAgentByTypeAndId({\n agentType: agents[0]._type,\n agentId: agents[0]._id,\n state,\n });\n debugMessage({ message: `AgentOps.getAgent: end`, state });\n return result;\n } else if (agents.length === 0) {\n throw new Error(`Agent '${agentId}' not found`);\n } else {\n throw new Error(`${agents.length} agents '${agentId}' found`);\n }\n}\n\n/**\n * Get agent by type and id\n * @param {string} agentType agent type (IdentityGatewayAgent, J2EEAgent, WebAgent)\n * @param {string} agentId agent id/name\n * @returns {Promise} a promise that resolves to an agent object\n */\nexport async function getAgentByTypeAndId({\n agentType,\n agentId,\n state,\n}: {\n agentType: AgentType;\n agentId: string;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.getAgentByTypeAndId: start`, state });\n const result = await _getAgentByTypeAndId({ agentType, agentId, state });\n debugMessage({ message: `AgentOps.getAgentByTypeAndId: start`, state });\n return result;\n}\n\n/**\n * Get identity gateway agents\n * @returns {Promise} a promise that resolves to an array of IdentityGatewayAgent objects\n */\nexport async function getIdentityGatewayAgents({ state }: { state: State }) {\n debugMessage({ message: `AgentOps.getIdentityGatewayAgents: start`, state });\n const { result } = await getAgentsByType({\n agentType: 'IdentityGatewayAgent',\n state,\n });\n debugMessage({ message: `AgentOps.getIdentityGatewayAgents: end`, state });\n return result;\n}\n\n/**\n * Get identity gateway agent\n * @param {string} gatewayId gateway id\n * @returns {Promise} a promise that resolves to an object containing an IdentityGatewayAgent object\n */\nexport async function getIdentityGatewayAgent({\n gatewayId,\n state,\n}: {\n gatewayId: string;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.getIdentityGatewayAgent: start`, state });\n const result = await getAgentByTypeAndId({\n agentType: 'IdentityGatewayAgent',\n agentId: gatewayId,\n state,\n });\n debugMessage({ message: `AgentOps.getIdentityGatewayAgent: end`, state });\n return result;\n}\n\n/**\n * Put identity gateway agent\n * @param {string} gatewayId gateway id\n * @param {Object} gatewayData IdentityGatewayAgent object\n * @returns {Promise} a promise that resolves to an object containing an IdentityGatewayAgent object\n */\nexport async function putIdentityGatewayAgent({\n gatewayId,\n gatewayData,\n state,\n}: {\n gatewayId: string;\n gatewayData: AgentSkeleton;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.putIdentityGatewayAgent: start`, state });\n const result = await putAgentByTypeAndId({\n agentType: 'IdentityGatewayAgent',\n agentId: gatewayId,\n agentData: gatewayData,\n state,\n });\n debugMessage({ message: `AgentOps.putIdentityGatewayAgent: end`, state });\n return result;\n}\n\n/**\n * Get java agents\n * @returns {Promise} a promise that resolves to an array of J2EEAgent objects\n */\nexport async function getJavaAgents({ state }: { state: State }) {\n debugMessage({ message: `AgentOps.getJavaAgents: start`, state });\n const { result } = await getAgentsByType({\n agentType: 'J2EEAgent',\n state,\n });\n debugMessage({ message: `AgentOps.getJavaAgents: end`, state });\n return result;\n}\n\n/**\n * Get java agent\n * @param {string} agentId java agent id\n * @returns {Promise} a promise that resolves to an object containing an J2EEAgent object\n */\nexport async function getJavaAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.getJavaAgent: start`, state });\n const result = await getAgentByTypeAndId({\n agentType: 'J2EEAgent',\n agentId,\n state,\n });\n debugMessage({ message: `AgentOps.getJavaAgent: end`, state });\n return result;\n}\n\n/**\n * Put java agent\n * @param {string} agentId java agent id\n * @param {Object} agentData java agent object\n * @returns {Promise} a promise that resolves to an object containing an java agent object\n */\nexport async function putJavaAgent({\n agentId,\n agentData,\n state,\n}: {\n agentId: string;\n agentData: AgentSkeleton;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.putJavaAgent: start`, state });\n const result = await putAgentByTypeAndId({\n agentType: 'J2EEAgent',\n agentId,\n agentData,\n state,\n });\n debugMessage({ message: `AgentOps.putJavaAgent: end`, state });\n return result;\n}\n\n/**\n * Get web agents\n * @returns {Promise} a promise that resolves to an array of WebAgent objects\n */\nexport async function getWebAgents({ state }: { state: State }) {\n debugMessage({ message: `AgentOps.getWebAgents: start`, state });\n const { result } = await getAgentsByType({\n agentType: 'WebAgent',\n state,\n });\n debugMessage({ message: `AgentOps.getWebAgents: end`, state });\n return result;\n}\n\n/**\n * Get web agent\n * @param {string} agentId web agent id\n * @returns {Promise} a promise that resolves to an object containing an WebAgent object\n */\nexport async function getWebAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.getWebAgent: start`, state });\n const result = await getAgentByTypeAndId({\n agentType: 'WebAgent',\n agentId,\n state,\n });\n debugMessage({ message: `AgentOps.getWebAgent: end`, state });\n return result;\n}\n\n/**\n * Put web agent\n * @param {string} agentId web agent id\n * @param {Object} agentData WebAgent object\n * @returns {Promise} a promise that resolves to an object containing an WebAgent object\n */\nexport async function putWebAgent({\n agentId,\n agentData,\n state,\n}: {\n agentId: string;\n agentData: AgentSkeleton;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.putWebAgent: start`, state });\n const result = await putAgentByTypeAndId({\n agentType: 'WebAgent',\n agentId,\n agentData,\n state,\n });\n debugMessage({ message: `AgentOps.putWebAgent: end`, state });\n return result;\n}\n\n/**\n * Export all agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface>} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportAgents({\n state,\n}: {\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage({ message: `AgentOps.exportAgents: start`, state });\n const exportData = createAgentExportTemplate();\n const agents = await getAgents({ state });\n for (const agent of agents) {\n exportData.agents[agent._id] = agent;\n }\n debugMessage({ message: `AgentOps.exportAgents: end`, state });\n return exportData;\n}\n\n/**\n * Export all identity gateway agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportIdentityGatewayAgents({\n state,\n}: {\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage({\n message: `AgentOps.exportIdentityGatewayAgents: start`,\n state,\n });\n const exportData = createAgentExportTemplate();\n const agents = await getIdentityGatewayAgents({ state });\n for (const agent of agents) {\n exportData.agents[agent._id] = agent;\n }\n debugMessage({ message: `AgentOps.exportIdentityGatewayAgents: end`, state });\n return exportData;\n}\n\n/**\n * Export all java agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportJavaAgents({\n state,\n}: {\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage({ message: `AgentOps.exportJavaAgents: start`, state });\n const exportData = createAgentExportTemplate();\n const agents = await getJavaAgents({ state });\n for (const agent of agents) {\n exportData.agents[agent._id] = agent;\n }\n debugMessage({ message: `AgentOps.exportJavaAgents: end`, state });\n return exportData;\n}\n\n/**\n * Export all web agents. The response can be saved to file as is.\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportWebAgents({\n state,\n}: {\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage({ message: `AgentOps.exportWebAgents: start`, state });\n const exportData = createAgentExportTemplate();\n const agents = await getWebAgents({ state });\n for (const agent of agents) {\n exportData.agents[agent._id] = agent;\n }\n debugMessage({ message: `AgentOps.exportWebAgents: end`, state });\n return exportData;\n}\n\n/**\n * Export agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage({ message: `AgentOps.exportAgent: start`, state });\n const exportData = createAgentExportTemplate();\n const agentObject = await getAgent({ agentId, state });\n exportData.agents[agentId] = agentObject;\n debugMessage({ message: `AgentOps.exportAgent: end`, state });\n return exportData;\n}\n\n/**\n * Export identity gateway agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportIdentityGatewayAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage({\n message: `AgentOps.exportIdentityGatewayAgent: start`,\n state,\n });\n const exportData = createAgentExportTemplate();\n const agentObject = await getIdentityGatewayAgent({\n gatewayId: agentId,\n state,\n });\n exportData.agents[agentId] = agentObject;\n debugMessage({ message: `AgentOps.exportIdentityGatewayAgent: end`, state });\n return exportData;\n}\n\n/**\n * Export java agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportJavaAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage({ message: `AgentOps.exportJavaAgent: start`, state });\n const exportData = createAgentExportTemplate();\n const agentObject = await getJavaAgent({ agentId, state });\n exportData.agents[agentId] = agentObject;\n debugMessage({ message: `AgentOps.exportJavaAgent: end`, state });\n return exportData;\n}\n\n/**\n * Export web agent. The response can be saved to file as is.\n * @param agentId agent id/name\n * @returns {Promise<AgentExportInterface} Promise resolving to an AgentExportInterface object.\n */\nexport async function exportWebAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}): Promise<AgentExportInterface> {\n debugMessage({ message: `AgentOps.exportWebAgent: start`, state });\n const exportData = createAgentExportTemplate();\n const agentObject = await getWebAgent({ agentId, state });\n exportData.agents[agentId] = agentObject;\n debugMessage({ message: `AgentOps.exportWebAgent: end`, state });\n return exportData;\n}\n\n/**\n * Import agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\nexport async function importAgents({\n importData,\n state,\n}: {\n importData: AgentExportInterface;\n state: State;\n}): Promise<void> {\n debugMessage({ message: `AgentOps.importAgents: start`, state });\n if (validateImport(importData.meta)) {\n for (const agentId of Object.keys(importData.agents)) {\n const agentType = importData.agents[agentId]._type._id as AgentType;\n debugMessage({\n message: `AgentOps.importAgents: ${agentId} [${agentType}]`,\n state,\n });\n await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n }\n } else {\n throw new Error('Invalid meta data.');\n }\n debugMessage({ message: `AgentOps.importAgents: end`, state });\n}\n\n/**\n * Import identity gateway agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\nexport async function importIdentityGatewayAgents({\n importData,\n state,\n}: {\n importData: AgentExportInterface;\n state: State;\n}): Promise<void> {\n debugMessage({\n message: `AgentOps.importIdentityGatewayAgents: start`,\n state,\n });\n if (validateImport(importData.meta)) {\n for (const agentId of Object.keys(importData.agents)) {\n const agentType = importData.agents[agentId]._type._id as AgentType;\n if (agentType !== 'IdentityGatewayAgent')\n throw new Error(\n `Wrong agent type! Expected 'IdentityGatewayAgent' but got '${agentType}'.`\n );\n await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n }\n } else {\n throw new Error('Invalid meta data.');\n }\n debugMessage({ message: `AgentOps.importIdentityGatewayAgents: end`, state });\n}\n\n/**\n * Import java agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\nexport async function importJavaAgents({\n importData,\n state,\n}: {\n importData: AgentExportInterface;\n state: State;\n}): Promise<void> {\n debugMessage({ message: `AgentOps.importJavaAgents: start`, state });\n if (validateImport(importData.meta)) {\n for (const agentId of Object.keys(importData.agents)) {\n const agentType = importData.agents[agentId]._type._id as AgentType;\n if (agentType !== 'J2EEAgent')\n throw new Error(\n `Wrong agent type! Expected 'J2EEAgent' but got '${agentType}'.`\n );\n await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n }\n } else {\n throw new Error('Invalid meta data.');\n }\n debugMessage({ message: `AgentOps.importJavaAgents: end`, state });\n}\n\n/**\n * Import web agents. The import data is usually read from an agent export file.\n * @param {AgentExportInterface} importData agent import data.\n */\nexport async function importWebAgents({\n importData,\n state,\n}: {\n importData: AgentExportInterface;\n state: State;\n}): Promise<void> {\n debugMessage({ message: `AgentOps.importWebAgents: start`, state });\n if (validateImport(importData.meta)) {\n for (const agentId of Object.keys(importData.agents)) {\n const agentType = importData.agents[agentId]._type._id as AgentType;\n if (agentType !== 'WebAgent')\n throw new Error(\n `Wrong agent type! Expected 'WebAgent' but got '${agentType}'.`\n );\n await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n }\n } else {\n throw new Error('Invalid meta data.');\n }\n debugMessage({ message: `AgentOps.importWebAgents: end`, state });\n}\n\n/**\n * Import agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\nexport async function importAgent({\n agentId,\n importData,\n state,\n}: {\n agentId: string;\n importData: AgentExportInterface;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.importAgent: start`, state });\n if (validateImport(importData.meta)) {\n const agentType = importData.agents[agentId]?._type._id as AgentType;\n const result = await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n debugMessage({ message: `AgentOps.importAgent: end`, state });\n return result;\n } else {\n throw new Error('Invalid meta data.');\n }\n}\n\n/**\n * Import identity gateway agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\nexport async function importIdentityGatewayAgent({\n agentId,\n importData,\n state,\n}: {\n agentId: string;\n importData: AgentExportInterface;\n state: State;\n}) {\n debugMessage({\n message: `AgentOps.importIdentityGatewayAgent: start`,\n state,\n });\n if (validateImport(importData.meta)) {\n const agentType = importData.agents[agentId]?._type._id as AgentType;\n if (agentType !== 'IdentityGatewayAgent')\n throw new Error(\n `Wrong agent type! Expected 'IdentityGatewayAgent' but got '${agentType}'.`\n );\n const result = await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n debugMessage({\n message: `AgentOps.importIdentityGatewayAgent: end`,\n state,\n });\n return result;\n } else {\n throw new Error('Invalid meta data.');\n }\n}\n\n/**\n * Import java agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\nexport async function importJavaAgent({\n agentId,\n importData,\n state,\n}: {\n agentId: string;\n importData: AgentExportInterface;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.importJavaAgent: start`, state });\n if (validateImport(importData.meta)) {\n const agentType = importData.agents[agentId]?._type._id as AgentType;\n if (agentType !== 'J2EEAgent')\n throw new Error(\n `Wrong agent type! Expected 'J2EEAgent' but got '${agentType}'.`\n );\n const result = await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n debugMessage({ message: `AgentOps.importJavaAgent: end`, state });\n return result;\n } else {\n throw new Error('Invalid meta data.');\n }\n}\n\n/**\n * Import java agent. The import data is usually read from an agent export file.\n * @param {string} agentId agent id/name\n * @param {AgentExportInterface} importData agent import data.\n * @returns {Promise} Promise resolving to an agent object.\n */\nexport async function importWebAgent({\n agentId,\n importData,\n state,\n}: {\n agentId: string;\n importData: AgentExportInterface;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.importWebAgent: start`, state });\n if (validateImport(importData.meta)) {\n const agentType = importData.agents[agentId]?._type._id as AgentType;\n if (agentType !== 'WebAgent')\n throw new Error(\n `Wrong agent type! Expected 'WebAgent' but got '${agentType}'.`\n );\n const result = await putAgentByTypeAndId({\n agentType,\n agentId,\n agentData: importData.agents[agentId],\n state,\n });\n debugMessage({ message: `AgentOps.importWebAgent: end`, state });\n return result;\n } else {\n throw new Error('Invalid meta data.');\n }\n}\n\n/**\n * Delete all agents\n */\nexport async function deleteAgents({ state }: { state: State }) {\n debugMessage({ message: `AgentOps.deleteAgents: start`, state });\n const agents = await getAgents({ state });\n for (const agent of agents) {\n debugMessage({ message: `AgentOps.deleteAgent: '${agent['_id']}'`, state });\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'] as AgentType,\n agentId: agent['_id'],\n state,\n });\n }\n debugMessage({ message: `AgentOps.deleteAgents: end`, state });\n}\n\n/**\n * Delete agent\n * @param agentId agent id/name\n */\nexport async function deleteAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.deleteAgent: start`, state });\n const agents = await findAgentById({ agentId, state });\n if (agents.length) {\n for (const agent of agents) {\n debugMessage({\n message: `AgentOps.deleteAgent: '${agent['_id']}'`,\n state,\n });\n await deleteAgentByTypeAndId({\n agentType: agent['_type'],\n agentId: agent['_id'],\n state,\n });\n }\n } else {\n throw new Error(`Agent '${agentId}' not found!`);\n }\n debugMessage({ message: `AgentOps.deleteAgent: end`, state });\n}\n\n/**\n * Delete all identity gateway agents\n */\nexport async function deleteIdentityGatewayAgents({ state }: { state: State }) {\n debugMessage({\n message: `AgentOps.deleteIdentityGatewayAgents: start`,\n state,\n });\n const agents = await getIdentityGatewayAgents({ state });\n for (const agent of agents) {\n debugMessage({\n message: `AgentOps.deleteIdentityGatewayAgent: '${agent['_id']}'`,\n state,\n });\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n debugMessage({ message: `AgentOps.deleteIdentityGatewayAgents: end`, state });\n}\n\n/**\n * Delete identity gateway agent\n * @param agentId agent id/name\n */\nexport async function deleteIdentityGatewayAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage({\n message: `AgentOps.deleteIdentityGatewayAgent: start`,\n state,\n });\n const agents = await findAgentByTypeAndId({\n agentType: 'IdentityGatewayAgent',\n agentId,\n state,\n });\n if (agents.length) {\n for (const agent of agents) {\n debugMessage({\n message: `AgentOps.deleteIdentityGatewayAgent: '${agent['_id']}'`,\n state,\n });\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n } else {\n throw new Error(`Identity gateway agent '${agentId}' not found!`);\n }\n debugMessage({ message: `AgentOps.deleteIdentityGatewayAgent: end`, state });\n}\n\n/**\n * Delete all java agents\n */\nexport async function deleteJavaAgents({ state }: { state: State }) {\n debugMessage({ message: `AgentOps.deleteJavaAgents: start`, state });\n const agents = await getJavaAgents({ state });\n for (const agent of agents) {\n debugMessage({\n message: `AgentOps.deleteJavaAgent: '${agent['_id']}'`,\n state,\n });\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n debugMessage({ message: `AgentOps.deleteJavaAgents: end`, state });\n}\n\n/**\n * Delete java agent\n * @param agentId agent id/name\n */\nexport async function deleteJavaAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.deleteJavaAgent: start`, state });\n const agents = await findAgentByTypeAndId({\n agentType: 'J2EEAgent',\n agentId,\n state,\n });\n if (agents.length) {\n for (const agent of agents) {\n debugMessage({\n message: `AgentOps.deleteJavaAgent: '${agent['_id']}'`,\n state,\n });\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n } else {\n throw new Error(`Java agent '${agentId}' not found!`);\n }\n debugMessage({ message: `AgentOps.deleteJavaAgent: end`, state });\n}\n\n/**\n * Delete all web agents\n */\nexport async function deleteWebAgents({ state }: { state: State }) {\n debugMessage({ message: `AgentOps.deleteWebAgents: start`, state });\n const agents = await getWebAgents({ state });\n for (const agent of agents) {\n debugMessage({\n message: `AgentOps.deleteWebAgent: '${agent['_id']}'`,\n state,\n });\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n debugMessage({ message: `AgentOps.deleteWebAgents: end`, state });\n}\n\n/**\n * Delete web agent\n * @param agentId agent id/name\n */\nexport async function deleteWebAgent({\n agentId,\n state,\n}: {\n agentId: string;\n state: State;\n}) {\n debugMessage({ message: `AgentOps.deleteWebAgent: start`, state });\n const agents = await findAgentByTypeAndId({\n agentType: 'WebAgent',\n agentId,\n state,\n });\n if (agents.length) {\n for (const agent of agents) {\n debugMessage({\n message: `AgentOps.deleteWebAgent: '${agent['_id']}'`,\n state,\n });\n await deleteAgentByTypeAndId({\n agentType: agent['_type']['_id'],\n agentId: agent['_id'],\n state,\n });\n }\n } else {\n throw new Error(`Web agent '${agentId}' not found!`);\n }\n debugMessage({ message: `AgentOps.deleteWebAgent: end`, state });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/AuthenticateOps.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAQpC,OAAO,EAAE,MAAM,EAAwB,MAAM,WAAW,CAAC;AAKzD,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,+BAA+B,CACnC,IAAI,GAAE,MAAkB,EACxB,KAAK,GAAE,MAAkB,GACxB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIzB;;;;OAIG;IACH,SAAS,CAAC,gBAAgB,UAAQ;CAGnC;AAmaD;;;;GAIG;AACH,wBAAsB,+BAA+B,CAAC,EACpD,IAAgB,EAChB,KAAiB,EACjB,KAAK,GACN,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA4BzB;AAuDD;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,EAC9B,gBAAwB,EACxB,KAAK,GACN,EAAE;IACD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CA4HnB","file":"AuthenticateOps.d.ts","sourcesContent":["import url from 'url';\nimport { createHash, randomBytes } from 'crypto';\nimport readlineSync from 'readline-sync';\nimport { encodeBase64Url } from '../api/utils/Base64';\nimport State from '../shared/State';\nimport * as globalConfig from '../storage/StaticStorage';\nimport { getServerInfo, getServerVersionInfo } from '../api/ServerInfoApi';\nimport { step } from '../api/AuthenticateApi';\nimport { accessToken, authorize } from '../api/OAuth2OIDCApi';\nimport { getConnectionProfile } from './ConnectionProfileOps';\nimport { v4 } from 'uuid';\nimport { parseUrl } from '../api/utils/ApiUtils';\nimport { JwkRsa, createSignedJwtToken } from './JoseOps';\nimport { getServiceAccount } from './cloud/ServiceAccountOps';\nimport { isValidUrl } from './utils/OpsUtils';\nimport { debugMessage, printMessage, verboseMessage } from './utils/Console';\n\nexport default class AuthenticateOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get access token for service account\n * @returns {string | null} Access token or null\n */\n async getAccessTokenForServiceAccount(\n saId: string = undefined,\n saJwk: JwkRsa = undefined\n ): Promise<string | null> {\n return getAccessTokenForServiceAccount({ saId, saJwk, state: this.state });\n }\n\n /**\n * Get tokens\n * @param {boolean} forceLoginAsUser true to force login as user even if a service account is available (default: false)\n * @returns {Promise<boolean>} true if tokens were successfully obtained, false otherwise\n */\n getTokens(forceLoginAsUser = false) {\n return getTokens({ forceLoginAsUser, state: this.state });\n }\n}\n\nconst adminClientPassword = 'doesnotmatter';\nconst redirectUrlTemplate = '/platform/appAuthHelperRedirect.html';\n\nconst cloudIdmAdminScopes = 'openid fr:idm:* fr:idc:esv:*';\nconst forgeopsIdmAdminScopes = 'openid fr:idm:*';\nconst serviceAccountScopes = 'fr:am:* fr:idm:* fr:idc:esv:*';\n\nlet adminClientId = 'idmAdminClient';\n\n/**\n * Helper function to get cookie name\n * @param {State} state library state\n * @returns {string} cookie name\n */\nasync function determineCookieName(state: State) {\n const data = await getServerInfo({ state });\n debugMessage(\n `AuthenticateOps.determineCookieName: cookieName=${data.cookieName}`\n );\n return data.cookieName;\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 * @param {State} state library state\n * @returns {Object} an object indicating if 2fa is required and the original payload\n */\nfunction checkAndHandle2FA(payload, state: State) {\n debugMessage(`AuthenticateOps.checkAndHandle2FA: start`);\n // let skippable = false;\n if ('callbacks' in payload) {\n for (const callback of payload.callbacks) {\n // select localAuthentication if Admin Federation is enabled\n if (callback.type === 'SelectIdPCallback') {\n debugMessage(\n `AuthenticateOps.checkAndHandle2FA: Admin federation enabled. Allowed providers:`\n );\n let localAuth = false;\n for (const value of callback.output[0].value) {\n debugMessage(`${value.provider}`);\n if (value.provider === 'localAuthentication') {\n localAuth = true;\n }\n }\n if (localAuth) {\n debugMessage(`local auth allowed`);\n callback.input[0].value = 'localAuthentication';\n } else {\n debugMessage(`local auth NOT allowed`);\n }\n }\n if (callback.type === 'HiddenValueCallback') {\n if (callback.input[0].value.includes('skip')) {\n // skippable = true;\n callback.input[0].value = 'Skip';\n // debugMessage(\n // `AuthenticateOps.checkAndHandle2FA: end [need2fa=true, skippable=true]`\n // );\n // return {\n // nextStep: true,\n // need2fa: true,\n // factor: 'None',\n // supported: true,\n // payload,\n // };\n }\n if (callback.input[0].value.includes('webAuthnOutcome')) {\n // webauthn!!!\n debugMessage(\n `AuthenticateOps.checkAndHandle2FA: end [need2fa=true, unsupported factor: webauthn]`\n );\n return {\n nextStep: false,\n need2fa: true,\n factor: 'WebAuthN',\n supported: false,\n payload,\n };\n }\n }\n if (callback.type === 'NameCallback') {\n if (callback.output[0].value.includes('code')) {\n // skippable = false;\n debugMessage(\n `AuthenticateOps.checkAndHandle2FA: need2fa=true, skippable=false`\n );\n printMessage('2FA is enabled and required for this user...');\n const code = readlineSync.question(`${callback.output[0].value}: `);\n callback.input[0].value = code;\n debugMessage(\n `AuthenticateOps.checkAndHandle2FA: end [need2fa=true, skippable=false, factor=Code]`\n );\n return {\n nextStep: true,\n need2fa: true,\n factor: 'Code',\n supported: true,\n payload,\n };\n } else {\n // answer callback\n callback.input[0].value = state.getUsername();\n }\n }\n if (callback.type === 'PasswordCallback') {\n // answer callback\n callback.input[0].value = state.getPassword();\n }\n }\n debugMessage(`AuthenticateOps.checkAndHandle2FA: end [need2fa=false]`);\n // debugMessage(payload);\n return {\n nextStep: true,\n need2fa: false,\n factor: 'None',\n supported: true,\n payload,\n };\n }\n debugMessage(`AuthenticateOps.checkAndHandle2FA: end [need2fa=false]`);\n // debugMessage(payload);\n return {\n nextStep: false,\n need2fa: false,\n factor: 'None',\n supported: true,\n payload,\n };\n}\n\n/**\n * Helper function to set the default realm by deployment type\n * @param {State} state library state\n */\nfunction determineDefaultRealm(state: State) {\n if (\n !state.getRealm() ||\n state.getRealm() === globalConfig.DEFAULT_REALM_KEY\n ) {\n state.setRealm(\n globalConfig.DEPLOYMENT_TYPE_REALM_MAP[state.getDeploymentType()]\n );\n }\n}\n\n/**\n * Helper function to determine the deployment type\n * @param {State} state library state\n * @returns {Promise<string>} deployment type\n */\nasync function determineDeploymentType(state: State): Promise<string> {\n const cookieValue = state.getCookieValue();\n\n // if we are using a service account, we know it's cloud\n if (state.getUseBearerTokenForAmApis())\n return globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY;\n\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(state.getHost(), redirectUrlTemplate);\n\n const config = {\n maxRedirects: 0,\n headers: {\n [state.getCookieName()]: state.getCookieValue(),\n },\n };\n let bodyFormData = `redirect_uri=${redirectURL}&scope=${cloudIdmAdminScopes}&response_type=code&client_id=${fidcClientId}&csrf=${cookieValue}&decision=allow&code_challenge=${challenge}&code_challenge_method=${challengeMethod}`;\n\n let deploymentType = globalConfig.CLASSIC_DEPLOYMENT_TYPE_KEY;\n try {\n await authorize({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config,\n state,\n });\n } catch (e) {\n // debugMessage(e.response);\n if (\n e.response?.status === 302 &&\n e.response.headers?.location?.indexOf('code=') > -1\n ) {\n verboseMessage(`ForgeRock Identity Cloud`['brightCyan'] + ` detected.`);\n deploymentType = globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY;\n } else {\n try {\n bodyFormData = `redirect_uri=${redirectURL}&scope=${forgeopsIdmAdminScopes}&response_type=code&client_id=${forgeopsClientId}&csrf=${state.getCookieValue()}&decision=allow&code_challenge=${challenge}&code_challenge_method=${challengeMethod}`;\n await authorize({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config,\n state,\n });\n } catch (ex) {\n if (\n ex.response?.status === 302 &&\n ex.response.headers?.location?.indexOf('code=') > -1\n ) {\n adminClientId = forgeopsClientId;\n verboseMessage(`ForgeOps deployment`['brightCyan'] + ` detected.`);\n deploymentType = globalConfig.FORGEOPS_DEPLOYMENT_TYPE_KEY;\n } else {\n verboseMessage(`Classic deployment`['brightCyan'] + ` detected.`);\n }\n }\n }\n }\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 */\nfunction 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 * @param {State} state library state\n * @returns {string} Session token or null\n */\nasync function authenticate(state: State): Promise<string> {\n debugMessage(`AuthenticateOps.authenticate: start`);\n const config = {\n headers: {\n 'X-OpenAM-Username': state.getUsername(),\n 'X-OpenAM-Password': state.getPassword(),\n },\n };\n let response = await step({ body: {}, config, state });\n\n let skip2FA = null;\n let steps = 0;\n const maxSteps = 3;\n do {\n skip2FA = checkAndHandle2FA(response, state);\n\n // throw exception if 2fa required but factor not supported by frodo (e.g. WebAuthN)\n if (!skip2FA.supported) {\n throw new Error(`Unsupported 2FA factor: ${skip2FA.factor}`);\n }\n\n if (skip2FA.nextStep) {\n steps++;\n response = await step({ body: skip2FA.payload, state });\n }\n\n if ('tokenId' in response) {\n debugMessage(\n `AuthenticateOps.authenticate: end [tokenId=${response['tokenId']}]`\n );\n return response['tokenId'] as string;\n }\n } while (skip2FA.nextStep && steps < maxSteps);\n debugMessage(`AuthenticateOps.authenticate: end [no session]`);\n return null;\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 * @param {State} state library state\n * @returns {string} oauth2 authorization code or null\n */\nasync function getAuthCode(\n redirectURL: string,\n codeChallenge: string,\n codeChallengeMethod: string,\n state: State\n) {\n try {\n const bodyFormData = `redirect_uri=${redirectURL}&scope=${\n state.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY\n ? cloudIdmAdminScopes\n : forgeopsIdmAdminScopes\n }&response_type=code&client_id=${adminClientId}&csrf=${state.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 maxRedirects: 0,\n };\n let response = undefined;\n try {\n response = await authorize({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config,\n state,\n });\n } catch (error) {\n response = error.response;\n }\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.headers?.location;\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 debugMessage(error.stack);\n return null;\n }\n}\n\n/**\n * Helper function to obtain oauth2 access token\n * @param {State} state library state\n * @returns {Promise<string | null>} access token or null\n */\nasync function getAccessTokenForUser(state: State): Promise<string | null> {\n debugMessage(`AuthenticateOps.getAccessTokenForUser: start`);\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(state.getHost(), redirectUrlTemplate);\n const authCode = await getAuthCode(\n redirectURL,\n challenge,\n challengeMethod,\n state\n );\n if (authCode == null) {\n printMessage('error getting auth code', 'error');\n return null;\n }\n let response = null;\n if (state.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY) {\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({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config,\n state,\n });\n } else {\n const bodyFormData = `client_id=${adminClientId}&redirect_uri=${redirectURL}&grant_type=authorization_code&code=${authCode}&code_verifier=${verifier}`;\n response = await accessToken({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config: {},\n state,\n });\n }\n if ('access_token' in response.data) {\n debugMessage(`AuthenticateOps.getAccessTokenForUser: end with token`);\n return response.data.access_token;\n }\n printMessage('No access token in response.', 'error');\n } catch (error) {\n debugMessage(`Error getting access token for user: ${error}`);\n debugMessage(error.response?.data);\n }\n debugMessage(`AuthenticateOps.getAccessTokenForUser: end without token`);\n return null;\n}\n\nfunction createPayload(serviceAccountId: string, host: string) {\n const u = parseUrl(host);\n const aud = `${u.origin}:${\n u.port ? u.port : u.protocol === 'https' ? '443' : '80'\n }${u.pathname}/oauth2/access_token`;\n\n // Cross platform way of setting JWT expiry time 3 minutes in the future, expressed as number of seconds since EPOCH\n const exp = Math.floor(new Date().getTime() / 1000 + 180);\n\n // A unique ID for the JWT which is required when requesting the openid scope\n const jti = v4();\n\n const iss = serviceAccountId;\n const sub = serviceAccountId;\n\n // Create the payload for our bearer token\n const payload = { iss, sub, aud, exp, jti };\n\n return payload;\n}\n\n/**\n * Get access token for service account\n * @param {State} state library state\n * @returns {string | null} Access token or null\n */\nexport async function getAccessTokenForServiceAccount({\n saId = undefined,\n saJwk = undefined,\n state,\n}: {\n saId?: string;\n saJwk?: JwkRsa;\n state: State;\n}): Promise<string | null> {\n saId = saId ? saId : state.getServiceAccountId();\n saJwk = saJwk ? saJwk : state.getServiceAccountJwk();\n debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: start`);\n const payload = createPayload(saId, state.getHost());\n debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: payload:`);\n debugMessage(payload);\n const jwt = await createSignedJwtToken(payload, saJwk);\n debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: jwt:`);\n debugMessage(jwt);\n const bodyFormData = `assertion=${jwt}&client_id=service-account&grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&scope=${serviceAccountScopes}`;\n const response = await accessToken({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config: {},\n state,\n });\n if ('access_token' in response.data) {\n debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: token:`);\n debugMessage(response.data.access_token);\n debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: end`);\n return response.data.access_token;\n }\n debugMessage(\n `AuthenticateOps.getAccessTokenForServiceAccount: No access token in response.`\n );\n debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: end`);\n return null;\n}\n\n/**\n * Helper function to determine deployment type, default realm, and version and update library state\n * @param state library state\n */\nasync function determineDeploymentTypeAndDefaultRealmAndVersion(\n state: State\n): Promise<void> {\n debugMessage(\n `AuthenticateOps.determineDeploymentTypeAndDefaultRealmAndVersion: start`\n );\n if (!state.getDeploymentType()) {\n state.setDeploymentType(await determineDeploymentType(state));\n }\n determineDefaultRealm(state);\n debugMessage(\n `AuthenticateOps.determineDeploymentTypeAndDefaultRealmAndVersion: realm=${state.getRealm()}, type=${state.getDeploymentType()}`\n );\n\n const versionInfo = await getServerVersionInfo({ state });\n\n // https://github.com/rockcarver/frodo-cli/issues/109\n debugMessage(`Full version: ${versionInfo.fullVersion}`);\n\n const version = await getSemanticVersion(versionInfo);\n state.setAmVersion(version);\n debugMessage(\n `AuthenticateOps.determineDeploymentTypeAndDefaultRealmAndVersion: end`\n );\n}\n\n/**\n * Get logged-in subject\n * @param {State} state library state\n * @returns {string} a string identifying subject type and id\n */\nasync function getLoggedInSubject(state: State): Promise<string> {\n let subjectString = `user ${state.getUsername()}`;\n if (state.getUseBearerTokenForAmApis()) {\n try {\n const name = (\n await getServiceAccount({\n serviceAccountId: state.getServiceAccountId(),\n state,\n })\n ).name;\n subjectString = `service account ${name} [${state.getServiceAccountId()}]`;\n } catch (error) {\n subjectString = `service account ${state.getServiceAccountId()}`;\n }\n }\n return subjectString;\n}\n\n/**\n * Get tokens\n * @param {boolean} forceLoginAsUser true to force login as user even if a service account is available (default: false)\n * @param {State} state library state\n * @returns {Promise<boolean>} true if tokens were successfully obtained, false otherwise\n */\nexport async function getTokens({\n forceLoginAsUser = false,\n state,\n}: {\n forceLoginAsUser?: boolean;\n state: State;\n}): Promise<boolean> {\n debugMessage(`AuthenticateOps.getTokens: start`);\n if (!state.getHost()) {\n printMessage(\n `No host specified and FRODO_HOST env variable not set!`,\n 'error'\n );\n return false;\n }\n try {\n // if username/password on cli are empty, try to read from connections.json\n if (\n state.getUsername() == null &&\n state.getPassword() == null &&\n !state.getServiceAccountId() &&\n !state.getServiceAccountJwk()\n ) {\n const conn = await getConnectionProfile({ state });\n if (conn) {\n state.setHost(conn.tenant);\n state.setUsername(conn.username);\n state.setPassword(conn.password);\n state.setAuthenticationService(conn.authenticationService);\n state.setAuthenticationHeaderOverrides(\n conn.authenticationHeaderOverrides\n );\n state.setServiceAccountId(conn.svcacctId);\n state.setServiceAccountJwk(conn.svcacctJwk);\n } else {\n return false;\n }\n }\n\n // if host is not a valid URL, try to locate a valid URL from connections.json\n if (!isValidUrl(state.getHost())) {\n const conn = await getConnectionProfile({ state });\n if (conn) {\n state.setHost(conn.tenant);\n } else {\n return false;\n }\n }\n\n // now that we have the full tenant URL we can lookup the cookie name\n state.setCookieName(await determineCookieName(state));\n\n // use service account to login?\n if (\n !forceLoginAsUser &&\n state.getServiceAccountId() &&\n state.getServiceAccountJwk()\n ) {\n debugMessage(\n `AuthenticateOps.getTokens: Authenticating with service account ${state.getServiceAccountId()}`\n );\n try {\n const token = await getAccessTokenForServiceAccount({ state });\n state.setBearerToken(token);\n state.setUseBearerTokenForAmApis(true);\n await determineDeploymentTypeAndDefaultRealmAndVersion(state);\n } catch (saErr) {\n debugMessage(saErr.response?.data || saErr);\n debugMessage(state);\n throw new Error(\n `Service account login error: ${\n saErr.response?.data?.error_description ||\n saErr.response?.data?.message ||\n saErr\n }`\n );\n }\n }\n // use user account to login\n else if (state.getUsername() && state.getPassword()) {\n debugMessage(\n `AuthenticateOps.getTokens: Authenticating with user account ${state.getUsername()}`\n );\n const token = await authenticate(state);\n if (token) state.setCookieValue(token);\n await determineDeploymentTypeAndDefaultRealmAndVersion(state);\n if (\n state.getCookieValue() &&\n !state.getBearerToken() &&\n (state.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY ||\n state.getDeploymentType() ===\n globalConfig.FORGEOPS_DEPLOYMENT_TYPE_KEY)\n ) {\n const accessToken = await getAccessTokenForUser(state);\n if (accessToken) state.setBearerToken(accessToken);\n }\n }\n // incomplete or no credentials\n else {\n printMessage(`Incomplete or no credentials!`, 'error');\n return false;\n }\n if (\n state.getCookieValue() ||\n (state.getUseBearerTokenForAmApis() && state.getBearerToken())\n ) {\n // https://github.com/rockcarver/frodo-cli/issues/102\n printMessage(\n `Connected to ${state.getHost()} [${\n state.getRealm() ? state.getRealm() : 'root'\n }] as ${await getLoggedInSubject(state)}`,\n 'info'\n );\n debugMessage(`AuthenticateOps.getTokens: end with tokens`);\n return true;\n }\n } catch (error) {\n // regular error\n printMessage(error.message, 'error');\n // axios error am api\n printMessage(error.response?.data?.message, 'error');\n // axios error am oauth2 api\n printMessage(error.response?.data?.error_description, 'error');\n // axios error data\n debugMessage(error.response?.data);\n // stack trace\n debugMessage(error.stack || new Error().stack);\n }\n debugMessage(`AuthenticateOps.getTokens: end without tokens`);\n return false;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ops/AuthenticateOps.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAQpC,OAAO,EAAE,MAAM,EAAwB,MAAM,WAAW,CAAC;AAKzD,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,+BAA+B,CACnC,IAAI,GAAE,MAAkB,EACxB,KAAK,GAAE,MAAkB,GACxB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIzB;;;;OAIG;IACH,SAAS,CAAC,gBAAgB,UAAQ;CAGnC;AA2dD;;;;GAIG;AACH,wBAAsB,+BAA+B,CAAC,EACpD,IAAgB,EAChB,KAAiB,EACjB,KAAK,GACN,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA+CzB;AA0DD;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,EAC9B,gBAAwB,EACxB,KAAK,GACN,EAAE;IACD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CAkJnB","file":"AuthenticateOps.d.ts","sourcesContent":["import url from 'url';\nimport { createHash, randomBytes } from 'crypto';\nimport readlineSync from 'readline-sync';\nimport { encodeBase64Url } from '../api/utils/Base64';\nimport State from '../shared/State';\nimport * as globalConfig from '../storage/StaticStorage';\nimport { getServerInfo, getServerVersionInfo } from '../api/ServerInfoApi';\nimport { step } from '../api/AuthenticateApi';\nimport { accessToken, authorize } from '../api/OAuth2OIDCApi';\nimport { getConnectionProfile } from './ConnectionProfileOps';\nimport { v4 } from 'uuid';\nimport { parseUrl } from '../api/utils/ApiUtils';\nimport { JwkRsa, createSignedJwtToken } from './JoseOps';\nimport { getServiceAccount } from './cloud/ServiceAccountOps';\nimport { isValidUrl } from './utils/OpsUtils';\nimport { debugMessage, printMessage, verboseMessage } from './utils/Console';\n\nexport default class AuthenticateOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get access token for service account\n * @returns {string | null} Access token or null\n */\n async getAccessTokenForServiceAccount(\n saId: string = undefined,\n saJwk: JwkRsa = undefined\n ): Promise<string | null> {\n return getAccessTokenForServiceAccount({ saId, saJwk, state: this.state });\n }\n\n /**\n * Get tokens\n * @param {boolean} forceLoginAsUser true to force login as user even if a service account is available (default: false)\n * @returns {Promise<boolean>} true if tokens were successfully obtained, false otherwise\n */\n getTokens(forceLoginAsUser = false) {\n return getTokens({ forceLoginAsUser, state: this.state });\n }\n}\n\nconst adminClientPassword = 'doesnotmatter';\nconst redirectUrlTemplate = '/platform/appAuthHelperRedirect.html';\n\nconst cloudIdmAdminScopes = 'openid fr:idm:* fr:idc:esv:*';\nconst forgeopsIdmAdminScopes = 'openid fr:idm:*';\nconst serviceAccountScopes = 'fr:am:* fr:idm:* fr:idc:esv:*';\n\nlet adminClientId = 'idmAdminClient';\n\n/**\n * Helper function to get cookie name\n * @param {State} state library state\n * @returns {string} cookie name\n */\nasync function determineCookieName(state: State) {\n const data = await getServerInfo({ state });\n debugMessage({\n message: `AuthenticateOps.determineCookieName: cookieName=${data.cookieName}`,\n state,\n });\n return data.cookieName;\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 * @param {State} state library state\n * @returns {Object} an object indicating if 2fa is required and the original payload\n */\nfunction checkAndHandle2FA(payload, state: State) {\n debugMessage({ message: `AuthenticateOps.checkAndHandle2FA: start`, state });\n // let skippable = false;\n if ('callbacks' in payload) {\n for (const callback of payload.callbacks) {\n // select localAuthentication if Admin Federation is enabled\n if (callback.type === 'SelectIdPCallback') {\n debugMessage({\n message: `AuthenticateOps.checkAndHandle2FA: Admin federation enabled. Allowed providers:`,\n state,\n });\n let localAuth = false;\n for (const value of callback.output[0].value) {\n debugMessage({ message: `${value.provider}`, state });\n if (value.provider === 'localAuthentication') {\n localAuth = true;\n }\n }\n if (localAuth) {\n debugMessage({ message: `local auth allowed`, state });\n callback.input[0].value = 'localAuthentication';\n } else {\n debugMessage({ message: `local auth NOT allowed`, state });\n }\n }\n if (callback.type === 'HiddenValueCallback') {\n if (callback.input[0].value.includes('skip')) {\n // skippable = true;\n callback.input[0].value = 'Skip';\n // debugMessage(\n // `AuthenticateOps.checkAndHandle2FA: end [need2fa=true, skippable=true]`\n // );\n // return {\n // nextStep: true,\n // need2fa: true,\n // factor: 'None',\n // supported: true,\n // payload,\n // };\n }\n if (callback.input[0].value.includes('webAuthnOutcome')) {\n // webauthn!!!\n debugMessage({\n message: `AuthenticateOps.checkAndHandle2FA: end [need2fa=true, unsupported factor: webauthn]`,\n state,\n });\n return {\n nextStep: false,\n need2fa: true,\n factor: 'WebAuthN',\n supported: false,\n payload,\n };\n }\n }\n if (callback.type === 'NameCallback') {\n if (callback.output[0].value.includes('code')) {\n // skippable = false;\n debugMessage({\n message: `AuthenticateOps.checkAndHandle2FA: need2fa=true, skippable=false`,\n state,\n });\n printMessage({\n message: '2FA is enabled and required for this user...',\n state,\n });\n const code = readlineSync.question(`${callback.output[0].value}: `);\n callback.input[0].value = code;\n debugMessage({\n message: `AuthenticateOps.checkAndHandle2FA: end [need2fa=true, skippable=false, factor=Code]`,\n state,\n });\n return {\n nextStep: true,\n need2fa: true,\n factor: 'Code',\n supported: true,\n payload,\n };\n } else {\n // answer callback\n callback.input[0].value = state.getUsername();\n }\n }\n if (callback.type === 'PasswordCallback') {\n // answer callback\n callback.input[0].value = state.getPassword();\n }\n }\n debugMessage({\n message: `AuthenticateOps.checkAndHandle2FA: end [need2fa=false]`,\n state,\n });\n // debugMessage(payload);\n return {\n nextStep: true,\n need2fa: false,\n factor: 'None',\n supported: true,\n payload,\n };\n }\n debugMessage({\n message: `AuthenticateOps.checkAndHandle2FA: end [need2fa=false]`,\n state,\n });\n // debugMessage(payload);\n return {\n nextStep: false,\n need2fa: false,\n factor: 'None',\n supported: true,\n payload,\n };\n}\n\n/**\n * Helper function to set the default realm by deployment type\n * @param {State} state library state\n */\nfunction determineDefaultRealm(state: State) {\n if (\n !state.getRealm() ||\n state.getRealm() === globalConfig.DEFAULT_REALM_KEY\n ) {\n state.setRealm(\n globalConfig.DEPLOYMENT_TYPE_REALM_MAP[state.getDeploymentType()]\n );\n }\n}\n\n/**\n * Helper function to determine the deployment type\n * @param {State} state library state\n * @returns {Promise<string>} deployment type\n */\nasync function determineDeploymentType(state: State): Promise<string> {\n const cookieValue = state.getCookieValue();\n\n // if we are using a service account, we know it's cloud\n if (state.getUseBearerTokenForAmApis())\n return globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY;\n\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(state.getHost(), redirectUrlTemplate);\n\n const config = {\n maxRedirects: 0,\n headers: {\n [state.getCookieName()]: state.getCookieValue(),\n },\n };\n let bodyFormData = `redirect_uri=${redirectURL}&scope=${cloudIdmAdminScopes}&response_type=code&client_id=${fidcClientId}&csrf=${cookieValue}&decision=allow&code_challenge=${challenge}&code_challenge_method=${challengeMethod}`;\n\n let deploymentType = globalConfig.CLASSIC_DEPLOYMENT_TYPE_KEY;\n try {\n await authorize({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config,\n state,\n });\n } catch (e) {\n // debugMessage(e.response);\n if (\n e.response?.status === 302 &&\n e.response.headers?.location?.indexOf('code=') > -1\n ) {\n verboseMessage({\n message: `ForgeRock Identity Cloud`['brightCyan'] + ` detected.`,\n state,\n });\n deploymentType = globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY;\n } else {\n try {\n bodyFormData = `redirect_uri=${redirectURL}&scope=${forgeopsIdmAdminScopes}&response_type=code&client_id=${forgeopsClientId}&csrf=${state.getCookieValue()}&decision=allow&code_challenge=${challenge}&code_challenge_method=${challengeMethod}`;\n await authorize({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config,\n state,\n });\n } catch (ex) {\n if (\n ex.response?.status === 302 &&\n ex.response.headers?.location?.indexOf('code=') > -1\n ) {\n adminClientId = forgeopsClientId;\n verboseMessage({\n message: `ForgeOps deployment`['brightCyan'] + ` detected.`,\n state,\n });\n deploymentType = globalConfig.FORGEOPS_DEPLOYMENT_TYPE_KEY;\n } else {\n verboseMessage({\n message: `Classic deployment`['brightCyan'] + ` detected.`,\n state,\n });\n }\n }\n }\n }\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 */\nfunction 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 * @param {State} state library state\n * @returns {string} Session token or null\n */\nasync function authenticate(state: State): Promise<string> {\n debugMessage({ message: `AuthenticateOps.authenticate: start`, state });\n const config = {\n headers: {\n 'X-OpenAM-Username': state.getUsername(),\n 'X-OpenAM-Password': state.getPassword(),\n },\n };\n let response = await step({ body: {}, config, state });\n\n let skip2FA = null;\n let steps = 0;\n const maxSteps = 3;\n do {\n skip2FA = checkAndHandle2FA(response, state);\n\n // throw exception if 2fa required but factor not supported by frodo (e.g. WebAuthN)\n if (!skip2FA.supported) {\n throw new Error(`Unsupported 2FA factor: ${skip2FA.factor}`);\n }\n\n if (skip2FA.nextStep) {\n steps++;\n response = await step({ body: skip2FA.payload, state });\n }\n\n if ('tokenId' in response) {\n debugMessage({\n message: `AuthenticateOps.authenticate: end [tokenId=${response['tokenId']}]`,\n state,\n });\n return response['tokenId'] as string;\n }\n } while (skip2FA.nextStep && steps < maxSteps);\n debugMessage({\n message: `AuthenticateOps.authenticate: end [no session]`,\n state,\n });\n return null;\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 * @param {State} state library state\n * @returns {string} oauth2 authorization code or null\n */\nasync function getAuthCode(\n redirectURL: string,\n codeChallenge: string,\n codeChallengeMethod: string,\n state: State\n) {\n try {\n const bodyFormData = `redirect_uri=${redirectURL}&scope=${\n state.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY\n ? cloudIdmAdminScopes\n : forgeopsIdmAdminScopes\n }&response_type=code&client_id=${adminClientId}&csrf=${state.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 maxRedirects: 0,\n };\n let response = undefined;\n try {\n response = await authorize({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config,\n state,\n });\n } catch (error) {\n response = error.response;\n }\n if (response.status < 200 || response.status > 399) {\n printMessage({\n message: 'error getting auth code',\n type: 'error',\n state,\n });\n printMessage({\n message: 'likely cause: mismatched parameters with OAuth client config',\n type: 'error',\n state,\n });\n return null;\n }\n const redirectLocationURL = response.headers?.location;\n const queryObject = url.parse(redirectLocationURL, true).query;\n if ('code' in queryObject) {\n return queryObject.code;\n }\n printMessage({ message: 'auth code not found', type: 'error', state });\n return null;\n } catch (error) {\n printMessage({\n message: `error getting auth code - ${error.message}`,\n type: 'error',\n state,\n });\n printMessage({ message: error.response?.data, type: 'error', state });\n debugMessage({ message: error.stack, state });\n return null;\n }\n}\n\n/**\n * Helper function to obtain oauth2 access token\n * @param {State} state library state\n * @returns {Promise<string | null>} access token or null\n */\nasync function getAccessTokenForUser(state: State): Promise<string | null> {\n debugMessage({\n message: `AuthenticateOps.getAccessTokenForUser: start`,\n state,\n });\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(state.getHost(), redirectUrlTemplate);\n const authCode = await getAuthCode(\n redirectURL,\n challenge,\n challengeMethod,\n state\n );\n if (authCode == null) {\n printMessage({\n message: 'error getting auth code',\n type: 'error',\n state,\n });\n return null;\n }\n let response = null;\n if (state.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY) {\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({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config,\n state,\n });\n } else {\n const bodyFormData = `client_id=${adminClientId}&redirect_uri=${redirectURL}&grant_type=authorization_code&code=${authCode}&code_verifier=${verifier}`;\n response = await accessToken({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config: {},\n state,\n });\n }\n if ('access_token' in response.data) {\n debugMessage({\n message: `AuthenticateOps.getAccessTokenForUser: end with token`,\n state,\n });\n return response.data.access_token;\n }\n printMessage({\n message: 'No access token in response.',\n type: 'error',\n state,\n });\n } catch (error) {\n debugMessage({\n message: `Error getting access token for user: ${error}`,\n state,\n });\n debugMessage({ message: error.response?.data, state });\n }\n debugMessage({\n message: `AuthenticateOps.getAccessTokenForUser: end without token`,\n state,\n });\n return null;\n}\n\nfunction createPayload(serviceAccountId: string, host: string) {\n const u = parseUrl(host);\n const aud = `${u.origin}:${\n u.port ? u.port : u.protocol === 'https' ? '443' : '80'\n }${u.pathname}/oauth2/access_token`;\n\n // Cross platform way of setting JWT expiry time 3 minutes in the future, expressed as number of seconds since EPOCH\n const exp = Math.floor(new Date().getTime() / 1000 + 180);\n\n // A unique ID for the JWT which is required when requesting the openid scope\n const jti = v4();\n\n const iss = serviceAccountId;\n const sub = serviceAccountId;\n\n // Create the payload for our bearer token\n const payload = { iss, sub, aud, exp, jti };\n\n return payload;\n}\n\n/**\n * Get access token for service account\n * @param {State} state library state\n * @returns {string | null} Access token or null\n */\nexport async function getAccessTokenForServiceAccount({\n saId = undefined,\n saJwk = undefined,\n state,\n}: {\n saId?: string;\n saJwk?: JwkRsa;\n state: State;\n}): Promise<string | null> {\n saId = saId ? saId : state.getServiceAccountId();\n saJwk = saJwk ? saJwk : state.getServiceAccountJwk();\n debugMessage({\n message: `AuthenticateOps.getAccessTokenForServiceAccount: start`,\n state,\n });\n const payload = createPayload(saId, state.getHost());\n debugMessage({\n message: `AuthenticateOps.getAccessTokenForServiceAccount: payload:`,\n state,\n });\n debugMessage({ message: payload, state });\n const jwt = await createSignedJwtToken(payload, saJwk);\n debugMessage({\n message: `AuthenticateOps.getAccessTokenForServiceAccount: jwt:`,\n state,\n });\n debugMessage({ message: jwt, state });\n const bodyFormData = `assertion=${jwt}&client_id=service-account&grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&scope=${serviceAccountScopes}`;\n const response = await accessToken({\n amBaseUrl: state.getHost(),\n data: bodyFormData,\n config: {},\n state,\n });\n if ('access_token' in response.data) {\n debugMessage({\n message: `AuthenticateOps.getAccessTokenForServiceAccount: token:`,\n state,\n });\n debugMessage({ message: response.data.access_token, state });\n debugMessage({\n message: `AuthenticateOps.getAccessTokenForServiceAccount: end`,\n state,\n });\n return response.data.access_token;\n }\n debugMessage({\n message: `AuthenticateOps.getAccessTokenForServiceAccount: No access token in response.`,\n state,\n });\n debugMessage({\n message: `AuthenticateOps.getAccessTokenForServiceAccount: end`,\n state,\n });\n return null;\n}\n\n/**\n * Helper function to determine deployment type, default realm, and version and update library state\n * @param state library state\n */\nasync function determineDeploymentTypeAndDefaultRealmAndVersion(\n state: State\n): Promise<void> {\n debugMessage({\n message: `AuthenticateOps.determineDeploymentTypeAndDefaultRealmAndVersion: start`,\n state,\n });\n if (!state.getDeploymentType()) {\n state.setDeploymentType(await determineDeploymentType(state));\n }\n determineDefaultRealm(state);\n debugMessage({\n message: `AuthenticateOps.determineDeploymentTypeAndDefaultRealmAndVersion: realm=${state.getRealm()}, type=${state.getDeploymentType()}`,\n state,\n });\n\n const versionInfo = await getServerVersionInfo({ state });\n\n // https://github.com/rockcarver/frodo-cli/issues/109\n debugMessage({ message: `Full version: ${versionInfo.fullVersion}`, state });\n\n const version = await getSemanticVersion(versionInfo);\n state.setAmVersion(version);\n debugMessage({\n message: `AuthenticateOps.determineDeploymentTypeAndDefaultRealmAndVersion: end`,\n state,\n });\n}\n\n/**\n * Get logged-in subject\n * @param {State} state library state\n * @returns {string} a string identifying subject type and id\n */\nasync function getLoggedInSubject(state: State): Promise<string> {\n let subjectString = `user ${state.getUsername()}`;\n if (state.getUseBearerTokenForAmApis()) {\n try {\n const name = (\n await getServiceAccount({\n serviceAccountId: state.getServiceAccountId(),\n state,\n })\n ).name;\n subjectString = `service account ${name} [${state.getServiceAccountId()}]`;\n } catch (error) {\n subjectString = `service account ${state.getServiceAccountId()}`;\n }\n }\n return subjectString;\n}\n\n/**\n * Get tokens\n * @param {boolean} forceLoginAsUser true to force login as user even if a service account is available (default: false)\n * @param {State} state library state\n * @returns {Promise<boolean>} true if tokens were successfully obtained, false otherwise\n */\nexport async function getTokens({\n forceLoginAsUser = false,\n state,\n}: {\n forceLoginAsUser?: boolean;\n state: State;\n}): Promise<boolean> {\n debugMessage({ message: `AuthenticateOps.getTokens: start`, state });\n if (!state.getHost()) {\n printMessage({\n message: `No host specified and FRODO_HOST env variable not set!`,\n type: 'error',\n state,\n });\n return false;\n }\n try {\n // if username/password on cli are empty, try to read from connections.json\n if (\n state.getUsername() == null &&\n state.getPassword() == null &&\n !state.getServiceAccountId() &&\n !state.getServiceAccountJwk()\n ) {\n const conn = await getConnectionProfile({ state });\n if (conn) {\n state.setHost(conn.tenant);\n state.setUsername(conn.username);\n state.setPassword(conn.password);\n state.setAuthenticationService(conn.authenticationService);\n state.setAuthenticationHeaderOverrides(\n conn.authenticationHeaderOverrides\n );\n state.setServiceAccountId(conn.svcacctId);\n state.setServiceAccountJwk(conn.svcacctJwk);\n } else {\n return false;\n }\n }\n\n // if host is not a valid URL, try to locate a valid URL from connections.json\n if (!isValidUrl(state.getHost())) {\n const conn = await getConnectionProfile({ state });\n if (conn) {\n state.setHost(conn.tenant);\n } else {\n return false;\n }\n }\n\n // now that we have the full tenant URL we can lookup the cookie name\n state.setCookieName(await determineCookieName(state));\n\n // use service account to login?\n if (\n !forceLoginAsUser &&\n state.getServiceAccountId() &&\n state.getServiceAccountJwk()\n ) {\n debugMessage({\n message: `AuthenticateOps.getTokens: Authenticating with service account ${state.getServiceAccountId()}`,\n state,\n });\n try {\n const token = await getAccessTokenForServiceAccount({ state });\n state.setBearerToken(token);\n state.setUseBearerTokenForAmApis(true);\n await determineDeploymentTypeAndDefaultRealmAndVersion(state);\n } catch (saErr) {\n debugMessage({ message: saErr.response?.data || saErr, state });\n debugMessage({ message: state, state });\n throw new Error(\n `Service account login error: ${\n saErr.response?.data?.error_description ||\n saErr.response?.data?.message ||\n saErr\n }`\n );\n }\n }\n // use user account to login\n else if (state.getUsername() && state.getPassword()) {\n debugMessage({\n message: `AuthenticateOps.getTokens: Authenticating with user account ${state.getUsername()}`,\n state,\n });\n const token = await authenticate(state);\n if (token) state.setCookieValue(token);\n await determineDeploymentTypeAndDefaultRealmAndVersion(state);\n if (\n state.getCookieValue() &&\n !state.getBearerToken() &&\n (state.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY ||\n state.getDeploymentType() ===\n globalConfig.FORGEOPS_DEPLOYMENT_TYPE_KEY)\n ) {\n const accessToken = await getAccessTokenForUser(state);\n if (accessToken) state.setBearerToken(accessToken);\n }\n }\n // incomplete or no credentials\n else {\n printMessage({\n message: `Incomplete or no credentials!`,\n type: 'error',\n state,\n });\n return false;\n }\n if (\n state.getCookieValue() ||\n (state.getUseBearerTokenForAmApis() && state.getBearerToken())\n ) {\n // https://github.com/rockcarver/frodo-cli/issues/102\n printMessage({\n message: `Connected to ${state.getHost()} [${\n state.getRealm() ? state.getRealm() : 'root'\n }] as ${await getLoggedInSubject(state)}`,\n type: 'info',\n state,\n });\n debugMessage({\n message: `AuthenticateOps.getTokens: end with tokens`,\n state,\n });\n return true;\n }\n } catch (error) {\n // regular error\n printMessage({ message: error.message, type: 'error', state });\n // axios error am api\n printMessage({\n message: error.response?.data?.message,\n type: 'error',\n state,\n });\n // axios error am oauth2 api\n printMessage({\n message: error.response?.data?.error_description,\n type: 'error',\n state,\n });\n // axios error data\n debugMessage({ message: error.response?.data, state });\n // stack trace\n debugMessage({ message: error.stack || new Error().stack, state });\n }\n debugMessage({\n message: `AuthenticateOps.getTokens: end without tokens`,\n state,\n });\n return false;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/CirclesOfTrustOps.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,gBAAgB,EAChB,mBAAmB,EAEpB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAC3D,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N,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,6BAA6B,CAAC;IAC1C,KAAK,EAAE,KAAK,CAAC;CACd,gBAoCA;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAAC,EAC7C,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,6BAA6B,CAAC;IAC1C,KAAK,EAAE,KAAK,CAAC;CACd,gBAmCA;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,6BAA6B,CAAC;IAC1C,KAAK,EAAE,KAAK,CAAC;CACd,kBAoCA","file":"CirclesOfTrustOps.d.ts","sourcesContent":["import { debugMessage } from './utils/Console';\nimport {\n getCirclesOfTrust as _getCirclesOfTrust,\n getCircleOfTrust,\n createCircleOfTrust,\n updateCircleOfTrust,\n} from '../api/CirclesOfTrustApi';\nimport { getMetadata } from './utils/ExportImportUtils';\nimport State from '../shared/State';\nimport { CirclesOfTrustExportInterface } from './OpsTypes';\nimport { CircleOfTrustSkeleton } from '../api/ApiTypes';\n\nexport default class CirclesOfTrustOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Create an empty agent export template\n * @returns {CirclesOfTrustExportInterface} an empty agent export template\n */\n createCirclesOfTrustExportTemplate() {\n return createCirclesOfTrustExportTemplate({ state: this.state });\n }\n\n /**\n * Get SAML circle of trust\n * @param {String} cotId circle of trust id/name\n */\n async getCircleOfTrust(cotId: string) {\n return getCircleOfTrust({ cotId, state: this.state });\n }\n\n /**\n * Get SAML circles of trust\n */\n async getCirclesOfTrust() {\n return getCirclesOfTrust({ state: this.state });\n }\n\n async createCircleOfTrust(cotData: CircleOfTrustSkeleton) {\n return createCircleOfTrust({ cotData, state: this.state });\n }\n\n /**\n * Export SAML circle of trust\n * @param {String} cotId circle of trust id/name\n */\n async exportCircleOfTrust(cotId: string) {\n return exportCircleOfTrust({ cotId, state: this.state });\n }\n\n /**\n * Export all SAML circles of trust\n */\n async exportCirclesOfTrust() {\n return exportCirclesOfTrust({ state: this.state });\n }\n\n /**\n * Import a SAML circle of trust by id/name from file\n * @param {String} cotId Circle of trust id/name\n * @param {CirclesOfTrustExportInterface} importData Import data\n */\n async importCircleOfTrust(\n cotId: string,\n importData: CirclesOfTrustExportInterface\n ) {\n return importCircleOfTrust({ cotId, importData, state: this.state });\n }\n\n /**\n * Import first SAML circle of trust\n * @param {CirclesOfTrustExportInterface} importData Import data\n */\n async importFirstCircleOfTrust(importData: CirclesOfTrustExportInterface) {\n return importFirstCircleOfTrust({ importData, state: this.state });\n }\n\n /**\n * Import all SAML circles of trust\n * @param {CirclesOfTrustExportInterface} importData Import file name\n */\n async importCirclesOfTrust(importData: CirclesOfTrustExportInterface) {\n return importCirclesOfTrust({ importData, state: this.state });\n }\n}\n\n/**\n * Create an empty agent export template\n * @returns {CirclesOfTrustExportInterface} an empty agent export template\n */\nexport function createCirclesOfTrustExportTemplate({\n state,\n}: {\n state: State;\n}) {\n return {\n meta: getMetadata({ state }),\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n cot: {},\n },\n } as CirclesOfTrustExportInterface;\n}\n\nexport { getCircleOfTrust, createCircleOfTrust };\n\n/**\n * Get circles of trust\n */\nexport async function getCirclesOfTrust({ state }: { state: State }) {\n const { result } = await _getCirclesOfTrust({ state });\n return result;\n}\n\n/**\n * Export circle of trust\n * @param {string} cotId circle of trust id/name\n * @returns {Promise<CirclesOfTrustExportInterface>} a promise that resolves to an CirclesOfTrustExportInterface object\n */\nexport async function exportCircleOfTrust({\n cotId,\n state,\n}: {\n cotId: string;\n state: State;\n}): Promise<CirclesOfTrustExportInterface> {\n debugMessage(`CirclesOfTrustOps.exportCircleOfTrust: start`);\n const exportData = createCirclesOfTrustExportTemplate({ state });\n const errors = [];\n try {\n const cotData = await getCircleOfTrust({\n cotId,\n state,\n });\n exportData.saml.cot[cotData._id] = cotData;\n } catch (error) {\n errors.push(error);\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => {\n if (error.response?.status === 404) {\n return `Circle of trust ${cotId} does not exist in realm ${state.getRealm()}`;\n } else {\n return error.response?.data?.message || error.message;\n }\n })\n .join('\\n');\n throw new Error(`Export error:\\n${errorMessages}`);\n }\n debugMessage(`CirclesOfTrustOps.exportCircleOfTrust: end`);\n return exportData;\n}\n\n/**\n * Export circles of trust\n * @returns {Promise<CirclesOfTrustExportInterface>} a promise that resolves to an CirclesOfTrustExportInterface object\n */\nexport async function exportCirclesOfTrust({\n state,\n}: {\n state: State;\n}): Promise<CirclesOfTrustExportInterface> {\n debugMessage(`CirclesOfTrustOps.exportCirclesOfTrust: start`);\n const exportData = createCirclesOfTrustExportTemplate({ state });\n const errors = [];\n try {\n const cots = await getCirclesOfTrust({ state });\n for (const cot of cots) {\n exportData.saml.cot[cot._id] = cot;\n }\n } catch (error) {\n errors.push(error);\n }\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n throw new Error(`Export error:\\n${errorMessages}`);\n }\n debugMessage(`CirclesOfTrustOps.exportCirclesOfTrust: end`);\n return exportData;\n}\n\n/**\n * Import a SAML circle of trust by id/name from file\n * @param {String} cotId Circle of trust id/name\n * @param {CirclesOfTrustExportInterface} importData import data\n */\nexport async function importCircleOfTrust({\n cotId,\n importData,\n state,\n}: {\n cotId: string;\n importData: CirclesOfTrustExportInterface;\n state: State;\n}) {\n let response = null;\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.saml.cot)) {\n if (id === cotId) {\n try {\n const cotData = importData.saml.cot[id];\n delete cotData._rev;\n try {\n response = await createCircleOfTrust({ cotData, state });\n } catch (createError) {\n if (createError.response?.status === 409)\n response = await updateCircleOfTrust({\n cotId: id,\n cotData,\n state,\n });\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n }\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(`Import error:\\n${cotId} not found in import data!`);\n }\n return response;\n}\n\n/**\n * Import first SAML circle of trust\n * @param {CirclesOfTrustExportInterface} importData import data\n */\nexport async function importFirstCircleOfTrust({\n importData,\n state,\n}: {\n importData: CirclesOfTrustExportInterface;\n state: State;\n}) {\n let response = null;\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.saml.cot)) {\n try {\n const cotData = importData.saml.cot[id];\n delete cotData._rev;\n try {\n response = await createCircleOfTrust({ cotData, state });\n } catch (createError) {\n if (createError.response?.status === 409)\n response = await updateCircleOfTrust({\n cotId: id,\n cotData,\n state,\n });\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n break;\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(`Import error:\\nNo circles of trust found in import data!`);\n }\n return response;\n}\n\n/**\n * Import SAML circles of trust\n * @param {CirclesOfTrustExportInterface} importData import data\n */\nexport async function importCirclesOfTrust({\n importData,\n state,\n}: {\n importData: CirclesOfTrustExportInterface;\n state: State;\n}) {\n const response = [];\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.saml.cot)) {\n try {\n const cotData = importData.saml.cot[id];\n delete cotData._rev;\n try {\n response.push(await createCircleOfTrust({ cotData, state }));\n } catch (createError) {\n if (createError.response?.status === 409)\n response.push(\n await updateCircleOfTrust({\n cotId: id,\n cotData,\n state,\n })\n );\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(`Import error:\\nNo circles of trust found in import data!`);\n }\n return response;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["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AACH,wBAAsB,oBAAoB,CAAC,EACzC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAwBzC;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,KAAK,EACL,UAAU,EACV,KAAK,GACN,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,6BAA6B,CAAC;IAC1C,KAAK,EAAE,KAAK,CAAC;CACd,gBAoCA;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAAC,EAC7C,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,6BAA6B,CAAC;IAC1C,KAAK,EAAE,KAAK,CAAC;CACd,gBAmCA;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,6BAA6B,CAAC;IAC1C,KAAK,EAAE,KAAK,CAAC;CACd,kBAoCA","file":"CirclesOfTrustOps.d.ts","sourcesContent":["import { debugMessage } from './utils/Console';\nimport {\n getCirclesOfTrust as _getCirclesOfTrust,\n getCircleOfTrust,\n createCircleOfTrust,\n updateCircleOfTrust,\n} from '../api/CirclesOfTrustApi';\nimport { getMetadata } from './utils/ExportImportUtils';\nimport State from '../shared/State';\nimport { CirclesOfTrustExportInterface } from './OpsTypes';\nimport { CircleOfTrustSkeleton } from '../api/ApiTypes';\n\nexport default class CirclesOfTrustOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Create an empty agent export template\n * @returns {CirclesOfTrustExportInterface} an empty agent export template\n */\n createCirclesOfTrustExportTemplate() {\n return createCirclesOfTrustExportTemplate({ state: this.state });\n }\n\n /**\n * Get SAML circle of trust\n * @param {String} cotId circle of trust id/name\n */\n async getCircleOfTrust(cotId: string) {\n return getCircleOfTrust({ cotId, state: this.state });\n }\n\n /**\n * Get SAML circles of trust\n */\n async getCirclesOfTrust() {\n return getCirclesOfTrust({ state: this.state });\n }\n\n async createCircleOfTrust(cotData: CircleOfTrustSkeleton) {\n return createCircleOfTrust({ cotData, state: this.state });\n }\n\n /**\n * Export SAML circle of trust\n * @param {String} cotId circle of trust id/name\n */\n async exportCircleOfTrust(cotId: string) {\n return exportCircleOfTrust({ cotId, state: this.state });\n }\n\n /**\n * Export all SAML circles of trust\n */\n async exportCirclesOfTrust() {\n return exportCirclesOfTrust({ state: this.state });\n }\n\n /**\n * Import a SAML circle of trust by id/name from file\n * @param {String} cotId Circle of trust id/name\n * @param {CirclesOfTrustExportInterface} importData Import data\n */\n async importCircleOfTrust(\n cotId: string,\n importData: CirclesOfTrustExportInterface\n ) {\n return importCircleOfTrust({ cotId, importData, state: this.state });\n }\n\n /**\n * Import first SAML circle of trust\n * @param {CirclesOfTrustExportInterface} importData Import data\n */\n async importFirstCircleOfTrust(importData: CirclesOfTrustExportInterface) {\n return importFirstCircleOfTrust({ importData, state: this.state });\n }\n\n /**\n * Import all SAML circles of trust\n * @param {CirclesOfTrustExportInterface} importData Import file name\n */\n async importCirclesOfTrust(importData: CirclesOfTrustExportInterface) {\n return importCirclesOfTrust({ importData, state: this.state });\n }\n}\n\n/**\n * Create an empty agent export template\n * @returns {CirclesOfTrustExportInterface} an empty agent export template\n */\nexport function createCirclesOfTrustExportTemplate({\n state,\n}: {\n state: State;\n}) {\n return {\n meta: getMetadata({ state }),\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n cot: {},\n },\n } as CirclesOfTrustExportInterface;\n}\n\nexport { getCircleOfTrust, createCircleOfTrust };\n\n/**\n * Get circles of trust\n */\nexport async function getCirclesOfTrust({ state }: { state: State }) {\n const { result } = await _getCirclesOfTrust({ state });\n return result;\n}\n\n/**\n * Export circle of trust\n * @param {string} cotId circle of trust id/name\n * @returns {Promise<CirclesOfTrustExportInterface>} a promise that resolves to an CirclesOfTrustExportInterface object\n */\nexport async function exportCircleOfTrust({\n cotId,\n state,\n}: {\n cotId: string;\n state: State;\n}): Promise<CirclesOfTrustExportInterface> {\n debugMessage({\n message: `CirclesOfTrustOps.exportCircleOfTrust: start`,\n state,\n });\n const exportData = createCirclesOfTrustExportTemplate({ state });\n const errors = [];\n try {\n const cotData = await getCircleOfTrust({\n cotId,\n state,\n });\n exportData.saml.cot[cotData._id] = cotData;\n } catch (error) {\n errors.push(error);\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => {\n if (error.response?.status === 404) {\n return `Circle of trust ${cotId} does not exist in realm ${state.getRealm()}`;\n } else {\n return error.response?.data?.message || error.message;\n }\n })\n .join('\\n');\n throw new Error(`Export error:\\n${errorMessages}`);\n }\n debugMessage({\n message: `CirclesOfTrustOps.exportCircleOfTrust: end`,\n state,\n });\n return exportData;\n}\n\n/**\n * Export circles of trust\n * @returns {Promise<CirclesOfTrustExportInterface>} a promise that resolves to an CirclesOfTrustExportInterface object\n */\nexport async function exportCirclesOfTrust({\n state,\n}: {\n state: State;\n}): Promise<CirclesOfTrustExportInterface> {\n debugMessage({\n message: `CirclesOfTrustOps.exportCirclesOfTrust: start`,\n state,\n });\n const exportData = createCirclesOfTrustExportTemplate({ state });\n const errors = [];\n try {\n const cots = await getCirclesOfTrust({ state });\n for (const cot of cots) {\n exportData.saml.cot[cot._id] = cot;\n }\n } catch (error) {\n errors.push(error);\n }\n if (errors.length) {\n const errorMessages = errors.map((error) => error.message).join('\\n');\n throw new Error(`Export error:\\n${errorMessages}`);\n }\n debugMessage({\n message: `CirclesOfTrustOps.exportCirclesOfTrust: end`,\n state,\n });\n return exportData;\n}\n\n/**\n * Import a SAML circle of trust by id/name from file\n * @param {String} cotId Circle of trust id/name\n * @param {CirclesOfTrustExportInterface} importData import data\n */\nexport async function importCircleOfTrust({\n cotId,\n importData,\n state,\n}: {\n cotId: string;\n importData: CirclesOfTrustExportInterface;\n state: State;\n}) {\n let response = null;\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.saml.cot)) {\n if (id === cotId) {\n try {\n const cotData = importData.saml.cot[id];\n delete cotData._rev;\n try {\n response = await createCircleOfTrust({ cotData, state });\n } catch (createError) {\n if (createError.response?.status === 409)\n response = await updateCircleOfTrust({\n cotId: id,\n cotData,\n state,\n });\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n }\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(`Import error:\\n${cotId} not found in import data!`);\n }\n return response;\n}\n\n/**\n * Import first SAML circle of trust\n * @param {CirclesOfTrustExportInterface} importData import data\n */\nexport async function importFirstCircleOfTrust({\n importData,\n state,\n}: {\n importData: CirclesOfTrustExportInterface;\n state: State;\n}) {\n let response = null;\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.saml.cot)) {\n try {\n const cotData = importData.saml.cot[id];\n delete cotData._rev;\n try {\n response = await createCircleOfTrust({ cotData, state });\n } catch (createError) {\n if (createError.response?.status === 409)\n response = await updateCircleOfTrust({\n cotId: id,\n cotData,\n state,\n });\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n break;\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(`Import error:\\nNo circles of trust found in import data!`);\n }\n return response;\n}\n\n/**\n * Import SAML circles of trust\n * @param {CirclesOfTrustExportInterface} importData import data\n */\nexport async function importCirclesOfTrust({\n importData,\n state,\n}: {\n importData: CirclesOfTrustExportInterface;\n state: State;\n}) {\n const response = [];\n const errors = [];\n const imported = [];\n for (const id of Object.keys(importData.saml.cot)) {\n try {\n const cotData = importData.saml.cot[id];\n delete cotData._rev;\n try {\n response.push(await createCircleOfTrust({ cotData, state }));\n } catch (createError) {\n if (createError.response?.status === 409)\n response.push(\n await updateCircleOfTrust({\n cotId: id,\n cotData,\n state,\n })\n );\n else throw createError;\n }\n imported.push(id);\n } catch (error) {\n errors.push(error);\n }\n }\n if (errors.length) {\n const errorMessages = errors\n .map((error) => error.response?.data?.message || error.message)\n .join('\\n');\n throw new Error(`Import error:\\n${errorMessages}`);\n }\n if (0 === imported.length) {\n throw new Error(`Import error:\\nNo circles of trust found in import data!`);\n }\n return response;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/ConnectionProfileOps.ts"],"names":[],"mappings":"AAMA,OAAO,EAA6C,MAAM,EAAE,MAAM,WAAW,CAAC;AAK9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAG5D,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACH,yBAAyB,IAAI,MAAM;IAInC;;;;;OAKG;IACH,sBAAsB,CACpB,kBAAkB,EAAE,wBAAwB,EAC5C,IAAI,EAAE,MAAM,GACX,gCAAgC,EAAE;IAIrC;;;;;OAKG;IACG,sBAAsB;IAI5B;;;;OAIG;IACG,0BAA0B,CAC9B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,0BAA0B,CAAC;IAItC;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,0BAA0B,CAAC;IAIjE;;;;OAIG;IACG,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D;;;OAGG;IACH,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI3C;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,yBAAyB,CAAC;CAGjE;AAMD,MAAM,WAAW,gCAAgC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,GA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GAKG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAqDtC;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAEtC;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CA2HnB;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;CACd,QAoCA;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAsBrC","file":"ConnectionProfileOps.d.ts","sourcesContent":["import fs from 'fs';\nimport os from 'os';\nimport path from 'path';\nimport DataProtection from './utils/DataProtection';\nimport { debugMessage, printMessage, verboseMessage } from './utils/Console';\nimport { FRODO_CONNECTION_PROFILES_PATH_KEY } from '../storage/StaticStorage';\nimport { createJwkRsa, createJwks, getJwkRsaPublic, JwkRsa } from './JoseOps';\nimport {\n createServiceAccount,\n getServiceAccount,\n} from './cloud/ServiceAccountOps';\nimport { IdObjectSkeletonInterface } from '../api/ApiTypes';\nimport { saveJsonToFile } from './utils/ExportImportUtils';\nimport { isValidUrl } from './utils/OpsUtils';\nimport State from '../shared/State';\n\nexport default class ConnectionProfileOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get connection profiles file name\n * @returns {string} connection profiles file name\n */\n getConnectionProfilesPath(): string {\n return getConnectionProfilesPath({ state: this.state });\n }\n\n /**\n * Find connection profiles\n * @param {ConnectionsFileInterface} connectionProfiles connection profile object\n * @param {string} host host url or unique substring\n * @returns {SecureConnectionProfileInterface[]} Array of connection profiles\n */\n findConnectionProfiles(\n connectionProfiles: ConnectionsFileInterface,\n host: string\n ): SecureConnectionProfileInterface[] {\n return findConnectionProfiles({ connectionProfiles, host });\n }\n\n /**\n * Initialize connection profiles\n *\n * This method is called from app.ts and runs before any of the message handlers are registered.\n * Therefore none of the Console message functions will produce any output.\n */\n async initConnectionProfiles() {\n initConnectionProfiles({ state: this.state });\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 */\n async getConnectionProfileByHost(\n host: string\n ): Promise<ConnectionProfileInterface> {\n return getConnectionProfileByHost({ host, state: this.state });\n }\n\n /**\n * Get connection profile\n * @returns {Object} connection profile or null\n */\n async getConnectionProfile(): Promise<ConnectionProfileInterface> {\n return getConnectionProfile({ state: this.state });\n }\n\n /**\n * Save connection profile\n * @param {string} host host url for new profiles or unique substring for existing profiles\n * @returns {Promise<boolean>} true if the operation succeeded, false otherwise\n */\n async saveConnectionProfile(host: string): Promise<boolean> {\n return saveConnectionProfile({ host, state: this.state });\n }\n\n /**\n * Delete connection profile\n * @param {string} host host tenant host url or unique substring\n */\n deleteConnectionProfile(host: string): void {\n deleteConnectionProfile({ host, state: this.state });\n }\n\n /**\n * Create a new service account using auto-generated parameters\n * @returns {Promise<IdObjectSkeletonInterface>} A promise resolving to a service account object\n */\n async addNewServiceAccount(): Promise<IdObjectSkeletonInterface> {\n return addNewServiceAccount({ state: this.state });\n }\n}\n\nconst fileOptions = {\n indentation: 4,\n};\n\nexport interface SecureConnectionProfileInterface {\n tenant: string;\n username?: string | null;\n encodedPassword?: string | null;\n logApiKey?: string | null;\n encodedLogApiSecret?: string | null;\n authenticationService?: string | null;\n authenticationHeaderOverrides?: Record<string, string>;\n svcacctId?: string | null;\n encodedSvcacctJwk?: string | null;\n svcacctName?: string | null;\n}\n\nexport interface ConnectionProfileInterface {\n tenant: string;\n username?: string | null;\n password?: string | null;\n logApiKey?: string | null;\n logApiSecret?: string | null;\n authenticationService?: string | null;\n authenticationHeaderOverrides?: Record<string, string>;\n svcacctId?: string | null;\n svcacctJwk?: JwkRsa;\n svcacctName?: string | null;\n}\n\nexport interface ConnectionsFileInterface {\n [key: string]: SecureConnectionProfileInterface;\n}\n\nconst legacyProfileFilename = '.frodorc';\nconst newProfileFilename = 'Connections.json';\n\n/**\n * Get connection profiles file name\n * @param {State} state library state\n * @returns {String} connection profiles file name\n */\nexport function getConnectionProfilesPath({ state }: { state: State }): string {\n return (\n state.getConnectionProfilesPath() ||\n process.env[FRODO_CONNECTION_PROFILES_PATH_KEY] ||\n `${os.homedir()}/.frodo/${newProfileFilename}`\n );\n}\n\n/**\n * Find connection profiles\n * @param {ConnectionsFileInterface} connectionProfiles connection profile object\n * @param {string} host host url or unique substring\n * @param {State} state library state\n * @returns {SecureConnectionProfileInterface[]} Array of connection profiles\n */\nfunction findConnectionProfiles({\n connectionProfiles,\n host,\n}: {\n connectionProfiles: ConnectionsFileInterface;\n host: string;\n}): SecureConnectionProfileInterface[] {\n const profiles: SecureConnectionProfileInterface[] = [];\n for (const tenant in connectionProfiles) {\n debugMessage(\n `ConnectionProfileOps.findConnectionProfiles: tenant=${tenant}`\n );\n if (tenant.includes(host)) {\n debugMessage(\n `ConnectionProfileOps.findConnectionProfiles: '${host}' identifies '${tenant}', including in result set`\n );\n const foundProfile = { ...connectionProfiles[tenant] };\n foundProfile.tenant = tenant;\n profiles.push(foundProfile);\n }\n }\n return profiles;\n}\n\n/**\n * Migrate from .frodorc to Connections.json\n */\nfunction migrateFromLegacyProfile() {\n const legacyPath = `${os.homedir()}/.frodo/${legacyProfileFilename}`;\n const newPath = `${os.homedir()}/.frodo/${newProfileFilename}`;\n if (!fs.existsSync(legacyPath) && !fs.existsSync(newPath)) {\n // no connections file (old or new), create empty new one\n fs.writeFileSync(\n newPath,\n JSON.stringify({}, null, fileOptions.indentation)\n );\n } else if (fs.existsSync(legacyPath) && !fs.existsSync(newPath)) {\n // old exists, new one does not - so copy old to new one\n fs.copyFileSync(legacyPath, newPath);\n // for now, just add a \"deprecated\" suffix. May delete the old file\n // in a future release\n fs.renameSync(legacyPath, `${legacyPath}.deprecated`);\n }\n // in other cases, where\n // (both old and new exist) OR (only new one exists) don't do anything\n}\n\n/**\n * Initialize connection profiles\n *\n * This method is called from app.ts and runs before any of the message handlers are registered.\n * Therefore none of the Console message functions will produce any output.\n * @param {State} state library state\n */\nexport async function initConnectionProfiles({ state }: { state: State }) {\n const dataProtection = new DataProtection(state.getMasterKeyPath());\n // create connections.json file if it doesn't exist\n const filename = getConnectionProfilesPath({ state });\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 and logApiSecret from clear text to aes-256-GCM\n else {\n migrateFromLegacyProfile();\n const data = fs.readFileSync(filename, 'utf8');\n const connectionsData: ConnectionsFileInterface = JSON.parse(data);\n let convert = false;\n for (const conn of Object.keys(connectionsData)) {\n if (connectionsData[conn]['password']) {\n convert = true;\n connectionsData[conn].encodedPassword = await dataProtection.encrypt(\n connectionsData[conn]['password']\n );\n delete connectionsData[conn]['password'];\n }\n if (connectionsData[conn]['logApiSecret']) {\n convert = true;\n connectionsData[conn].encodedLogApiSecret =\n await dataProtection.encrypt(connectionsData[conn]['logApiSecret']);\n delete connectionsData[conn]['logApiSecret'];\n }\n if (connectionsData[conn]['svcacctJwk']) {\n convert = true;\n connectionsData[conn].encodedSvcacctJwk = await dataProtection.encrypt(\n connectionsData[conn]['svcacctJwk']\n );\n delete connectionsData[conn]['svcacctJwk'];\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 * @param {State} state library state\n * @returns {Object} connection profile or null\n */\nexport async function getConnectionProfileByHost({\n host,\n state,\n}: {\n host: string;\n state: State;\n}): Promise<ConnectionProfileInterface> {\n try {\n const dataProtection = new DataProtection(state.getMasterKeyPath());\n const filename = getConnectionProfilesPath({ state });\n const connectionsData = JSON.parse(fs.readFileSync(filename, 'utf8'));\n const profiles = findConnectionProfiles({\n connectionProfiles: connectionsData,\n host,\n });\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 logApiKey: profiles[0].logApiKey ? profiles[0].logApiKey : null,\n logApiSecret: profiles[0].encodedLogApiSecret\n ? await dataProtection.decrypt(profiles[0].encodedLogApiSecret)\n : null,\n authenticationService: profiles[0].authenticationService\n ? profiles[0].authenticationService\n : null,\n authenticationHeaderOverrides: profiles[0].authenticationHeaderOverrides\n ? profiles[0].authenticationHeaderOverrides\n : {},\n svcacctName: profiles[0].svcacctName ? profiles[0].svcacctName : null,\n svcacctId: profiles[0].svcacctId ? profiles[0].svcacctId : null,\n svcacctJwk: profiles[0].encodedSvcacctJwk\n ? await dataProtection.decrypt(profiles[0].encodedSvcacctJwk)\n : null,\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 state,\n}: {\n state: State;\n}): Promise<ConnectionProfileInterface> {\n return getConnectionProfileByHost({ host: state.getHost(), state });\n}\n\n/**\n * Save connection profile\n * @param {string} host host url for new profiles or unique substring for existing profiles\n * @returns {Promise<boolean>} true if the operation succeeded, false otherwise\n */\nexport async function saveConnectionProfile({\n host,\n state,\n}: {\n host: string;\n state: State;\n}): Promise<boolean> {\n debugMessage(`ConnectionProfileOps.saveConnectionProfile: start`);\n const dataProtection = new DataProtection(state.getMasterKeyPath());\n const filename = getConnectionProfilesPath({ state });\n debugMessage(`Saving connection profile in ${filename}`);\n let profiles: ConnectionsFileInterface = {};\n let profile: SecureConnectionProfileInterface = { tenant: '' };\n try {\n fs.statSync(filename);\n const data = fs.readFileSync(filename, 'utf8');\n profiles = JSON.parse(data);\n\n // find tenant\n const found = findConnectionProfiles({\n connectionProfiles: profiles,\n host,\n });\n\n // replace tenant in session with real tenant url if necessary\n if (found.length === 1) {\n profile = found[0];\n state.setHost(profile.tenant);\n verboseMessage(`Existing profile: ${profile.tenant}`);\n debugMessage(profile);\n }\n\n // connection profile not found, validate host is a real URL\n if (found.length === 0) {\n if (isValidUrl(host)) {\n state.setHost(host);\n debugMessage(`New profile: ${host}`);\n } else {\n printMessage(\n `No existing profile found matching '${host}'. Provide a valid URL as the host argument to create a new profile.`,\n 'error'\n );\n debugMessage(`ConnectionProfileOps.saveConnectionProfile: end [false]`);\n return false;\n }\n }\n } catch (error) {\n debugMessage(`New profiles file ${filename} with new profile ${host}`);\n }\n\n // user account\n if (state.getUsername()) profile.username = state.getUsername();\n if (state.getPassword())\n profile.encodedPassword = await dataProtection.encrypt(state.getPassword());\n\n // log API\n if (state.getLogApiKey()) profile.logApiKey = state.getLogApiKey();\n if (state.getLogApiSecret())\n profile.encodedLogApiSecret = await dataProtection.encrypt(\n state.getLogApiSecret()\n );\n\n // service account\n if (state.getServiceAccountId()) {\n profile.svcacctId = state.getServiceAccountId();\n profile.svcacctName = (\n await getServiceAccount({\n serviceAccountId: state.getServiceAccountId(),\n state,\n })\n ).name;\n }\n if (state.getServiceAccountJwk())\n profile.encodedSvcacctJwk = await dataProtection.encrypt(\n state.getServiceAccountJwk()\n );\n // update existing service account profile\n if (profile.svcacctId && !profile.svcacctName) {\n profile.svcacctName = (\n await getServiceAccount({ serviceAccountId: profile.svcacctId, state })\n ).name;\n debugMessage(\n `ConnectionProfileOps.saveConnectionProfile: added missing service account name`\n );\n }\n\n // advanced settings\n if (state.getAuthenticationService()) {\n profile.authenticationService = state.getAuthenticationService();\n printMessage(\n 'Advanced setting: Authentication Service: ' +\n state.getAuthenticationService(),\n 'info'\n );\n }\n if (\n state.getAuthenticationHeaderOverrides() &&\n Object.entries(state.getAuthenticationHeaderOverrides()).length\n ) {\n profile.authenticationHeaderOverrides =\n state.getAuthenticationHeaderOverrides();\n printMessage('Advanced setting: Authentication Header Overrides: ', 'info');\n printMessage(state.getAuthenticationHeaderOverrides(), 'info');\n }\n\n // remove the helper key 'tenant'\n delete profile.tenant;\n\n // update profiles\n profiles[state.getHost()] = profile;\n\n // sort profiles\n const orderedProfiles = Object.keys(profiles)\n .sort()\n .reduce((obj, key) => {\n obj[key] = profiles[key];\n return obj;\n }, {});\n\n // save profiles\n saveJsonToFile({\n data: orderedProfiles,\n filename,\n includeMeta: false,\n state,\n });\n verboseMessage(`Saved connection profile ${state.getHost()} in ${filename}`);\n debugMessage(`ConnectionProfileOps.saveConnectionProfile: end [true]`);\n return true;\n}\n\n/**\n * Delete connection profile\n * @param {String} host host tenant host url or unique substring\n */\nexport function deleteConnectionProfile({\n host,\n state,\n}: {\n host: string;\n state: State;\n}) {\n const filename = getConnectionProfilesPath({ state });\n let connectionsData: ConnectionsFileInterface = {};\n fs.stat(filename, (err) => {\n if (err == null) {\n const data = fs.readFileSync(filename, 'utf8');\n connectionsData = JSON.parse(data);\n const profiles = findConnectionProfiles({\n connectionProfiles: connectionsData,\n host,\n });\n if (profiles.length == 1) {\n delete connectionsData[profiles[0].tenant];\n fs.writeFileSync(filename, JSON.stringify(connectionsData, null, 2));\n printMessage(`Deleted connection profile ${profiles[0].tenant}`);\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\n/**\n * Create a new service account using auto-generated parameters\n * @returns {Promise<IdObjectSkeletonInterface>} A promise resolving to a service account object\n */\nexport async function addNewServiceAccount({\n state,\n}: {\n state: State;\n}): Promise<IdObjectSkeletonInterface> {\n debugMessage(`ConnectionProfileOps.addNewServiceAccount: start`);\n const name = `Frodo-SA-${new Date().getTime()}`;\n debugMessage(`ConnectionProfileOps.addNewServiceAccount: name=${name}...`);\n const description = `${state.getUsername()}'s Frodo Service Account`;\n const scope = ['fr:am:*', 'fr:idm:*', 'fr:idc:esv:*'];\n const jwkPrivate = await createJwkRsa();\n const jwkPublic = await getJwkRsaPublic(jwkPrivate);\n const jwks = createJwks(jwkPublic);\n const sa = await createServiceAccount({\n name,\n description,\n accountStatus: 'Active',\n scopes: scope,\n jwks,\n state,\n });\n debugMessage(`ConnectionProfileOps.addNewServiceAccount: id=${sa._id}`);\n state.setServiceAccountId(sa._id);\n state.setServiceAccountJwk(jwkPrivate);\n debugMessage(`ConnectionProfileOps.addNewServiceAccount: end`);\n return sa;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ops/ConnectionProfileOps.ts"],"names":[],"mappings":"AAMA,OAAO,EAA6C,MAAM,EAAE,MAAM,WAAW,CAAC;AAK9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAG5D,OAAO,KAAK,MAAM,i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CACd,GAAG,OAAO,CAAC,OAAO,CAAC,CA0JnB;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;CACd,QAuDA;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAkCrC","file":"ConnectionProfileOps.d.ts","sourcesContent":["import fs from 'fs';\nimport os from 'os';\nimport path from 'path';\nimport DataProtection from './utils/DataProtection';\nimport { debugMessage, printMessage, verboseMessage } from './utils/Console';\nimport { FRODO_CONNECTION_PROFILES_PATH_KEY } from '../storage/StaticStorage';\nimport { createJwkRsa, createJwks, getJwkRsaPublic, JwkRsa } from './JoseOps';\nimport {\n createServiceAccount,\n getServiceAccount,\n} from './cloud/ServiceAccountOps';\nimport { IdObjectSkeletonInterface } from '../api/ApiTypes';\nimport { saveJsonToFile } from './utils/ExportImportUtils';\nimport { isValidUrl } from './utils/OpsUtils';\nimport State from '../shared/State';\n\nexport default class ConnectionProfileOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get connection profiles file name\n * @returns {string} connection profiles file name\n */\n getConnectionProfilesPath(): string {\n return getConnectionProfilesPath({ state: this.state });\n }\n\n /**\n * Find connection profiles\n * @param {ConnectionsFileInterface} connectionProfiles connection profile object\n * @param {string} host host url or unique substring\n * @returns {SecureConnectionProfileInterface[]} Array of connection profiles\n */\n findConnectionProfiles(\n connectionProfiles: ConnectionsFileInterface,\n host: string\n ): SecureConnectionProfileInterface[] {\n return findConnectionProfiles({\n connectionProfiles,\n host,\n state: this.state,\n });\n }\n\n /**\n * Initialize connection profiles\n *\n * This method is called from app.ts and runs before any of the message handlers are registered.\n * Therefore none of the Console message functions will produce any output.\n */\n async initConnectionProfiles() {\n initConnectionProfiles({ state: this.state });\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 */\n async getConnectionProfileByHost(\n host: string\n ): Promise<ConnectionProfileInterface> {\n return getConnectionProfileByHost({ host, state: this.state });\n }\n\n /**\n * Get connection profile\n * @returns {Object} connection profile or null\n */\n async getConnectionProfile(): Promise<ConnectionProfileInterface> {\n return getConnectionProfile({ state: this.state });\n }\n\n /**\n * Save connection profile\n * @param {string} host host url for new profiles or unique substring for existing profiles\n * @returns {Promise<boolean>} true if the operation succeeded, false otherwise\n */\n async saveConnectionProfile(host: string): Promise<boolean> {\n return saveConnectionProfile({ host, state: this.state });\n }\n\n /**\n * Delete connection profile\n * @param {string} host host tenant host url or unique substring\n */\n deleteConnectionProfile(host: string): void {\n deleteConnectionProfile({ host, state: this.state });\n }\n\n /**\n * Create a new service account using auto-generated parameters\n * @returns {Promise<IdObjectSkeletonInterface>} A promise resolving to a service account object\n */\n async addNewServiceAccount(): Promise<IdObjectSkeletonInterface> {\n return addNewServiceAccount({ state: this.state });\n }\n}\n\nconst fileOptions = {\n indentation: 4,\n};\n\nexport interface SecureConnectionProfileInterface {\n tenant: string;\n username?: string | null;\n encodedPassword?: string | null;\n logApiKey?: string | null;\n encodedLogApiSecret?: string | null;\n authenticationService?: string | null;\n authenticationHeaderOverrides?: Record<string, string>;\n svcacctId?: string | null;\n encodedSvcacctJwk?: string | null;\n svcacctName?: string | null;\n}\n\nexport interface ConnectionProfileInterface {\n tenant: string;\n username?: string | null;\n password?: string | null;\n logApiKey?: string | null;\n logApiSecret?: string | null;\n authenticationService?: string | null;\n authenticationHeaderOverrides?: Record<string, string>;\n svcacctId?: string | null;\n svcacctJwk?: JwkRsa;\n svcacctName?: string | null;\n}\n\nexport interface ConnectionsFileInterface {\n [key: string]: SecureConnectionProfileInterface;\n}\n\nconst legacyProfileFilename = '.frodorc';\nconst newProfileFilename = 'Connections.json';\n\n/**\n * Get connection profiles file name\n * @param {State} state library state\n * @returns {String} connection profiles file name\n */\nexport function getConnectionProfilesPath({ state }: { state: State }): string {\n return (\n state.getConnectionProfilesPath() ||\n process.env[FRODO_CONNECTION_PROFILES_PATH_KEY] ||\n `${os.homedir()}/.frodo/${newProfileFilename}`\n );\n}\n\n/**\n * Find connection profiles\n * @param {ConnectionsFileInterface} connectionProfiles connection profile object\n * @param {string} host host url or unique substring\n * @param {State} state library state\n * @returns {SecureConnectionProfileInterface[]} Array of connection profiles\n */\nfunction findConnectionProfiles({\n connectionProfiles,\n host,\n state,\n}: {\n connectionProfiles: ConnectionsFileInterface;\n host: string;\n state: State;\n}): SecureConnectionProfileInterface[] {\n const profiles: SecureConnectionProfileInterface[] = [];\n for (const tenant in connectionProfiles) {\n debugMessage({\n message: `ConnectionProfileOps.findConnectionProfiles: tenant=${tenant}`,\n state,\n });\n if (tenant.includes(host)) {\n debugMessage({\n message: `ConnectionProfileOps.findConnectionProfiles: '${host}' identifies '${tenant}', including in result set`,\n state,\n });\n const foundProfile = { ...connectionProfiles[tenant] };\n foundProfile.tenant = tenant;\n profiles.push(foundProfile);\n }\n }\n return profiles;\n}\n\n/**\n * Migrate from .frodorc to Connections.json\n */\nfunction migrateFromLegacyProfile() {\n const legacyPath = `${os.homedir()}/.frodo/${legacyProfileFilename}`;\n const newPath = `${os.homedir()}/.frodo/${newProfileFilename}`;\n if (!fs.existsSync(legacyPath) && !fs.existsSync(newPath)) {\n // no connections file (old or new), create empty new one\n fs.writeFileSync(\n newPath,\n JSON.stringify({}, null, fileOptions.indentation)\n );\n } else if (fs.existsSync(legacyPath) && !fs.existsSync(newPath)) {\n // old exists, new one does not - so copy old to new one\n fs.copyFileSync(legacyPath, newPath);\n // for now, just add a \"deprecated\" suffix. May delete the old file\n // in a future release\n fs.renameSync(legacyPath, `${legacyPath}.deprecated`);\n }\n // in other cases, where\n // (both old and new exist) OR (only new one exists) don't do anything\n}\n\n/**\n * Initialize connection profiles\n *\n * This method is called from app.ts and runs before any of the message handlers are registered.\n * Therefore none of the Console message functions will produce any output.\n * @param {State} state library state\n */\nexport async function initConnectionProfiles({ state }: { state: State }) {\n const dataProtection = new DataProtection({\n pathToMasterKey: state.getMasterKeyPath(),\n state,\n });\n // create connections.json file if it doesn't exist\n const filename = getConnectionProfilesPath({ state });\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 and logApiSecret from clear text to aes-256-GCM\n else {\n migrateFromLegacyProfile();\n const data = fs.readFileSync(filename, 'utf8');\n const connectionsData: ConnectionsFileInterface = JSON.parse(data);\n let convert = false;\n for (const conn of Object.keys(connectionsData)) {\n if (connectionsData[conn]['password']) {\n convert = true;\n connectionsData[conn].encodedPassword = await dataProtection.encrypt(\n connectionsData[conn]['password']\n );\n delete connectionsData[conn]['password'];\n }\n if (connectionsData[conn]['logApiSecret']) {\n convert = true;\n connectionsData[conn].encodedLogApiSecret =\n await dataProtection.encrypt(connectionsData[conn]['logApiSecret']);\n delete connectionsData[conn]['logApiSecret'];\n }\n if (connectionsData[conn]['svcacctJwk']) {\n convert = true;\n connectionsData[conn].encodedSvcacctJwk = await dataProtection.encrypt(\n connectionsData[conn]['svcacctJwk']\n );\n delete connectionsData[conn]['svcacctJwk'];\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 * @param {State} state library state\n * @returns {Object} connection profile or null\n */\nexport async function getConnectionProfileByHost({\n host,\n state,\n}: {\n host: string;\n state: State;\n}): Promise<ConnectionProfileInterface> {\n try {\n const dataProtection = new DataProtection({\n pathToMasterKey: state.getMasterKeyPath(),\n state,\n });\n const filename = getConnectionProfilesPath({ state });\n const connectionsData = JSON.parse(fs.readFileSync(filename, 'utf8'));\n const profiles = findConnectionProfiles({\n connectionProfiles: connectionsData,\n host,\n state,\n });\n if (profiles.length == 0) {\n printMessage({\n message: `Profile for ${host} not found. Please specify credentials on command line`,\n type: 'error',\n state,\n });\n return null;\n }\n if (profiles.length > 1) {\n printMessage({\n message: `Multiple matching profiles found.`,\n type: 'error',\n state,\n });\n profiles.forEach((p) => {\n printMessage({ message: `- ${p.tenant}`, type: 'error', state });\n });\n printMessage({\n message: `Please specify a unique sub-string`,\n type: 'error',\n state,\n });\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 logApiKey: profiles[0].logApiKey ? profiles[0].logApiKey : null,\n logApiSecret: profiles[0].encodedLogApiSecret\n ? await dataProtection.decrypt(profiles[0].encodedLogApiSecret)\n : null,\n authenticationService: profiles[0].authenticationService\n ? profiles[0].authenticationService\n : null,\n authenticationHeaderOverrides: profiles[0].authenticationHeaderOverrides\n ? profiles[0].authenticationHeaderOverrides\n : {},\n svcacctName: profiles[0].svcacctName ? profiles[0].svcacctName : null,\n svcacctId: profiles[0].svcacctId ? profiles[0].svcacctId : null,\n svcacctJwk: profiles[0].encodedSvcacctJwk\n ? await dataProtection.decrypt(profiles[0].encodedSvcacctJwk)\n : null,\n };\n } catch (e) {\n printMessage({\n message: `Can not read saved connection info, please specify credentials on command line: ${e}`,\n type: 'error',\n state,\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 state,\n}: {\n state: State;\n}): Promise<ConnectionProfileInterface> {\n return getConnectionProfileByHost({ host: state.getHost(), state });\n}\n\n/**\n * Save connection profile\n * @param {string} host host url for new profiles or unique substring for existing profiles\n * @returns {Promise<boolean>} true if the operation succeeded, false otherwise\n */\nexport async function saveConnectionProfile({\n host,\n state,\n}: {\n host: string;\n state: State;\n}): Promise<boolean> {\n debugMessage({\n message: `ConnectionProfileOps.saveConnectionProfile: start`,\n state,\n });\n const dataProtection = new DataProtection({\n pathToMasterKey: state.getMasterKeyPath(),\n state,\n });\n const filename = getConnectionProfilesPath({ state });\n debugMessage({ message: `Saving connection profile in ${filename}`, state });\n let profiles: ConnectionsFileInterface = {};\n let profile: SecureConnectionProfileInterface = { tenant: '' };\n try {\n fs.statSync(filename);\n const data = fs.readFileSync(filename, 'utf8');\n profiles = JSON.parse(data);\n\n // find tenant\n const found = findConnectionProfiles({\n connectionProfiles: profiles,\n host,\n state,\n });\n\n // replace tenant in session with real tenant url if necessary\n if (found.length === 1) {\n profile = found[0];\n state.setHost(profile.tenant);\n verboseMessage({ message: `Existing profile: ${profile.tenant}`, state });\n debugMessage({ message: profile, state });\n }\n\n // connection profile not found, validate host is a real URL\n if (found.length === 0) {\n if (isValidUrl(host)) {\n state.setHost(host);\n debugMessage({ message: `New profile: ${host}`, state });\n } else {\n printMessage({\n message: `No existing profile found matching '${host}'. Provide a valid URL as the host argument to create a new profile.`,\n type: 'error',\n state,\n });\n debugMessage({\n message: `ConnectionProfileOps.saveConnectionProfile: end [false]`,\n state,\n });\n return false;\n }\n }\n } catch (error) {\n debugMessage({\n message: `New profiles file ${filename} with new profile ${host}`,\n state,\n });\n }\n\n // user account\n if (state.getUsername()) profile.username = state.getUsername();\n if (state.getPassword())\n profile.encodedPassword = await dataProtection.encrypt(state.getPassword());\n\n // log API\n if (state.getLogApiKey()) profile.logApiKey = state.getLogApiKey();\n if (state.getLogApiSecret())\n profile.encodedLogApiSecret = await dataProtection.encrypt(\n state.getLogApiSecret()\n );\n\n // service account\n if (state.getServiceAccountId()) {\n profile.svcacctId = state.getServiceAccountId();\n profile.svcacctName = (\n await getServiceAccount({\n serviceAccountId: state.getServiceAccountId(),\n state,\n })\n ).name;\n }\n if (state.getServiceAccountJwk())\n profile.encodedSvcacctJwk = await dataProtection.encrypt(\n state.getServiceAccountJwk()\n );\n // update existing service account profile\n if (profile.svcacctId && !profile.svcacctName) {\n profile.svcacctName = (\n await getServiceAccount({ serviceAccountId: profile.svcacctId, state })\n ).name;\n debugMessage({\n message: `ConnectionProfileOps.saveConnectionProfile: added missing service account name`,\n state,\n });\n }\n\n // advanced settings\n if (state.getAuthenticationService()) {\n profile.authenticationService = state.getAuthenticationService();\n printMessage({\n message:\n 'Advanced setting: Authentication Service: ' +\n state.getAuthenticationService(),\n type: 'info',\n state,\n });\n }\n if (\n state.getAuthenticationHeaderOverrides() &&\n Object.entries(state.getAuthenticationHeaderOverrides()).length\n ) {\n profile.authenticationHeaderOverrides =\n state.getAuthenticationHeaderOverrides();\n printMessage({\n message: 'Advanced setting: Authentication Header Overrides: ',\n type: 'info',\n state,\n });\n printMessage({\n message: state.getAuthenticationHeaderOverrides(),\n type: 'info',\n state,\n });\n }\n\n // remove the helper key 'tenant'\n delete profile.tenant;\n\n // update profiles\n profiles[state.getHost()] = profile;\n\n // sort profiles\n const orderedProfiles = Object.keys(profiles)\n .sort()\n .reduce((obj, key) => {\n obj[key] = profiles[key];\n return obj;\n }, {});\n\n // save profiles\n saveJsonToFile({\n data: orderedProfiles,\n filename,\n includeMeta: false,\n state,\n });\n verboseMessage({\n message: `Saved connection profile ${state.getHost()} in ${filename}`,\n state,\n });\n debugMessage({\n message: `ConnectionProfileOps.saveConnectionProfile: end [true]`,\n state,\n });\n return true;\n}\n\n/**\n * Delete connection profile\n * @param {String} host host tenant host url or unique substring\n */\nexport function deleteConnectionProfile({\n host,\n state,\n}: {\n host: string;\n state: State;\n}) {\n const filename = getConnectionProfilesPath({ state });\n let connectionsData: ConnectionsFileInterface = {};\n fs.stat(filename, (err) => {\n if (err == null) {\n const data = fs.readFileSync(filename, 'utf8');\n connectionsData = JSON.parse(data);\n const profiles = findConnectionProfiles({\n connectionProfiles: connectionsData,\n host,\n state,\n });\n if (profiles.length == 1) {\n delete connectionsData[profiles[0].tenant];\n fs.writeFileSync(filename, JSON.stringify(connectionsData, null, 2));\n printMessage({\n message: `Deleted connection profile ${profiles[0].tenant}`,\n state,\n });\n } else {\n if (profiles.length > 1) {\n printMessage({\n message: `Multiple matching profiles found.`,\n type: 'error',\n state,\n });\n profiles.forEach((p) => {\n printMessage({ message: `- ${p.tenant}`, type: 'error', state });\n });\n printMessage({\n message: `Please specify a unique sub-string`,\n type: 'error',\n state,\n });\n return null;\n } else {\n printMessage({\n message: `No connection profile ${host} found`,\n state,\n });\n }\n }\n } else if (err.code === 'ENOENT') {\n printMessage({\n message: `Connection profile file ${filename} not found`,\n state,\n });\n } else {\n printMessage({\n message: `Error in deleting connection profile: ${err.code}`,\n type: 'error',\n state,\n });\n }\n });\n}\n\n/**\n * Create a new service account using auto-generated parameters\n * @returns {Promise<IdObjectSkeletonInterface>} A promise resolving to a service account object\n */\nexport async function addNewServiceAccount({\n state,\n}: {\n state: State;\n}): Promise<IdObjectSkeletonInterface> {\n debugMessage({\n message: `ConnectionProfileOps.addNewServiceAccount: start`,\n state,\n });\n const name = `Frodo-SA-${new Date().getTime()}`;\n debugMessage({\n message: `ConnectionProfileOps.addNewServiceAccount: name=${name}...`,\n state,\n });\n const description = `${state.getUsername()}'s Frodo Service Account`;\n const scope = ['fr:am:*', 'fr:idm:*', 'fr:idc:esv:*'];\n const jwkPrivate = await createJwkRsa();\n const jwkPublic = await getJwkRsaPublic(jwkPrivate);\n const jwks = createJwks(jwkPublic);\n const sa = await createServiceAccount({\n name,\n description,\n accountStatus: 'Active',\n scopes: scope,\n jwks,\n state,\n });\n debugMessage({\n message: `ConnectionProfileOps.addNewServiceAccount: id=${sa._id}`,\n state,\n });\n state.setServiceAccountId(sa._id);\n state.setServiceAccountJwk(jwkPrivate);\n debugMessage({\n message: `ConnectionProfileOps.addNewServiceAccount: end`,\n state,\n });\n return sa;\n}\n"]}
|
|
@@ -3,6 +3,10 @@ import State from '../shared/State';
|
|
|
3
3
|
export default class EmailTemplateOps {
|
|
4
4
|
state: State;
|
|
5
5
|
constructor(state: State);
|
|
6
|
+
/**
|
|
7
|
+
* Email template type key used to build the IDM id: 'emailTemplate/<id>'
|
|
8
|
+
*/
|
|
9
|
+
EMAIL_TEMPLATE_TYPE: string;
|
|
6
10
|
/**
|
|
7
11
|
* Get all email templates
|
|
8
12
|
* @returns {Promise} a promise that resolves to an array of email template objects
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ops/EmailTemplateOps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC5B,MAAM,iBAAiB,CAAC;AAMzB,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,iBAAiB;IAIvB;;;;OAIG;IACG,gBAAgB,CAAC,UAAU,EAAE,MAAM;IAIzC;;;;;OAKG;IACG,gBAAgB,CACpB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,qBAAqB;CAItC;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AAEnD;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,gBAElE;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;CACd,gBAKA;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,UAAU,EACV,YAAY,EACZ,KAAK,GACN,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,qBAAqB,GAAG,2BAA2B,CAAC;IAClE,KAAK,EAAE,KAAK,CAAC;CACd,gBAMA","file":"EmailTemplateOps.d.ts","sourcesContent":["import {\n EmailTemplateSkeleton,\n NoIdObjectSkeletonInterface,\n} from '../api/ApiTypes';\nimport {\n getConfigEntitiesByType,\n getConfigEntity,\n putConfigEntity,\n} from '../api/IdmConfigApi';\nimport State from '../shared/State';\n\nexport default class EmailTemplateOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Get all email templates\n * @returns {Promise} a promise that resolves to an array of email template objects\n */\n async getEmailTemplates() {\n return getEmailTemplates({ state: this.state });\n }\n\n /**\n * Get email template\n * @param {string} templateId id/name of the email template without the type prefix\n * @returns {Promise} a promise that resolves an email template object\n */\n async getEmailTemplate(templateId: string) {\n return getEmailTemplate({ templateId, state: this.state });\n }\n\n /**\n * Put email template\n * @param {string} templateId id/name of the email template without the type prefix\n * @param {Object} templateData email template object\n * @returns {Promise} a promise that resolves to an email template object\n */\n async putEmailTemplate(\n templateId: string,\n templateData: EmailTemplateSkeleton\n ) {\n return putEmailTemplate({ templateId, templateData, state: this.state });\n }\n}\n\n/**\n * Email template type key used to build the IDM id: 'emailTemplate/<id>'\n */\nexport const EMAIL_TEMPLATE_TYPE = 'emailTemplate';\n\n/**\n * Get all email templates\n * @returns {Promise} a promise that resolves to an array of email template objects\n */\nexport async function getEmailTemplates({ state }: { state: State }) {\n return getConfigEntitiesByType({ type: EMAIL_TEMPLATE_TYPE, state });\n}\n\n/**\n * Get email template\n * @param {string} templateId id/name of the email template without the type prefix\n * @returns {Promise} a promise that resolves an email template object\n */\nexport async function getEmailTemplate({\n templateId,\n state,\n}: {\n templateId: string;\n state: State;\n}) {\n return getConfigEntity({\n entityId: `${EMAIL_TEMPLATE_TYPE}/${templateId}`,\n state,\n });\n}\n\n/**\n * Put email template\n * @param {string} templateId id/name of the email template without the type prefix\n * @param {Object} templateData email template object\n * @returns {Promise} a promise that resolves to an email template object\n */\nexport async function putEmailTemplate({\n templateId,\n templateData,\n state,\n}: {\n templateId: string;\n templateData: EmailTemplateSkeleton | NoIdObjectSkeletonInterface;\n state: State;\n}) {\n return putConfigEntity({\n entityId: `${EMAIL_TEMPLATE_TYPE}/${templateId}`,\n entityData: templateData,\n state,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ops/EmailTemplateOps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC5B,MAAM,iBAAiB,CAAC;AAMzB,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;OAEG;IACH,mBAAmB,SAAuB;IAE1C;;;OAGG;IACG,iBAAiB;IAIvB;;;;OAIG;IACG,gBAAgB,CAAC,UAAU,EAAE,MAAM;IAIzC;;;;;OAKG;IACG,gBAAgB,CACpB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,qBAAqB;CAItC;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AAEnD;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,gBAElE;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,UAAU,EACV,KAAK,GACN,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;CACd,gBAKA;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,UAAU,EACV,YAAY,EACZ,KAAK,GACN,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,qBAAqB,GAAG,2BAA2B,CAAC;IAClE,KAAK,EAAE,KAAK,CAAC;CACd,gBAMA","file":"EmailTemplateOps.d.ts","sourcesContent":["import {\n EmailTemplateSkeleton,\n NoIdObjectSkeletonInterface,\n} from '../api/ApiTypes';\nimport {\n getConfigEntitiesByType,\n getConfigEntity,\n putConfigEntity,\n} from '../api/IdmConfigApi';\nimport State from '../shared/State';\n\nexport default class EmailTemplateOps {\n state: State;\n constructor(state: State) {\n this.state = state;\n }\n\n /**\n * Email template type key used to build the IDM id: 'emailTemplate/<id>'\n */\n EMAIL_TEMPLATE_TYPE = EMAIL_TEMPLATE_TYPE;\n\n /**\n * Get all email templates\n * @returns {Promise} a promise that resolves to an array of email template objects\n */\n async getEmailTemplates() {\n return getEmailTemplates({ state: this.state });\n }\n\n /**\n * Get email template\n * @param {string} templateId id/name of the email template without the type prefix\n * @returns {Promise} a promise that resolves an email template object\n */\n async getEmailTemplate(templateId: string) {\n return getEmailTemplate({ templateId, state: this.state });\n }\n\n /**\n * Put email template\n * @param {string} templateId id/name of the email template without the type prefix\n * @param {Object} templateData email template object\n * @returns {Promise} a promise that resolves to an email template object\n */\n async putEmailTemplate(\n templateId: string,\n templateData: EmailTemplateSkeleton\n ) {\n return putEmailTemplate({ templateId, templateData, state: this.state });\n }\n}\n\n/**\n * Email template type key used to build the IDM id: 'emailTemplate/<id>'\n */\nexport const EMAIL_TEMPLATE_TYPE = 'emailTemplate';\n\n/**\n * Get all email templates\n * @returns {Promise} a promise that resolves to an array of email template objects\n */\nexport async function getEmailTemplates({ state }: { state: State }) {\n return getConfigEntitiesByType({ type: EMAIL_TEMPLATE_TYPE, state });\n}\n\n/**\n * Get email template\n * @param {string} templateId id/name of the email template without the type prefix\n * @returns {Promise} a promise that resolves an email template object\n */\nexport async function getEmailTemplate({\n templateId,\n state,\n}: {\n templateId: string;\n state: State;\n}) {\n return getConfigEntity({\n entityId: `${EMAIL_TEMPLATE_TYPE}/${templateId}`,\n state,\n });\n}\n\n/**\n * Put email template\n * @param {string} templateId id/name of the email template without the type prefix\n * @param {Object} templateData email template object\n * @returns {Promise} a promise that resolves to an email template object\n */\nexport async function putEmailTemplate({\n templateId,\n templateData,\n state,\n}: {\n templateId: string;\n templateData: EmailTemplateSkeleton | NoIdObjectSkeletonInterface;\n state: State;\n}) {\n return putConfigEntity({\n entityId: `${EMAIL_TEMPLATE_TYPE}/${templateId}`,\n entityData: templateData,\n state,\n });\n}\n"]}
|