@rockcarver/frodo-lib 2.0.0-1 → 2.0.0-2

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/cjs/api/ApiTypes.js.map +1 -1
  3. package/cjs/index.js +1 -105
  4. package/cjs/index.js.map +1 -1
  5. package/cjs/lib/FrodoLib.js +20 -20
  6. package/cjs/lib/FrodoLib.js.map +1 -1
  7. package/cjs/ops/AgentOps.js +8 -0
  8. package/cjs/ops/AgentOps.js.map +1 -1
  9. package/cjs/ops/AuthenticateOps.js +33 -6
  10. package/cjs/ops/AuthenticateOps.js.map +1 -1
  11. package/cjs/ops/CirclesOfTrustOps.js +36 -10
  12. package/cjs/ops/CirclesOfTrustOps.js.map +1 -1
  13. package/cjs/ops/ConnectionProfileOps.js +13 -126
  14. package/cjs/ops/ConnectionProfileOps.js.map +1 -1
  15. package/cjs/ops/IdmOps.js.map +1 -1
  16. package/cjs/ops/JourneyOps.js.map +1 -1
  17. package/cjs/ops/OAuth2OidcOps.js +84 -0
  18. package/cjs/ops/OAuth2OidcOps.js.map +1 -0
  19. package/cjs/ops/ResourceTypeOps.js +65 -49
  20. package/cjs/ops/ResourceTypeOps.js.map +1 -1
  21. package/cjs/ops/ServiceOps.js +3 -0
  22. package/cjs/ops/ServiceOps.js.map +1 -1
  23. package/cjs/ops/ThemeOps.js +28 -14
  24. package/cjs/ops/ThemeOps.js.map +1 -1
  25. package/cjs/ops/cloud/LogOps.js +3 -13
  26. package/cjs/ops/cloud/LogOps.js.map +1 -1
  27. package/cjs/ops/utils/Console.js +7 -7
  28. package/cjs/ops/utils/Console.js.map +1 -1
  29. package/cjs/ops/utils/ExportImportUtils.js +109 -0
  30. package/cjs/ops/utils/ExportImportUtils.js.map +1 -1
  31. package/cjs/ops/utils/ExportImportUtils.test.js.map +1 -1
  32. package/cjs/ops/utils/Version.js +29 -6
  33. package/cjs/ops/utils/Version.js.map +1 -1
  34. package/cjs/ops/utils/Version.test.js.map +1 -1
  35. package/cjs/shared/State.js +0 -2
  36. package/cjs/shared/State.js.map +1 -1
  37. package/esm/index.mjs +1 -59
  38. package/esm/lib/FrodoLib.mjs +19 -18
  39. package/esm/ops/AgentOps.mjs +8 -0
  40. package/esm/ops/AuthenticateOps.mjs +24 -4
  41. package/esm/ops/CirclesOfTrustOps.mjs +18 -2
  42. package/esm/ops/ConnectionProfileOps.mjs +1 -105
  43. package/esm/ops/OAuth2OidcOps.mjs +40 -0
  44. package/esm/ops/ResourceTypeOps.mjs +14 -4
  45. package/esm/ops/ServiceOps.mjs +3 -0
  46. package/esm/ops/ThemeOps.mjs +7 -7
  47. package/esm/ops/cloud/LogOps.mjs +3 -13
  48. package/esm/ops/utils/Console.mjs +8 -8
  49. package/esm/ops/utils/ExportImportUtils.mjs +101 -0
  50. package/esm/ops/utils/ExportImportUtils.test.mjs +15 -2
  51. package/esm/ops/utils/Version.mjs +21 -4
  52. package/esm/ops/utils/Version.test.mjs +4 -1
  53. package/esm/shared/State.mjs +0 -2
  54. package/package.json +1 -1
  55. package/types/api/ApiTypes.d.ts +11 -11
  56. package/types/api/ApiTypes.d.ts.map +1 -1
  57. package/types/index.d.ts +1 -48
  58. package/types/index.d.ts.map +1 -1
  59. package/types/lib/FrodoLib.d.ts +13 -9
  60. package/types/lib/FrodoLib.d.ts.map +1 -1
  61. package/types/ops/AgentOps.d.ts +5 -0
  62. package/types/ops/AgentOps.d.ts.map +1 -1
  63. package/types/ops/AuthenticateOps.d.ts +11 -1
  64. package/types/ops/AuthenticateOps.d.ts.map +1 -1
  65. package/types/ops/CirclesOfTrustOps.d.ts +16 -2
  66. package/types/ops/CirclesOfTrustOps.d.ts.map +1 -1
  67. package/types/ops/ConnectionProfileOps.d.ts +0 -19
  68. package/types/ops/ConnectionProfileOps.d.ts.map +1 -1
  69. package/types/ops/IdmOps.d.ts +1 -1
  70. package/types/ops/IdmOps.d.ts.map +1 -1
  71. package/types/ops/JourneyOps.d.ts +2 -2
  72. package/types/ops/JourneyOps.d.ts.map +1 -1
  73. package/types/ops/OAuth2OidcOps.d.ts +11 -0
  74. package/types/ops/OAuth2OidcOps.d.ts.map +1 -0
  75. package/types/ops/ResourceTypeOps.d.ts +3 -3
  76. package/types/ops/ResourceTypeOps.d.ts.map +1 -1
  77. package/types/ops/ServiceOps.d.ts +1 -0
  78. package/types/ops/ServiceOps.d.ts.map +1 -1
  79. package/types/ops/ThemeOps.d.ts +14 -14
  80. package/types/ops/ThemeOps.d.ts.map +1 -1
  81. package/types/ops/cloud/LogOps.d.ts +1 -1
  82. package/types/ops/cloud/LogOps.d.ts.map +1 -1
  83. package/types/ops/utils/Console.d.ts.map +1 -1
  84. package/types/ops/utils/ExportImportUtils.d.ts +43 -0
  85. package/types/ops/utils/ExportImportUtils.d.ts.map +1 -1
  86. package/types/ops/utils/Version.d.ts +16 -2
  87. package/types/ops/utils/Version.d.ts.map +1 -1
  88. package/types/shared/State.d.ts.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/FrodoLib.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,eAAe,MAAM,wBAAwB,CAAC;AACrD,OAAO,iBAAiB,MAAM,0BAA0B,CAAC;AACzD,OAAO,oBAAoB,MAAM,6BAA6B,CAAC;AAC/D,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AACvD,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,UAAU,MAAM,mBAAmB,CAAC;AAC3C,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,O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;QAClB,SAAS,EAAE,YAAY,CAAC;QACxB,YAAY,EAAE,eAAe,CAAC;KAC/B,CAAwE;IACzE,KAAK,EAAE;QACL,OAAO,EAAE,UAAU,CAAC;QACpB,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,UAAU,CAAC;QACnB,cAAc,EAAE,iBAAiB,CAAC;QAClC,OAAO,EAAE,UAAU,CAAC;QACpB,QAAQ,EAAE,YAAY,CAAC;KACxB,CAOC;IACF,IAAI,EAAE,oBAAoB,CAAC;IAC3B,KAAK,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAA;KAAE,CAA2B;IAChE,OAAO;;;;;;;;MAQL;IACF,GAAG,EAAE;QACH,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,gBAAgB,CAAC;QAC1B,YAAY,EAAE,eAAe,CAAC;KAC/B,CAAsE;IACvE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,eAAe,CAAQ;IAC9B,UAAU,EAAE;QACV,MAAM,EAAE,eAAe,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,iBAAiB,CAAC;KAC7B,CAAmE;IACpE,KAAK,EAAE,QAAQ,CAAC;IAChB,KAAK,EAAE;QACL,cAAc,EAAE,iBAAiB,CAAC;QAClC,cAAc,EAAE,QAAQ,CAAC;KAC1B,CAA4D;IAC7D,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,QAAQ,CAAC;gBAEJ,MAAM,GAAE,cAAmB;CA8CxC;AAED,eAAO,MAAM,KAAK,UAAiB,CAAC;AACpC,eAAO,MAAM,WAAW,OAAc,CAAC","file":"FrodoLib.d.ts","sourcesContent":["import State, { StateInterface } from '../shared/State';\n\nimport AdminOps from '../ops/AdminOps';\nimport AgentOps from '../ops/AgentOps';\nimport AuthenticateOps from '../ops/AuthenticateOps';\nimport CirclesOfTrustOps from '../ops/CirclesOfTrustOps';\nimport ConnectionProfileOps from '../ops/ConnectionProfileOps';\nimport EmailTemplateOps from '../ops/EmailTemplateOps';\nimport FeatureOps from '../ops/cloud/FeatureOps';\nimport IdmOps from '../ops/IdmOps';\nimport IdpOps from '../ops/IdpOps';\nimport InfoOps from '../ops/InfoOps';\nimport JourneyOps from '../ops/JourneyOps';\nimport LogOps from '../ops/cloud/LogOps';\nimport ManagedObjectOps from '../ops/ManagedObjectOps';\nimport NodeOps from '../ops/NodeOps';\nimport OAuth2ClientOps from '../ops/OAuth2ClientOps';\nimport OAuth2ProviderOps from '../ops/OAuth2ProviderOps';\nimport OrganizationOps from '../ops/OrganizationOps';\nimport PolicyOps from '../ops/PolicyOps';\nimport PolicySetOps from '../ops/PolicySetOps';\nimport RealmOps from '../ops/RealmOps';\nimport ResourceTypeOps from '../ops/ResourceTypeOps';\nimport Saml2Ops from '../ops/Saml2Ops';\nimport ScriptOps from '../ops/ScriptOps';\nimport ServiceOps from '../ops/ServiceOps';\nimport SecretsOps from '../ops/cloud/SecretsOps';\nimport ServiceAccountOps from '../ops/cloud/ServiceAccountOps';\nimport StartupOps from '../ops/cloud/StartupOps';\nimport ThemeOps from '../ops/ThemeOps';\nimport VariablesOps from '../ops/cloud/VariablesOps';\n// TODO: revisit if there are better ways\nimport * as JoseOps from '../ops/JoseOps';\nimport * as OpsUtils from '../ops/utils/OpsUtils';\nimport * as Base64 from '../api/utils/Base64';\nimport * as ScriptValidationUtils from '../ops/utils/ScriptValidationUtils';\nimport * as Version from '../ops/utils/Version';\nimport * as ExportImportUtils from '../ops/utils/ExportImportUtils';\nimport * as constants from '../storage/StaticStorage';\n\nexport class FrodoLib {\n state: State;\n admin: AdminOps;\n agent: AgentOps;\n authn: {\n journey: JourneyOps;\n node: NodeOps;\n } = { journey: undefined, node: undefined };\n authz: {\n policy: PolicyOps;\n policySet: PolicySetOps;\n resourceType: ResourceTypeOps;\n } = { policy: undefined, policySet: undefined, resourceType: undefined };\n cloud: {\n feature: FeatureOps;\n log: LogOps;\n secret: SecretsOps;\n serviceAccount: ServiceAccountOps;\n startup: StartupOps;\n variable: VariablesOps;\n } = {\n feature: undefined,\n log: undefined,\n secret: undefined,\n serviceAccount: undefined,\n startup: undefined,\n variable: undefined,\n };\n conn: ConnectionProfileOps;\n email: { template: EmailTemplateOps } = { template: undefined };\n helpers = {\n jose: JoseOps,\n utils: OpsUtils,\n base64: Base64,\n script: ScriptValidationUtils,\n version: Version,\n exportImportUtils: ExportImportUtils,\n constants: constants,\n };\n idm: {\n config: IdmOps;\n managed: ManagedObjectOps;\n organization: OrganizationOps;\n } = { config: undefined, managed: undefined, organization: undefined };\n info: InfoOps;\n login: AuthenticateOps = null;\n oauth2oidc: {\n client: OAuth2ClientOps;\n external: IdpOps;\n provider: OAuth2ProviderOps;\n } = { client: undefined, external: undefined, provider: undefined };\n realm: RealmOps;\n saml2: {\n circlesOfTrust: CirclesOfTrustOps;\n entityProvider: Saml2Ops;\n } = { circlesOfTrust: undefined, entityProvider: undefined };\n script: ScriptOps;\n service: ServiceOps;\n theme: ThemeOps;\n\n constructor(config: StateInterface = {}) {\n this.state = new State(config);\n\n // initialize all the modules needing state\n this.admin = new AdminOps(this.state);\n this.agent = new AgentOps(this.state);\n\n this.authn.journey = new JourneyOps(this.state);\n this.authn.node = new NodeOps(this.state);\n\n this.authz.policy = new PolicyOps(this.state);\n this.authz.policySet = new PolicySetOps(this.state);\n this.authz.resourceType = new ResourceTypeOps(this.state);\n\n this.cloud.feature = new FeatureOps(this.state);\n this.cloud.log = new LogOps(this.state);\n this.cloud.secret = new SecretsOps(this.state);\n this.cloud.serviceAccount = new ServiceAccountOps(this.state);\n this.cloud.startup = new StartupOps(this.state);\n this.cloud.variable = new VariablesOps(this.state);\n\n this.conn = new ConnectionProfileOps(this.state);\n\n this.email.template = new EmailTemplateOps(this.state);\n\n this.idm.config = new IdmOps(this.state);\n this.idm.managed = new ManagedObjectOps(this.state);\n this.idm.organization = new OrganizationOps(this.state);\n\n this.info = new InfoOps(this.state);\n this.login = new AuthenticateOps(this.state);\n\n this.oauth2oidc.client = new OAuth2ClientOps(this.state);\n this.oauth2oidc.external = new IdpOps(this.state);\n this.oauth2oidc.provider = new OAuth2ProviderOps(this.state);\n\n this.realm = new RealmOps(this.state);\n\n this.saml2.circlesOfTrust = new CirclesOfTrustOps(this.state);\n this.saml2.entityProvider = new Saml2Ops(this.state);\n\n this.script = new ScriptOps(this.state);\n this.service = new ServiceOps(this.state);\n\n this.theme = new ThemeOps(this.state);\n }\n}\n\nexport const frodo = new FrodoLib();\nexport const globalState = frodo.state;\n// frodo.Admin.repairOrgModel(false, true, true);\n// frodo.Cloud.Log.tail('', '');\n// frodo.Info.getInfo();\n// frodo.Saml2.EntityProvider.deleteRawSaml2Provider('');\n// frodo.Authz.Policy.exportPolicy('');\n// frodo.authn.getTokens();\n"]}
1
+ {"version":3,"sources":["../src/lib/FrodoLib.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,eAAe,MAAM,wBAAwB,CAAC;AACrD,OAAO,iBAAiB,MAAM,0BAA0B,CAAC;AACzD,OAAO,oBAAoB,MAAM,6BAA6B,CAAC;AAC/D,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AACvD,OAAO,iBAAiB,MAAM,gCAAgC,CAAC;AAC/D,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,UAAU,MAAM,mBAAmB,CAAC;AAC3C,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AACvD,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO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L,OAAO,EAAE,UAAU,CAAC;QACpB,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,UAAU,CAAC;QACnB,cAAc,EAAE,iBAAiB,CAAC;QAClC,OAAO,EAAE,UAAU,CAAC;QACpB,QAAQ,EAAE,YAAY,CAAC;KACxB,CAOC;IACF,IAAI,EAAE,oBAAoB,CAAC;IAC3B,KAAK,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAA;KAAE,CAA2B;IAChE,MAAM;;;;;;MAMJ;IACF,GAAG,EAAE;QACH,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,gBAAgB,CAAC;QAC1B,YAAY,EAAE,eAAe,CAAC;KAC/B,CAAsE;IACvE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,eAAe,CAAQ;IAC9B,UAAU,EAAE;QACV,MAAM,EAAE,eAAe,CAAC;QACxB,QAAQ,EAAE,aAAa,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,iBAAiB,CAAC;KAC7B,CAKC;IACF,KAAK,EAAE,QAAQ,CAAC;IAChB,KAAK,EAAE;QACL,cAAc,EAAE,iBAAiB,CAAC;QAClC,cAAc,EAAE,QAAQ,CAAC;KAC1B,CAA4D;IAC7D,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,QAAQ,CAAC;IAChB,KAAK,EAAE;QACL,KAAK,EAAE,iBAAiB,CAAC;QACzB,OAAO,EAAE,OAAO,CAAC;KAClB,CAA4C;gBAEjC,MAAM,GAAE,cAAmB;CAiDxC;AAED,eAAO,MAAM,KAAK,UAAiB,CAAC;AACpC,eAAO,MAAM,KAAK,OAAc,CAAC","file":"FrodoLib.d.ts","sourcesContent":["// instantiable modules\nimport State, { StateInterface } from '../shared/State';\nimport AdminOps from '../ops/AdminOps';\nimport AgentOps from '../ops/AgentOps';\nimport AuthenticateOps from '../ops/AuthenticateOps';\nimport CirclesOfTrustOps from '../ops/CirclesOfTrustOps';\nimport ConnectionProfileOps from '../ops/ConnectionProfileOps';\nimport EmailTemplateOps from '../ops/EmailTemplateOps';\nimport ExportImportUtils from '../ops/utils/ExportImportUtils';\nimport FeatureOps from '../ops/cloud/FeatureOps';\nimport IdmOps from '../ops/IdmOps';\nimport IdpOps from '../ops/IdpOps';\nimport InfoOps from '../ops/InfoOps';\nimport JourneyOps from '../ops/JourneyOps';\nimport LogOps from '../ops/cloud/LogOps';\nimport ManagedObjectOps from '../ops/ManagedObjectOps';\nimport NodeOps from '../ops/NodeOps';\nimport OAuth2ClientOps from '../ops/OAuth2ClientOps';\nimport OAuth2OidcOps from '../ops/OAuth2OidcOps';\nimport OAuth2ProviderOps from '../ops/OAuth2ProviderOps';\nimport OrganizationOps from '../ops/OrganizationOps';\nimport PolicyOps from '../ops/PolicyOps';\nimport PolicySetOps from '../ops/PolicySetOps';\nimport RealmOps from '../ops/RealmOps';\nimport ResourceTypeOps from '../ops/ResourceTypeOps';\nimport Saml2Ops from '../ops/Saml2Ops';\nimport ScriptOps from '../ops/ScriptOps';\nimport ServiceOps from '../ops/ServiceOps';\nimport SecretsOps from '../ops/cloud/SecretsOps';\nimport ServiceAccountOps from '../ops/cloud/ServiceAccountOps';\nimport StartupOps from '../ops/cloud/StartupOps';\nimport ThemeOps from '../ops/ThemeOps';\nimport VariablesOps from '../ops/cloud/VariablesOps';\nimport Version from '../ops/utils/Version';\n\n// non-instantiable modules\nimport * as JoseOps from '../ops/JoseOps';\nimport * as OpsUtils from '../ops/utils/OpsUtils';\nimport * as Base64 from '../api/utils/Base64';\nimport * as ScriptValidationUtils from '../ops/utils/ScriptValidationUtils';\nimport * as constants from '../storage/StaticStorage';\n\nexport class FrodoLib {\n state: State;\n admin: AdminOps;\n agent: AgentOps;\n authn: {\n journey: JourneyOps;\n node: NodeOps;\n } = { journey: undefined, node: undefined };\n authz: {\n policy: PolicyOps;\n policySet: PolicySetOps;\n resourceType: ResourceTypeOps;\n } = { policy: undefined, policySet: undefined, resourceType: undefined };\n cloud: {\n feature: FeatureOps;\n log: LogOps;\n secret: SecretsOps;\n serviceAccount: ServiceAccountOps;\n startup: StartupOps;\n variable: VariablesOps;\n } = {\n feature: undefined,\n log: undefined,\n secret: undefined,\n serviceAccount: undefined,\n startup: undefined,\n variable: undefined,\n };\n conn: ConnectionProfileOps;\n email: { template: EmailTemplateOps } = { template: undefined };\n helper = {\n base64: Base64,\n constants: constants,\n jose: JoseOps,\n script: ScriptValidationUtils,\n utils: OpsUtils,\n };\n idm: {\n config: IdmOps;\n managed: ManagedObjectOps;\n organization: OrganizationOps;\n } = { config: undefined, managed: undefined, organization: undefined };\n info: InfoOps;\n login: AuthenticateOps = null;\n oauth2oidc: {\n client: OAuth2ClientOps;\n endpoint: OAuth2OidcOps;\n external: IdpOps;\n provider: OAuth2ProviderOps;\n } = {\n client: undefined,\n endpoint: undefined,\n external: undefined,\n provider: undefined,\n };\n realm: RealmOps;\n saml2: {\n circlesOfTrust: CirclesOfTrustOps;\n entityProvider: Saml2Ops;\n } = { circlesOfTrust: undefined, entityProvider: undefined };\n script: ScriptOps;\n service: ServiceOps;\n theme: ThemeOps;\n utils: {\n impex: ExportImportUtils;\n version: Version;\n } = { impex: undefined, version: undefined };\n\n constructor(config: StateInterface = {}) {\n this.state = new State(config);\n\n this.admin = new AdminOps(this.state);\n this.agent = new AgentOps(this.state);\n\n this.authn.journey = new JourneyOps(this.state);\n this.authn.node = new NodeOps(this.state);\n\n this.authz.policy = new PolicyOps(this.state);\n this.authz.policySet = new PolicySetOps(this.state);\n this.authz.resourceType = new ResourceTypeOps(this.state);\n\n this.cloud.feature = new FeatureOps(this.state);\n this.cloud.log = new LogOps(this.state);\n this.cloud.secret = new SecretsOps(this.state);\n this.cloud.serviceAccount = new ServiceAccountOps(this.state);\n this.cloud.startup = new StartupOps(this.state);\n this.cloud.variable = new VariablesOps(this.state);\n\n this.conn = new ConnectionProfileOps(this.state);\n\n this.email.template = new EmailTemplateOps(this.state);\n\n this.idm.config = new IdmOps(this.state);\n this.idm.managed = new ManagedObjectOps(this.state);\n this.idm.organization = new OrganizationOps(this.state);\n\n this.info = new InfoOps(this.state);\n this.login = new AuthenticateOps(this.state);\n\n this.oauth2oidc.client = new OAuth2ClientOps(this.state);\n this.oauth2oidc.endpoint = new OAuth2OidcOps(this.state);\n this.oauth2oidc.external = new IdpOps(this.state);\n this.oauth2oidc.provider = new OAuth2ProviderOps(this.state);\n\n this.realm = new RealmOps(this.state);\n\n this.saml2.circlesOfTrust = new CirclesOfTrustOps(this.state);\n this.saml2.entityProvider = new Saml2Ops(this.state);\n\n this.script = new ScriptOps(this.state);\n this.service = new ServiceOps(this.state);\n\n this.theme = new ThemeOps(this.state);\n\n this.utils.impex = new ExportImportUtils(this.state);\n this.utils.version = new Version(this.state);\n }\n}\n\nexport const frodo = new FrodoLib();\nexport const state = frodo.state;\n"]}
@@ -7,6 +7,11 @@ export declare const AGENT_TYPE_WEB = "WebAgent";
7
7
  export default class AgentOps {
8
8
  state: State;
9
9
  constructor(state: State);
10
+ /**
11
+ * Create an empty agent export template
12
+ * @returns {AgentExportInterface} an empty agent export template
13
+ */
14
+ createAgentExportTemplate(): AgentExportInterface;
10
15
  /**
11
16
  * Get all agents. Results are sorted aphabetically.
12
17
  * @returns {Promise<TreeSkeleton[]>} a promise that resolves to an array of agent objects
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/AgentOps.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,eAAO,MAAM,aAAa,yBAAyB,CAAC;AACpD,eAAO,MAAM,eAAe,cAAc,CAAC;AAC3C,eAAO,MAAM,cAAc,aAAa,CAAC;AAEzC,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,KAAK,EAAE,KAAK,CAAC;g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AAE,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 * 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,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,eAAO,MAAM,aAAa,yBAAyB,CAAC;AACpD,eAAO,MAAM,eAAe,cAAc,CAAC;AAC3C,eAAO,MAAM,cAAc,aAAa,CAAC;AAEzC,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,MAAM,EAAE,OAAO,EAAE,MAAM;IAI5D;;;OAGG;IACG,wBAAwB;IAI9B;;;;OAIG;IACG,uBAAuB,CAAC,SAAS,EAAE,MAAM;IAI/C;;;;;OAKG;IACG,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa;IAQ3E;;;OAGG;IACG,aAAa;IAInB;;;;OAIG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM;IAIlC;;;;;OAKG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa;IAI5D;;;OAGG;IACG,YAAY;IAIlB;;;;OAIG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM;IAIjC;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa;IAI3D;;;OAGG;IACG,YAAY,IAAI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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,7 +1,13 @@
1
1
  import State from '../shared/State';
2
+ import { JwkRsa } from './JoseOps';
2
3
  export default class AuthenticateOps {
3
4
  state: State;
4
5
  constructor(state: State);
6
+ /**
7
+ * Get access token for service account
8
+ * @returns {string | null} Access token or null
9
+ */
10
+ getAccessTokenForServiceAccount(saId?: string, saJwk?: JwkRsa): Promise<string | null>;
5
11
  /**
6
12
  * Get tokens
7
13
  * @param {boolean} forceLoginAsUser true to force login as user even if a service account is available (default: false)
@@ -14,7 +20,11 @@ export default class AuthenticateOps {
14
20
  * @param {State} state library state
15
21
  * @returns {string | null} Access token or null
16
22
  */
17
- export declare function getAccessTokenForServiceAccount(state: State): Promise<string | null>;
23
+ export declare function getAccessTokenForServiceAccount({ saId, saJwk, state, }: {
24
+ saId?: string;
25
+ saJwk?: JwkRsa;
26
+ state: State;
27
+ }): Promise<string | null>;
18
28
  /**
19
29
  * Get tokens
20
30
  * @param {boolean} forceLoginAsUser true to force login as user even if a service account is available (default: false)
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/AuthenticateOps.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAapC,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;;OAIG;IACH,SAAS,CAAC,gBAAgB,UAAQ;CAGnC;AAmaD;;;;GAIG;AACH,wBAAsB,+BAA+B,CACnD,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA0BxB;AAmDD;;;;;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 { 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 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 state: State\n): Promise<string | null> {\n debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: start`);\n const payload = createPayload(state.getServiceAccountId(), state.getHost());\n debugMessage(`AuthenticateOps.getAccessTokenForServiceAccount: payload:`);\n debugMessage(payload);\n const jwt = await createSignedJwtToken(payload, state.getServiceAccountJwk());\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 const name = (\n await getServiceAccount({\n serviceAccountId: state.getServiceAccountId(),\n state,\n })\n ).name;\n subjectString = `service account ${name} [${state.getServiceAccountId()}]`;\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;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;AAmDD;;;;;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 const name = (\n await getServiceAccount({\n serviceAccountId: state.getServiceAccountId(),\n state,\n })\n ).name;\n subjectString = `service account ${name} [${state.getServiceAccountId()}]`;\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,9 +1,15 @@
1
- import { getCircleOfTrust } from '../api/CirclesOfTrustApi';
1
+ import { getCircleOfTrust, createCircleOfTrust } from '../api/CirclesOfTrustApi';
2
2
  import State from '../shared/State';
3
3
  import { CirclesOfTrustExportInterface } from './OpsTypes';
4
+ import { CircleOfTrustSkeleton } from '../api/ApiTypes';
4
5
  export default class CirclesOfTrustOps {
5
6
  state: State;
6
7
  constructor(state: State);
8
+ /**
9
+ * Create an empty agent export template
10
+ * @returns {CirclesOfTrustExportInterface} an empty agent export template
11
+ */
12
+ createCirclesOfTrustExportTemplate(): CirclesOfTrustExportInterface;
7
13
  /**
8
14
  * Get SAML circle of trust
9
15
  * @param {String} cotId circle of trust id/name
@@ -13,6 +19,7 @@ export default class CirclesOfTrustOps {
13
19
  * Get SAML circles of trust
14
20
  */
15
21
  getCirclesOfTrust(): Promise<any>;
22
+ createCircleOfTrust(cotData: CircleOfTrustSkeleton): Promise<any>;
16
23
  /**
17
24
  * Export SAML circle of trust
18
25
  * @param {String} cotId circle of trust id/name
@@ -39,7 +46,14 @@ export default class CirclesOfTrustOps {
39
46
  */
40
47
  importCirclesOfTrust(importData: CirclesOfTrustExportInterface): Promise<any[]>;
41
48
  }
42
- export { getCircleOfTrust };
49
+ /**
50
+ * Create an empty agent export template
51
+ * @returns {CirclesOfTrustExportInterface} an empty agent export template
52
+ */
53
+ export declare function createCirclesOfTrustExportTemplate({ state, }: {
54
+ state: State;
55
+ }): CirclesOfTrustExportInterface;
56
+ export { getCircleOfTrust, createCircleOfTrust };
43
57
  /**
44
58
  * Get circles of trust
45
59
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/CirclesOfTrustOps.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,gBAAgB,EAGjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,KAAK,EAAE,KAAK,CAAC;gBACD,KAAK,EAAE,KAAK;IAIxB;;;OAGG;IACG,gBAAgB,CAAC,KAAK,EAAE,MAAM;IAIpC;;OAEG;IACG,iBAAiB;IAIvB;;;OAGG;IACG,mBAAmB,CAAC,KAAK,EAAE,MAAM;IAIvC;;OAEG;IACG,oBAAoB;IAI1B;;;;OAIG;IACG,mBAAmB,CACvB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,6BAA6B;IAK3C;;;OAGG;IACG,wBAAwB,CAAC,UAAU,EAAE,6BAA6B;IAIxE;;;OAGG;IACG,oBAAoB,CAAC,UAAU,EAAE,6BAA6B;CAGrE;AAmBD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,gBAGlE;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,KAAK,EACL,KAAK,GACN,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,6BAA6B,CAAC,CA2BzC;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAkBzC;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';\n\nexport default class CirclesOfTrustOps {\n state: State;\n constructor(state: State) {\n this.state = 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 /**\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 */\nfunction createCirclesOfTrustExportTemplate({ state }: { state: State }) {\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 };\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":["../src/ops/CirclesOfTrustOps.ts"],"names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ACzC,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;CACd,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAkBzC;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(`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"]}
@@ -86,15 +86,6 @@ export interface ConnectionsFileInterface {
86
86
  export declare function getConnectionProfilesPath({ state }: {
87
87
  state: State;
88
88
  }): string;
89
- /**
90
- * List connection profiles
91
- * @param {boolean} long Long list format with details
92
- * @param {State} state library state
93
- */
94
- export declare function listConnectionProfiles({ long, state, }: {
95
- long?: boolean;
96
- state: State;
97
- }): void;
98
89
  /**
99
90
  * Initialize connection profiles
100
91
  *
@@ -139,16 +130,6 @@ export declare function deleteConnectionProfile({ host, state, }: {
139
130
  host: string;
140
131
  state: State;
141
132
  }): void;
142
- /**
143
- * Describe connection profile
144
- * @param {string} host Host URL or unique substring
145
- * @param {boolean} showSecrets Whether secrets should be shown in clear text or not
146
- */
147
- export declare function describeConnectionProfile({ host, showSecrets, state, }: {
148
- host: string;
149
- showSecrets: boolean;
150
- state: State;
151
- }): Promise<void>;
152
133
  /**
153
134
  * Create a new service account using auto-generated parameters
154
135
  * @returns {Promise<IdObjectSkeletonInterface>} A promise resolving to a service account object