@credibledata/cred-cli 0.0.103 → 0.0.105
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -1
- package/dist/agent-contract.spec.js +548 -0
- package/dist/agent-contract.spec.js.map +1 -0
- package/dist/browser.js +72 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.spec.js +125 -0
- package/dist/browser.spec.js.map +1 -0
- package/dist/client/api.js +4137 -1159
- package/dist/client/api.js.map +1 -1
- package/dist/client-codeassist/api.js +476 -0
- package/dist/client-codeassist/api.js.map +1 -0
- package/dist/client-codeassist/base.js +69 -0
- package/dist/client-codeassist/base.js.map +1 -0
- package/dist/client-codeassist/common.js +162 -0
- package/dist/client-codeassist/common.js.map +1 -0
- package/dist/client-codeassist/configuration.js +44 -0
- package/dist/client-codeassist/configuration.js.map +1 -0
- package/dist/client-codeassist/index.js +32 -0
- package/dist/client-codeassist/index.js.map +1 -0
- package/dist/clientconfiguration.js +17 -289
- package/dist/clientconfiguration.js.map +1 -1
- package/dist/clientconfiguration.spec.js +35 -96
- package/dist/clientconfiguration.spec.js.map +1 -1
- package/dist/commands/add.js +103 -3
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/add.spec.js +113 -0
- package/dist/commands/add.spec.js.map +1 -0
- package/dist/commands/connection/createconnections.js +104 -7
- package/dist/commands/connection/createconnections.js.map +1 -1
- package/dist/commands/connection/createconnections.spec.js +35 -1
- package/dist/commands/connection/createconnections.spec.js.map +1 -1
- package/dist/commands/connection/deleteconnection.js +4 -2
- package/dist/commands/connection/deleteconnection.js.map +1 -1
- package/dist/commands/connection/deleteconnection.spec.js +6 -1
- package/dist/commands/connection/deleteconnection.spec.js.map +1 -1
- package/dist/commands/connection/listconnections.js +2 -0
- package/dist/commands/connection/listconnections.js.map +1 -1
- package/dist/commands/connection/updateconnection.js +365 -0
- package/dist/commands/connection/updateconnection.js.map +1 -0
- package/dist/commands/connection/updateconnection.spec.js +625 -0
- package/dist/commands/connection/updateconnection.spec.js.map +1 -0
- package/dist/commands/database/createdatabase.js +52 -0
- package/dist/commands/database/createdatabase.js.map +1 -0
- package/dist/commands/database/database.spec.js +267 -0
- package/dist/commands/database/database.spec.js.map +1 -0
- package/dist/commands/database/deletedatabase.js +91 -0
- package/dist/commands/database/deletedatabase.js.map +1 -0
- package/dist/commands/database/getdatabase.js +97 -0
- package/dist/commands/database/getdatabase.js.map +1 -0
- package/dist/commands/database/listdatabases.js +36 -0
- package/dist/commands/database/listdatabases.js.map +1 -0
- package/dist/commands/database/shared.js +125 -0
- package/dist/commands/database/shared.js.map +1 -0
- package/dist/commands/database/shared.spec.js +109 -0
- package/dist/commands/database/shared.spec.js.map +1 -0
- package/dist/commands/database/updatedatabase.js +39 -0
- package/dist/commands/database/updatedatabase.js.map +1 -0
- package/dist/commands/environment/createenvironment.js +59 -28
- package/dist/commands/environment/createenvironment.js.map +1 -1
- package/dist/commands/environment/createenvironment.spec.js +29 -0
- package/dist/commands/environment/createenvironment.spec.js.map +1 -1
- package/dist/commands/environment/deleteenvironment.js +3 -2
- package/dist/commands/environment/deleteenvironment.js.map +1 -1
- package/dist/commands/environment/deleteenvironment.spec.js +5 -1
- package/dist/commands/environment/deleteenvironment.spec.js.map +1 -1
- package/dist/commands/environment/getenvironment.js +1 -0
- package/dist/commands/environment/getenvironment.js.map +1 -1
- package/dist/commands/environment/listenvironments.js +40 -8
- package/dist/commands/environment/listenvironments.js.map +1 -1
- package/dist/commands/environment/listenvironments.spec.js +41 -2
- package/dist/commands/environment/listenvironments.spec.js.map +1 -1
- package/dist/commands/environment/setenvironment.js +145 -6
- package/dist/commands/environment/setenvironment.js.map +1 -1
- package/dist/commands/environment/setenvironment.spec.js +256 -8
- package/dist/commands/environment/setenvironment.spec.js.map +1 -1
- package/dist/commands/environment/updateenvironment.js +12 -8
- package/dist/commands/environment/updateenvironment.js.map +1 -1
- package/dist/commands/environment/updateenvironment.spec.js +36 -2
- package/dist/commands/environment/updateenvironment.spec.js.map +1 -1
- package/dist/commands/get.js +64 -1
- package/dist/commands/get.js.map +1 -1
- package/dist/commands/group/addmember.js +3 -1
- package/dist/commands/group/addmember.js.map +1 -1
- package/dist/commands/group/addmember.spec.js +7 -2
- package/dist/commands/group/addmember.spec.js.map +1 -1
- package/dist/commands/group/creategroup.js +2 -0
- package/dist/commands/group/creategroup.js.map +1 -1
- package/dist/commands/group/deletegroup.js +3 -1
- package/dist/commands/group/deletegroup.js.map +1 -1
- package/dist/commands/group/deletegroup.spec.js +7 -1
- package/dist/commands/group/deletegroup.spec.js.map +1 -1
- package/dist/commands/group/getgroup.js +2 -0
- package/dist/commands/group/getgroup.js.map +1 -1
- package/dist/commands/group/listgroups.js +2 -0
- package/dist/commands/group/listgroups.js.map +1 -1
- package/dist/commands/group/removemember.js +3 -1
- package/dist/commands/group/removemember.js.map +1 -1
- package/dist/commands/group/removemember.spec.js +7 -2
- package/dist/commands/group/removemember.spec.js.map +1 -1
- package/dist/commands/groupaccesstoken/deleteToken.js +2 -1
- package/dist/commands/groupaccesstoken/deleteToken.js.map +1 -1
- package/dist/commands/groupaccesstoken/groupContainer.js +2 -0
- package/dist/commands/groupaccesstoken/groupContainer.js.map +1 -1
- package/dist/commands/list.js +24 -4
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/materialization/cancelrun.js +3 -1
- package/dist/commands/materialization/cancelrun.js.map +1 -1
- package/dist/commands/materialization/getindex.js +2 -0
- package/dist/commands/materialization/getindex.js.map +1 -1
- package/dist/commands/materialization/getmaterialization.js +2 -0
- package/dist/commands/materialization/getmaterialization.js.map +1 -1
- package/dist/commands/materialization/getpreaggregate.js +2 -0
- package/dist/commands/materialization/getpreaggregate.js.map +1 -1
- package/dist/commands/materialization/getrun.js +2 -0
- package/dist/commands/materialization/getrun.js.map +1 -1
- package/dist/commands/materialization/listindexes.js +2 -0
- package/dist/commands/materialization/listindexes.js.map +1 -1
- package/dist/commands/materialization/listmaterializations.js +2 -0
- package/dist/commands/materialization/listmaterializations.js.map +1 -1
- package/dist/commands/materialization/listpreaggregates.js +2 -0
- package/dist/commands/materialization/listpreaggregates.js.map +1 -1
- package/dist/commands/materialization/listruns.js +3 -1
- package/dist/commands/materialization/listruns.js.map +1 -1
- package/dist/commands/materialization/rerun.js +3 -1
- package/dist/commands/materialization/rerun.js.map +1 -1
- package/dist/commands/misc/inquirerHost.js +87 -0
- package/dist/commands/misc/inquirerHost.js.map +1 -0
- package/dist/commands/misc/inquirerHost.spec.js +91 -0
- package/dist/commands/misc/inquirerHost.spec.js.map +1 -0
- package/dist/commands/misc/login.js +348 -58
- package/dist/commands/misc/login.js.map +1 -1
- package/dist/commands/misc/login.spec.js +525 -7
- package/dist/commands/misc/login.spec.js.map +1 -1
- package/dist/commands/misc/logout.js +26 -3
- package/dist/commands/misc/logout.js.map +1 -1
- package/dist/commands/misc/logout.spec.js +52 -12
- package/dist/commands/misc/logout.spec.js.map +1 -1
- package/dist/commands/misc/resolveLoginTarget.spec.js +90 -0
- package/dist/commands/misc/resolveLoginTarget.spec.js.map +1 -0
- package/dist/commands/misc/scope.spec.js +108 -0
- package/dist/commands/misc/scope.spec.js.map +1 -0
- package/dist/commands/misc/set-access-token.js +1 -1
- package/dist/commands/misc/set-access-token.js.map +1 -1
- package/dist/commands/misc/set-access-token.spec.js +13 -2
- package/dist/commands/misc/set-access-token.spec.js.map +1 -1
- package/dist/commands/misc/setup.js +819 -0
- package/dist/commands/misc/setup.js.map +1 -0
- package/dist/commands/misc/setup.spec.js +783 -0
- package/dist/commands/misc/setup.spec.js.map +1 -0
- package/dist/commands/misc/status.js +168 -0
- package/dist/commands/misc/status.js.map +1 -0
- package/dist/commands/misc/status.spec.js +301 -0
- package/dist/commands/misc/status.spec.js.map +1 -0
- package/dist/commands/misc/token.js +57 -0
- package/dist/commands/misc/token.js.map +1 -0
- package/dist/commands/misc/token.spec.js +92 -0
- package/dist/commands/misc/token.spec.js.map +1 -0
- package/dist/commands/package/deletepackage.js +4 -2
- package/dist/commands/package/deletepackage.js.map +1 -1
- package/dist/commands/package/deletepackage.spec.js +7 -1
- package/dist/commands/package/deletepackage.spec.js.map +1 -1
- package/dist/commands/package/getpackage.js +142 -0
- package/dist/commands/package/getpackage.js.map +1 -0
- package/dist/commands/package/getpackage.spec.js +246 -0
- package/dist/commands/package/getpackage.spec.js.map +1 -0
- package/dist/commands/package/listpackages.js +2 -0
- package/dist/commands/package/listpackages.js.map +1 -1
- package/dist/commands/package/publish.archive.spec.js +570 -0
- package/dist/commands/package/publish.archive.spec.js.map +1 -0
- package/dist/commands/package/publish.js +780 -49
- package/dist/commands/package/publish.js.map +1 -1
- package/dist/commands/package/publish.spec.js +451 -8
- package/dist/commands/package/publish.spec.js.map +1 -1
- package/dist/commands/package/updatepackage.js +22 -19
- package/dist/commands/package/updatepackage.js.map +1 -1
- package/dist/commands/package/updatepackage.spec.js +36 -1
- package/dist/commands/package/updatepackage.spec.js.map +1 -1
- package/dist/commands/permission/createpermission.js +3 -1
- package/dist/commands/permission/createpermission.js.map +1 -1
- package/dist/commands/permission/deletepermission.js +6 -3
- package/dist/commands/permission/deletepermission.js.map +1 -1
- package/dist/commands/permission/getpermission.js +2 -0
- package/dist/commands/permission/getpermission.js.map +1 -1
- package/dist/commands/permission/listpermissions.js +2 -0
- package/dist/commands/permission/listpermissions.js.map +1 -1
- package/dist/commands/rm.js +21 -0
- package/dist/commands/rm.js.map +1 -1
- package/dist/commands/set.js +40 -6
- package/dist/commands/set.js.map +1 -1
- package/dist/commands/set.spec.js +123 -0
- package/dist/commands/set.spec.js.map +1 -0
- package/dist/commands/table/addtable.js +155 -0
- package/dist/commands/table/addtable.js.map +1 -0
- package/dist/commands/table/deletetable.js +45 -0
- package/dist/commands/table/deletetable.js.map +1 -0
- package/dist/commands/table/gettable.js +32 -0
- package/dist/commands/table/gettable.js.map +1 -0
- package/dist/commands/table/listtables.js +36 -0
- package/dist/commands/table/listtables.js.map +1 -0
- package/dist/commands/table/table.spec.js +304 -0
- package/dist/commands/table/table.spec.js.map +1 -0
- package/dist/commands/table/tablefile.js +195 -0
- package/dist/commands/table/tablefile.js.map +1 -0
- package/dist/commands/table/tablefile.spec.js +158 -0
- package/dist/commands/table/tablefile.spec.js.map +1 -0
- package/dist/commands/update.js +21 -0
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/version/archive-unarchive-version.js +4 -2
- package/dist/commands/version/archive-unarchive-version.js.map +1 -1
- package/dist/commands/version/archive-unarchive-version.spec.js +6 -1
- package/dist/commands/version/archive-unarchive-version.spec.js.map +1 -1
- package/dist/commands/version/listversions.js +2 -0
- package/dist/commands/version/listversions.js.map +1 -1
- package/dist/common/UserGroupId.js +9 -4
- package/dist/common/UserGroupId.js.map +1 -1
- package/dist/common/UserGroupId.spec.js +5 -0
- package/dist/common/UserGroupId.spec.js.map +1 -1
- package/dist/constants.js +37 -143
- package/dist/constants.js.map +1 -1
- package/dist/index.js +487 -90
- package/dist/index.js.map +1 -1
- package/dist/logger.js +42 -9
- package/dist/logger.js.map +1 -1
- package/dist/session.js +56 -0
- package/dist/session.js.map +1 -0
- package/dist/session.spec.js +103 -0
- package/dist/session.spec.js.map +1 -0
- package/dist/setup-core/briefing.js +176 -0
- package/dist/setup-core/briefing.js.map +1 -0
- package/dist/setup-core/credstore.js +415 -0
- package/dist/setup-core/credstore.js.map +1 -0
- package/dist/setup-core/credstore.spec.js +238 -0
- package/dist/setup-core/credstore.spec.js.map +1 -0
- package/dist/setup-core/environments.js +267 -0
- package/dist/setup-core/environments.js.map +1 -0
- package/dist/setup-core/flow.e2e.js +165 -0
- package/dist/setup-core/flow.e2e.js.map +1 -0
- package/dist/setup-core/flow.js +765 -0
- package/dist/setup-core/flow.js.map +1 -0
- package/dist/setup-core/flow.spec.js +1348 -0
- package/dist/setup-core/flow.spec.js.map +1 -0
- package/dist/setup-core/folderconfig.js +283 -0
- package/dist/setup-core/folderconfig.js.map +1 -0
- package/dist/setup-core/git.js +97 -0
- package/dist/setup-core/git.js.map +1 -0
- package/dist/setup-core/host.js +77 -0
- package/dist/setup-core/host.js.map +1 -0
- package/dist/setup-core/importconnections.js +470 -0
- package/dist/setup-core/importconnections.js.map +1 -0
- package/dist/setup-core/importconnections.spec.js +594 -0
- package/dist/setup-core/importconnections.spec.js.map +1 -0
- package/dist/setup-core/liveness.js +94 -0
- package/dist/setup-core/liveness.js.map +1 -0
- package/dist/setup-core/liveness.spec.js +59 -0
- package/dist/setup-core/liveness.spec.js.map +1 -0
- package/dist/setup-core/localpublisherconfig.js +26 -0
- package/dist/setup-core/localpublisherconfig.js.map +1 -0
- package/dist/setup-core/localpublisherconfig.spec.js +29 -0
- package/dist/setup-core/localpublisherconfig.spec.js.map +1 -0
- package/dist/setup-core/mcpconfig.js +198 -0
- package/dist/setup-core/mcpconfig.js.map +1 -0
- package/dist/setup-core/mcpconfig.spec.js +205 -0
- package/dist/setup-core/mcpconfig.spec.js.map +1 -0
- package/dist/setup-core/packagemanifest.js +55 -0
- package/dist/setup-core/packagemanifest.js.map +1 -0
- package/dist/setup-core/ports.js +182 -0
- package/dist/setup-core/ports.js.map +1 -0
- package/dist/setup-core/ports.spec.js +173 -0
- package/dist/setup-core/ports.spec.js.map +1 -0
- package/dist/setup-core/publisherconfig.js +268 -0
- package/dist/setup-core/publisherconfig.js.map +1 -0
- package/dist/setup-core/publisherconfig.oracle.js +166 -0
- package/dist/setup-core/publisherconfig.oracle.js.map +1 -0
- package/dist/setup-core/publisherconfig.spec.js +277 -0
- package/dist/setup-core/publisherconfig.spec.js.map +1 -0
- package/dist/setup-core/publisherversion.js +26 -0
- package/dist/setup-core/publisherversion.js.map +1 -0
- package/dist/setup-core/readiness.spec.js +161 -0
- package/dist/setup-core/readiness.spec.js.map +1 -0
- package/dist/setup-core/readylines.js +169 -0
- package/dist/setup-core/readylines.js.map +1 -0
- package/dist/setup-core/readylines.spec.js +70 -0
- package/dist/setup-core/readylines.spec.js.map +1 -0
- package/dist/setup-core/refresh.js +348 -0
- package/dist/setup-core/refresh.js.map +1 -0
- package/dist/setup-core/refresh.spec.js +501 -0
- package/dist/setup-core/refresh.spec.js.map +1 -0
- package/dist/setup-core/skills.js +279 -0
- package/dist/setup-core/skills.js.map +1 -0
- package/dist/setup-core/skills.spec.js +334 -0
- package/dist/setup-core/skills.spec.js.map +1 -0
- package/dist/setup-core/supervisor.js +879 -0
- package/dist/setup-core/supervisor.js.map +1 -0
- package/dist/setup-core/supervisor.spec.js +833 -0
- package/dist/setup-core/supervisor.spec.js.map +1 -0
- package/dist/setup-core/writefile.js +61 -0
- package/dist/setup-core/writefile.js.map +1 -0
- package/dist/setup-core/writefile.spec.js +68 -0
- package/dist/setup-core/writefile.spec.js.map +1 -0
- package/dist/utils.js +409 -3
- package/dist/utils.js.map +1 -1
- package/dist/utils.spec.js +373 -2
- package/dist/utils.spec.js.map +1 -1
- package/dist/versioncheck-refresh.js +18 -0
- package/dist/versioncheck-refresh.js.map +1 -0
- package/dist/versioncheck.js +324 -0
- package/dist/versioncheck.js.map +1 -0
- package/dist/versioncheck.spec.js +587 -0
- package/dist/versioncheck.spec.js.map +1 -0
- package/node_modules/@credibledata/cli-auth/dist/index.d.ts +86 -0
- package/node_modules/@credibledata/cli-auth/dist/index.js +102 -0
- package/node_modules/@credibledata/cli-auth/package.json +19 -0
- package/package.json +18 -6
- package/.github/workflows/build.yml +0 -23
- package/.mocharc.json +0 -10
- package/.prettierignore +0 -2
- package/.prettierrc +0 -4
- package/README-DEV.md +0 -40
- package/coverage/coverage-summary.json +0 -40
- package/coverage/tmp/coverage-2152-1789496974457-0.json +0 -1
- package/coverage/tmp/coverage-2153-1789496954404-0.json +0 -1
- package/docker/Dockerfile.ci +0 -18
- package/docker-compose.yml +0 -18
- package/eslint.config.mjs +0 -45
- package/generate-client.sh +0 -27
- package/mocha.setup.ts +0 -4
- package/openapitools.json +0 -10
- package/src/client/.openapi-generator/FILES +0 -9
- package/src/client/.openapi-generator/VERSION +0 -1
- package/src/client/.openapi-generator-ignore +0 -23
- package/src/client/api.ts +0 -15999
- package/src/client/base.ts +0 -86
- package/src/client/common.ts +0 -150
- package/src/client/configuration.ts +0 -110
- package/src/client/git_push.sh +0 -57
- package/src/client/index.ts +0 -18
- package/src/clientconfiguration.spec.ts +0 -615
- package/src/clientconfiguration.ts +0 -364
- package/src/commands/add.ts +0 -191
- package/src/commands/connection/createconnections.spec.ts +0 -413
- package/src/commands/connection/createconnections.ts +0 -109
- package/src/commands/connection/deleteconnection.spec.ts +0 -189
- package/src/commands/connection/deleteconnection.ts +0 -57
- package/src/commands/connection/listconnections.spec.ts +0 -132
- package/src/commands/connection/listconnections.ts +0 -58
- package/src/commands/environment/createenvironment.spec.ts +0 -249
- package/src/commands/environment/createenvironment.ts +0 -73
- package/src/commands/environment/deleteenvironment.spec.ts +0 -152
- package/src/commands/environment/deleteenvironment.ts +0 -48
- package/src/commands/environment/getenvironment.spec.ts +0 -110
- package/src/commands/environment/getenvironment.ts +0 -43
- package/src/commands/environment/listenvironments.spec.ts +0 -123
- package/src/commands/environment/listenvironments.ts +0 -67
- package/src/commands/environment/setenvironment.spec.ts +0 -63
- package/src/commands/environment/setenvironment.ts +0 -14
- package/src/commands/environment/updateenvironment.spec.ts +0 -386
- package/src/commands/environment/updateenvironment.ts +0 -168
- package/src/commands/get.ts +0 -153
- package/src/commands/group/addmember.spec.ts +0 -257
- package/src/commands/group/addmember.ts +0 -85
- package/src/commands/group/creategroup.spec.ts +0 -146
- package/src/commands/group/creategroup.ts +0 -54
- package/src/commands/group/deletegroup.spec.ts +0 -120
- package/src/commands/group/deletegroup.ts +0 -45
- package/src/commands/group/getgroup.spec.ts +0 -129
- package/src/commands/group/getgroup.ts +0 -47
- package/src/commands/group/listgroups.spec.ts +0 -137
- package/src/commands/group/listgroups.ts +0 -45
- package/src/commands/group/removemember.spec.ts +0 -224
- package/src/commands/group/removemember.ts +0 -75
- package/src/commands/groupaccesstoken/createToken.spec.ts +0 -211
- package/src/commands/groupaccesstoken/createToken.ts +0 -72
- package/src/commands/groupaccesstoken/deleteToken.spec.ts +0 -147
- package/src/commands/groupaccesstoken/deleteToken.ts +0 -29
- package/src/commands/groupaccesstoken/groupContainer.ts +0 -83
- package/src/commands/groupaccesstoken/listTokens.spec.ts +0 -147
- package/src/commands/groupaccesstoken/listTokens.ts +0 -29
- package/src/commands/legacy.ts +0 -5
- package/src/commands/list.ts +0 -326
- package/src/commands/materialization/cancelrun.ts +0 -70
- package/src/commands/materialization/getindex.ts +0 -55
- package/src/commands/materialization/getmaterialization.ts +0 -57
- package/src/commands/materialization/getpreaggregate.ts +0 -58
- package/src/commands/materialization/getrun.ts +0 -55
- package/src/commands/materialization/listindexes.ts +0 -69
- package/src/commands/materialization/listmaterializations.ts +0 -53
- package/src/commands/materialization/listpreaggregates.ts +0 -74
- package/src/commands/materialization/listruns.ts +0 -77
- package/src/commands/materialization/rerun.ts +0 -123
- package/src/commands/misc/login.spec.ts +0 -371
- package/src/commands/misc/login.ts +0 -343
- package/src/commands/misc/logout.spec.ts +0 -32
- package/src/commands/misc/logout.ts +0 -9
- package/src/commands/misc/loopbackOAuth.ts +0 -127
- package/src/commands/misc/set-access-token.spec.ts +0 -95
- package/src/commands/misc/set-access-token.ts +0 -32
- package/src/commands/package/deletepackage.spec.ts +0 -164
- package/src/commands/package/deletepackage.ts +0 -58
- package/src/commands/package/listpackages.spec.ts +0 -163
- package/src/commands/package/listpackages.ts +0 -74
- package/src/commands/package/publish.spec.ts +0 -642
- package/src/commands/package/publish.ts +0 -236
- package/src/commands/package/updatepackage.spec.ts +0 -319
- package/src/commands/package/updatepackage.ts +0 -95
- package/src/commands/permission/createpermission.spec.ts +0 -507
- package/src/commands/permission/createpermission.ts +0 -181
- package/src/commands/permission/deletepermission.ts +0 -117
- package/src/commands/permission/getpermission.ts +0 -115
- package/src/commands/permission/listpermissions.ts +0 -101
- package/src/commands/permission/scope.ts +0 -180
- package/src/commands/rm.ts +0 -146
- package/src/commands/set.ts +0 -25
- package/src/commands/update.ts +0 -107
- package/src/commands/version/archive-unarchive-version.spec.ts +0 -456
- package/src/commands/version/archive-unarchive-version.ts +0 -108
- package/src/commands/version/listversions.spec.ts +0 -138
- package/src/commands/version/listversions.ts +0 -45
- package/src/common/UserGroupId.spec.ts +0 -115
- package/src/common/UserGroupId.ts +0 -137
- package/src/constants.spec.ts +0 -111
- package/src/constants.ts +0 -228
- package/src/index.ts +0 -378
- package/src/logger.spec.ts +0 -158
- package/src/logger.ts +0 -90
- package/src/polyfills/file.polyfill.ts +0 -6
- package/src/utils.spec.ts +0 -135
- package/src/utils.ts +0 -115
- package/src/validator.spec.ts +0 -51
- package/src/validator.ts +0 -44
- package/tsconfig.json +0 -17
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ClientConfiguration = exports.InvalidConfigError = void 0;
|
|
7
|
+
exports.resolveTokens = resolveTokens;
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const cli_auth_1 = require("@credibledata/cli-auth");
|
|
11
|
+
const os_1 = __importDefault(require("os"));
|
|
12
|
+
const environments_1 = require("./environments");
|
|
13
|
+
const writefile_1 = require("./writefile");
|
|
14
|
+
/**
|
|
15
|
+
* Thrown when `.cred` exists but cannot be used: either it does not parse as
|
|
16
|
+
* JSON or it parses but lacks the required top-level shape. Distinct from fs
|
|
17
|
+
* errors (ENOENT, EACCES) so callers that want to recover — `cred login` —
|
|
18
|
+
* can target *only* a corrupt-content failure and leave permission/IO errors
|
|
19
|
+
* to surface loudly.
|
|
20
|
+
*/
|
|
21
|
+
class InvalidConfigError extends Error {
|
|
22
|
+
}
|
|
23
|
+
exports.InvalidConfigError = InvalidConfigError;
|
|
24
|
+
/**
|
|
25
|
+
* Sort the stored token fields into access token and id token by audience,
|
|
26
|
+
* using the rules `cred` and `ms2ad` share (cli-auth/src/index.ts, where each
|
|
27
|
+
* rule is written down and tested), bound to this deployment's Auth0 values.
|
|
28
|
+
*
|
|
29
|
+
* A token it cannot identify comes back `undefined`, so the caller says "run
|
|
30
|
+
* `cred login`" instead of sending a token the control plane will refuse.
|
|
31
|
+
*/
|
|
32
|
+
function resolveTokens(stored, environment) {
|
|
33
|
+
return (0, cli_auth_1.resolveTokens)(stored, environments_1.auth0ConfigsByEnv[environment]);
|
|
34
|
+
}
|
|
35
|
+
class ClientConfiguration {
|
|
36
|
+
/**
|
|
37
|
+
* Make every default store (`new ClientConfiguration()`, the form the ~40
|
|
38
|
+
* CLI commands build for themselves) read `scope` instead of the global
|
|
39
|
+
* `activeEnvironment`, organization and environment, without writing them.
|
|
40
|
+
*
|
|
41
|
+
* The CLI calls this once at startup, for a command run in a directory
|
|
42
|
+
* `cred init` pinned, unless `--cell` names another cell: that
|
|
43
|
+
* cell's own store applies, and the pin is ignored. Without it those commands read only `~/.cred`, so in
|
|
44
|
+
* a directory pinned to one organization `cred ls connections` listed
|
|
45
|
+
* another's, and `cred rm connection` would have deleted from it.
|
|
46
|
+
*
|
|
47
|
+
* A store built with an explicit path or deployment is left alone: those
|
|
48
|
+
* are the callers that already chose where to read, and the specs.
|
|
49
|
+
*/
|
|
50
|
+
static scopeCommand(scope) {
|
|
51
|
+
ClientConfiguration.commandScope = scope;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @param customConfigPath an alternate `~/.cred` location, for tests.
|
|
55
|
+
* @param environmentOverride pin every per-environment read to this
|
|
56
|
+
* deployment instead of the file's `activeEnvironment`, without
|
|
57
|
+
* writing to disk. `~/.cred` stores credentials per deployment, so a
|
|
58
|
+
* caller that targets a deployment other than the active one needs
|
|
59
|
+
* its token, organization and environment from that deployment too:
|
|
60
|
+
* resolving only the URL would talk to one deployment's control plane
|
|
61
|
+
* with another's token.
|
|
62
|
+
*/
|
|
63
|
+
constructor(customConfigPath, environmentOverride) {
|
|
64
|
+
var _a;
|
|
65
|
+
this.configPath = `${os_1.default.homedir()}/.cred`;
|
|
66
|
+
if (customConfigPath) {
|
|
67
|
+
this.configPath = customConfigPath;
|
|
68
|
+
}
|
|
69
|
+
this.environmentOverride = environmentOverride;
|
|
70
|
+
if (!customConfigPath && !environmentOverride) {
|
|
71
|
+
this.scope = ClientConfiguration.commandScope;
|
|
72
|
+
this.environmentOverride = (_a = this.scope) === null || _a === void 0 ? void 0 : _a.deployment;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The same file, with every per-deployment read and write pinned to
|
|
77
|
+
* `environment` — the one this store resolves to now. For an operation that
|
|
78
|
+
* reads, waits and then writes: without the pin, the write resolves the
|
|
79
|
+
* deployment again and follows an `activeEnvironment` changed in between.
|
|
80
|
+
*/
|
|
81
|
+
pinnedToCurrentEnvironment() {
|
|
82
|
+
return this.pinnedTo(this.getEnvironment());
|
|
83
|
+
}
|
|
84
|
+
/** The same file, with every per-deployment read and write pinned to `environment`. */
|
|
85
|
+
pinnedTo(environment) {
|
|
86
|
+
return new ClientConfiguration(this.configPath, environment);
|
|
87
|
+
}
|
|
88
|
+
/** Where this store lives on disk. The token refresh locks a file beside it. */
|
|
89
|
+
getConfigPath() {
|
|
90
|
+
return this.configPath;
|
|
91
|
+
}
|
|
92
|
+
loadConfig() {
|
|
93
|
+
let fileContents;
|
|
94
|
+
try {
|
|
95
|
+
fileContents = fs_1.default.readFileSync(this.configPath);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === "ENOENT") {
|
|
99
|
+
// First-time setup: create a default config on disk.
|
|
100
|
+
this.config = this.defaultConfig();
|
|
101
|
+
this.writeConfig();
|
|
102
|
+
return this.config;
|
|
103
|
+
}
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
this.config = JSON.parse(fileContents.toString());
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
// Non-atomic writes from older binaries, or a manually corrupted file,
|
|
111
|
+
// can leave `.cred` unparseable. Fail loud rather than silently
|
|
112
|
+
// overwriting — a silent reset erases the access token for every
|
|
113
|
+
// subsequent caller on the same machine.
|
|
114
|
+
throw new InvalidConfigError(`Failed to parse ${this.configPath}: ${error}. The file may be corrupt; re-run \`cred login\` to reset.`);
|
|
115
|
+
}
|
|
116
|
+
if (!this.config.activeEnvironment || !this.config.configPerEnvironment) {
|
|
117
|
+
throw new InvalidConfigError(`Invalid config structure in ${this.configPath}; re-run \`cred login\` to reset.`);
|
|
118
|
+
}
|
|
119
|
+
for (const env of environments_1.ALL_ENVIRONMENTS) {
|
|
120
|
+
if (!this.config.configPerEnvironment[env]) {
|
|
121
|
+
this.config.configPerEnvironment[env] = {};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return this.config;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Ensure `.cred` is usable, recovering from a corrupt file if needed.
|
|
128
|
+
*
|
|
129
|
+
* `loadConfig` deliberately fails loud on a corrupt/invalid file so a read
|
|
130
|
+
* path never silently erases tokens. But `cred login` exists precisely to
|
|
131
|
+
* (re)establish config, so it must be able to get past a bad file — that is
|
|
132
|
+
* what the "re-run `cred login` to reset" message promises. We make the
|
|
133
|
+
* message true here: the bad file is renamed aside (never deleted, so a
|
|
134
|
+
* support engineer can still inspect it) and a fresh default is written.
|
|
135
|
+
*
|
|
136
|
+
* Only an {@link InvalidConfigError} triggers recovery. fs errors such as
|
|
137
|
+
* EACCES are real environment problems and are rethrown — resetting would
|
|
138
|
+
* just fail to write anyway, and we must not mask a permissions issue as a
|
|
139
|
+
* successful reset.
|
|
140
|
+
*
|
|
141
|
+
* @returns the path the corrupt file was backed up to, or null if the
|
|
142
|
+
* existing config was already valid. The caller decides how to
|
|
143
|
+
* report it; this module does not own a logger.
|
|
144
|
+
*/
|
|
145
|
+
recoverIfCorrupt() {
|
|
146
|
+
try {
|
|
147
|
+
this.loadConfig();
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (!(error instanceof InvalidConfigError)) {
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
const backupPath = `${this.configPath}.corrupt-${crypto_1.default
|
|
155
|
+
.randomBytes(8)
|
|
156
|
+
.toString("hex")}`;
|
|
157
|
+
fs_1.default.renameSync(this.configPath, backupPath);
|
|
158
|
+
this.config = this.defaultConfig();
|
|
159
|
+
this.writeConfig();
|
|
160
|
+
return backupPath;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
defaultConfig() {
|
|
164
|
+
const configPerEnvironment = {};
|
|
165
|
+
for (const env of environments_1.ALL_ENVIRONMENTS) {
|
|
166
|
+
configPerEnvironment[env] = {};
|
|
167
|
+
}
|
|
168
|
+
return { configPerEnvironment, activeEnvironment: environments_1.DEFAULT_DEPLOYMENT };
|
|
169
|
+
}
|
|
170
|
+
// 0600 because this file holds tokens: the default 0644 is readable by every
|
|
171
|
+
// other account on the machine. Atomicity and the unguessable temp name are
|
|
172
|
+
// `writeFileAtomic`'s job — see there for why each matters.
|
|
173
|
+
writeConfig() {
|
|
174
|
+
(0, writefile_1.writeFileAtomic)(this.configPath, JSON.stringify(this.config), {
|
|
175
|
+
mode: 0o600,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
currentEnvConfig() {
|
|
179
|
+
this.loadConfig();
|
|
180
|
+
return this.config.configPerEnvironment[this.getEnvironment()];
|
|
181
|
+
}
|
|
182
|
+
setOrganization(organizationName) {
|
|
183
|
+
this.loadConfig();
|
|
184
|
+
const environment = this.getEnvironment();
|
|
185
|
+
this.config.configPerEnvironment[environment].organization =
|
|
186
|
+
organizationName;
|
|
187
|
+
this.writeConfig();
|
|
188
|
+
}
|
|
189
|
+
// `undefined` clears it: that is what `login.ts` writes when the organization
|
|
190
|
+
// changes and the old environment no longer applies, and what `cred init`
|
|
191
|
+
// writes before opening the picker. `cred status` reports an unset
|
|
192
|
+
// environment with `?? "Not set"`, which only catches null/undefined — so a
|
|
193
|
+
// clear that wrote `""` would print a blank line instead.
|
|
194
|
+
setProject(projectName) {
|
|
195
|
+
this.loadConfig();
|
|
196
|
+
const environment = this.getEnvironment();
|
|
197
|
+
this.config.configPerEnvironment[environment].project = projectName;
|
|
198
|
+
this.writeConfig();
|
|
199
|
+
}
|
|
200
|
+
getOrganization() {
|
|
201
|
+
var _a, _b;
|
|
202
|
+
return (_b = (_a = this.scope) === null || _a === void 0 ? void 0 : _a.organization) !== null && _b !== void 0 ? _b : this.currentEnvConfig().organization;
|
|
203
|
+
}
|
|
204
|
+
getProject() {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
return (_b = (_a = this.scope) === null || _a === void 0 ? void 0 : _a.environment) !== null && _b !== void 0 ? _b : this.currentEnvConfig().project;
|
|
207
|
+
}
|
|
208
|
+
setAccessToken(userToken, accessToken) {
|
|
209
|
+
this.loadConfig();
|
|
210
|
+
const environment = this.getEnvironment();
|
|
211
|
+
this.config.configPerEnvironment[environment].isServiceAccountToken =
|
|
212
|
+
!userToken;
|
|
213
|
+
this.config.configPerEnvironment[environment].accessToken = accessToken;
|
|
214
|
+
this.writeConfig();
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Persist a freshly-issued Auth0 token pair.
|
|
218
|
+
*
|
|
219
|
+
* Writes the access token to BOTH `accessToken` and `jwtAccessToken`, which
|
|
220
|
+
* is the shape the CLI has always written and the shape the extension can
|
|
221
|
+
* still read (it takes the access token from `jwtAccessToken`). `idToken`
|
|
222
|
+
* gets its own field so it is never confused with the access token again.
|
|
223
|
+
*/
|
|
224
|
+
setTokenPair(tokens) {
|
|
225
|
+
this.loadConfig();
|
|
226
|
+
const environment = this.getEnvironment();
|
|
227
|
+
const envConfig = this.config.configPerEnvironment[environment];
|
|
228
|
+
envConfig.isServiceAccountToken = false;
|
|
229
|
+
envConfig.accessToken = tokens.accessToken;
|
|
230
|
+
envConfig.jwtAccessToken = tokens.accessToken;
|
|
231
|
+
if (tokens.idToken) {
|
|
232
|
+
envConfig.idToken = tokens.idToken;
|
|
233
|
+
}
|
|
234
|
+
if (tokens.refreshToken) {
|
|
235
|
+
envConfig.refreshToken = tokens.refreshToken;
|
|
236
|
+
}
|
|
237
|
+
this.writeConfig();
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The token to put in an `Authorization` header, resolved by audience rather
|
|
241
|
+
* than by field name so it is correct whichever tool wrote the file last.
|
|
242
|
+
*/
|
|
243
|
+
getApiAccessToken() {
|
|
244
|
+
const envConfig = this.currentEnvConfig();
|
|
245
|
+
if (envConfig.isServiceAccountToken) {
|
|
246
|
+
return envConfig.accessToken;
|
|
247
|
+
}
|
|
248
|
+
return resolveTokens(envConfig, this.getEnvironment()).apiAccessToken;
|
|
249
|
+
}
|
|
250
|
+
getIdToken() {
|
|
251
|
+
return resolveTokens(this.currentEnvConfig(), this.getEnvironment())
|
|
252
|
+
.idToken;
|
|
253
|
+
}
|
|
254
|
+
getAuthenticationHeader() {
|
|
255
|
+
const envConfig = this.currentEnvConfig();
|
|
256
|
+
const authType = envConfig.isServiceAccountToken ? "ApiKey" : "Bearer";
|
|
257
|
+
return `${authType} ${this.getApiAccessToken()}`;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* @deprecated Ambiguous — returns the raw `accessToken` field, whose meaning
|
|
261
|
+
* depends on which tool wrote it last. Use {@link getApiAccessToken} for an
|
|
262
|
+
* `Authorization` header or {@link getIdToken} for profile claims.
|
|
263
|
+
*/
|
|
264
|
+
getAccessToken() {
|
|
265
|
+
return this.currentEnvConfig().accessToken;
|
|
266
|
+
}
|
|
267
|
+
setJwtAccessToken(jwtAccessToken) {
|
|
268
|
+
this.loadConfig();
|
|
269
|
+
const environment = this.getEnvironment();
|
|
270
|
+
this.config.configPerEnvironment[environment].jwtAccessToken =
|
|
271
|
+
jwtAccessToken;
|
|
272
|
+
this.writeConfig();
|
|
273
|
+
}
|
|
274
|
+
getJwtAccessToken() {
|
|
275
|
+
return this.currentEnvConfig().jwtAccessToken;
|
|
276
|
+
}
|
|
277
|
+
setVSCodeUser(username, email) {
|
|
278
|
+
this.loadConfig();
|
|
279
|
+
const environment = this.getEnvironment();
|
|
280
|
+
if (!this.config.configPerEnvironment[environment]) {
|
|
281
|
+
this.config.configPerEnvironment[environment] = {};
|
|
282
|
+
}
|
|
283
|
+
this.config.configPerEnvironment[environment].vsCodeUser = {
|
|
284
|
+
username,
|
|
285
|
+
email,
|
|
286
|
+
};
|
|
287
|
+
this.writeConfig();
|
|
288
|
+
}
|
|
289
|
+
getVSCodeUser() {
|
|
290
|
+
return this.currentEnvConfig().vsCodeUser;
|
|
291
|
+
}
|
|
292
|
+
setRefreshToken(refreshToken) {
|
|
293
|
+
this.loadConfig();
|
|
294
|
+
const environment = this.getEnvironment();
|
|
295
|
+
this.config.configPerEnvironment[environment].refreshToken = refreshToken;
|
|
296
|
+
this.writeConfig();
|
|
297
|
+
}
|
|
298
|
+
getRefreshToken() {
|
|
299
|
+
return this.currentEnvConfig().refreshToken;
|
|
300
|
+
}
|
|
301
|
+
isServiceAccountToken() {
|
|
302
|
+
return Boolean(this.currentEnvConfig().isServiceAccountToken);
|
|
303
|
+
}
|
|
304
|
+
doesConfigExists() {
|
|
305
|
+
this.loadConfig();
|
|
306
|
+
const environment = this.getEnvironment();
|
|
307
|
+
return Boolean(this.config.configPerEnvironment[environment]);
|
|
308
|
+
}
|
|
309
|
+
getHeaders() {
|
|
310
|
+
return {
|
|
311
|
+
Authorization: this.getAuthenticationHeader(),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Remove this deployment's tokens and keep the rest of its entry: the
|
|
316
|
+
* organization and environment (`project`) the user chose. For a session
|
|
317
|
+
* Auth0 has refused, where the next step is signing back in to the same
|
|
318
|
+
* place. `cred logout` uses `destroyConfig`, which forgets everything.
|
|
319
|
+
*/
|
|
320
|
+
clearTokens() {
|
|
321
|
+
// Resolve the deployment first: getEnvironment() reloads `this.config`,
|
|
322
|
+
// so reading `this.config` before it would edit a stale copy and write
|
|
323
|
+
// the old tokens back.
|
|
324
|
+
const environment = this.getEnvironment();
|
|
325
|
+
this.loadConfig();
|
|
326
|
+
const envConfig = this.config.configPerEnvironment[environment];
|
|
327
|
+
if (!envConfig)
|
|
328
|
+
return;
|
|
329
|
+
delete envConfig.accessToken;
|
|
330
|
+
delete envConfig.jwtAccessToken;
|
|
331
|
+
delete envConfig.idToken;
|
|
332
|
+
delete envConfig.refreshToken;
|
|
333
|
+
delete envConfig.isServiceAccountToken;
|
|
334
|
+
this.writeConfig();
|
|
335
|
+
}
|
|
336
|
+
destroyConfig() {
|
|
337
|
+
this.loadConfig();
|
|
338
|
+
const environment = this.getEnvironment();
|
|
339
|
+
this.config.configPerEnvironment[environment] = {};
|
|
340
|
+
this.writeConfig();
|
|
341
|
+
}
|
|
342
|
+
setEnvironment(environment) {
|
|
343
|
+
this.loadConfig();
|
|
344
|
+
this.config.activeEnvironment = environment;
|
|
345
|
+
this.writeConfig();
|
|
346
|
+
}
|
|
347
|
+
getEnvironment() {
|
|
348
|
+
var _a;
|
|
349
|
+
return (_a = this.environmentOverride) !== null && _a !== void 0 ? _a : this.getGlobalEnvironment();
|
|
350
|
+
}
|
|
351
|
+
/** The `activeEnvironment` the file records, whatever `--cell` or a pin says this store acts on. */
|
|
352
|
+
getGlobalEnvironment() {
|
|
353
|
+
this.loadConfig();
|
|
354
|
+
return this.config.activeEnvironment || environments_1.DEFAULT_DEPLOYMENT;
|
|
355
|
+
}
|
|
356
|
+
/** The cells whose slot holds a token, in the order the file lists them. */
|
|
357
|
+
signedInCells() {
|
|
358
|
+
this.loadConfig();
|
|
359
|
+
return environments_1.ALL_ENVIRONMENTS.filter((env) => {
|
|
360
|
+
const slot = this.config.configPerEnvironment[env];
|
|
361
|
+
return Boolean((slot === null || slot === void 0 ? void 0 : slot.accessToken) || (slot === null || slot === void 0 ? void 0 : slot.jwtAccessToken) || (slot === null || slot === void 0 ? void 0 : slot.refreshToken));
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Seconds until the API access token expires; negative once it has. Returns
|
|
366
|
+
* `undefined` when there is no decodable expiry — a service-account token or
|
|
367
|
+
* a malformed one — so callers can tell "no deadline" from "expires soon".
|
|
368
|
+
*/
|
|
369
|
+
secondsUntilExpiry() {
|
|
370
|
+
var _a;
|
|
371
|
+
const token = this.getApiAccessToken();
|
|
372
|
+
const exp = (_a = (0, cli_auth_1.decodeJwtClaims)(token)) === null || _a === void 0 ? void 0 : _a.exp;
|
|
373
|
+
if (!exp)
|
|
374
|
+
return undefined;
|
|
375
|
+
return exp - Math.floor(Date.now() / 1000);
|
|
376
|
+
}
|
|
377
|
+
isTokenValid() {
|
|
378
|
+
var _a;
|
|
379
|
+
const envConfig = this.currentEnvConfig();
|
|
380
|
+
if (!this.getApiAccessToken()) {
|
|
381
|
+
// "Nothing stored" and "something stored that we cannot use" are
|
|
382
|
+
// different problems and have different fixes, so they keep different
|
|
383
|
+
// messages. Since `resolveTokens` stopped falling back to the raw
|
|
384
|
+
// field, an unusable token reaches here rather than being handed on —
|
|
385
|
+
// without this branch it would be reported as an empty store, which
|
|
386
|
+
// sends someone looking for a login that already happened.
|
|
387
|
+
const stored = (_a = envConfig.accessToken) !== null && _a !== void 0 ? _a : envConfig.jwtAccessToken;
|
|
388
|
+
return {
|
|
389
|
+
valid: false,
|
|
390
|
+
reason: stored
|
|
391
|
+
? "Invalid token format. Please login again."
|
|
392
|
+
: "No token found. Please login.",
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
if (envConfig.isServiceAccountToken) {
|
|
396
|
+
return { valid: true };
|
|
397
|
+
}
|
|
398
|
+
const remaining = this.secondsUntilExpiry();
|
|
399
|
+
if (remaining === undefined) {
|
|
400
|
+
return {
|
|
401
|
+
valid: false,
|
|
402
|
+
reason: "Invalid token format. Please login again.",
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (remaining <= 0) {
|
|
406
|
+
return {
|
|
407
|
+
valid: false,
|
|
408
|
+
reason: "Token expired. Please login again.",
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
return { valid: true };
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
exports.ClientConfiguration = ClientConfiguration;
|
|
415
|
+
//# sourceMappingURL=credstore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credstore.js","sourceRoot":"","sources":["../../src/setup-core/credstore.ts"],"names":[],"mappings":";;;;;;AAgGA,sCAKC;AArGD,oDAA4B;AAC5B,4CAAoB;AACpB,qDAIgC;AAChC,4CAAoB;AAGpB,iDAKwB;AACxB,2CAA8C;AA+D9C;;;;;;GAMG;AACH,MAAa,kBAAmB,SAAQ,KAAK;CAAG;AAAhD,gDAAgD;AAEhD;;;;;;;GAOG;AACH,SAAgB,aAAa,CAC1B,MAAuB,EACvB,WAAwB;IAExB,OAAO,IAAA,wBAAmB,EAAC,MAAM,EAAE,gCAAiB,CAAC,WAAW,CAAC,CAAC,CAAC;AACtE,CAAC;AAYD,MAAa,mBAAmB;IAI7B;;;;;;;;;;;;;OAaG;IACI,MAAM,CAAC,YAAY,CAAC,KAA+B;QACvD,mBAAmB,CAAC,YAAY,GAAG,KAAK,CAAC;IAC5C,CAAC;IAOD;;;;;;;;;OASG;IACH,YAAY,gBAAyB,EAAE,mBAAiC;;QAfhE,eAAU,GAAG,GAAG,YAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;QAgB1C,IAAI,gBAAgB,EAAE,CAAC;YACpB,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC;QACtC,CAAC;QACD,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,gBAAgB,IAAI,CAAC,mBAAm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AE,KAAK;gBACZ,MAAM,EAAE,oCAAoC;aAC9C,CAAC;QACL,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;CACH;AA3aD,kDA2aC"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chai_1 = require("chai");
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const credstore_1 = require("./credstore");
|
|
11
|
+
const environments_1 = require("./environments");
|
|
12
|
+
const PROD = environments_1.auth0ConfigsByEnv.production;
|
|
13
|
+
/**
|
|
14
|
+
* Build a decodable (unsigned) JWT. `aud` is the only claim that matters here:
|
|
15
|
+
* it is what tells an access token from an id token.
|
|
16
|
+
*/
|
|
17
|
+
function jwt(claims) {
|
|
18
|
+
const part = (value) => Buffer.from(JSON.stringify(value)).toString("base64url");
|
|
19
|
+
return `${part({ alg: "HS256", typ: "JWT" })}.${part(claims)}.signature`;
|
|
20
|
+
}
|
|
21
|
+
const inOneHour = () => Math.floor(Date.now() / 1000) + 3600;
|
|
22
|
+
// Minted per test, not at load: mocha loads every spec before running any, so
|
|
23
|
+
// a token minted at load has already aged by however long the earlier specs
|
|
24
|
+
// took, which breaks the expiry assertions on a slow CI run.
|
|
25
|
+
/** An Auth0 API access token: audienced to the API. */
|
|
26
|
+
let accessTokenJwt;
|
|
27
|
+
/** An Auth0 id token: audienced to the client id. */
|
|
28
|
+
let idTokenJwt;
|
|
29
|
+
describe("credstore token resolution", () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
accessTokenJwt = jwt({ aud: PROD.audience, exp: inOneHour() });
|
|
32
|
+
idTokenJwt = jwt({
|
|
33
|
+
aud: PROD.clientId,
|
|
34
|
+
exp: inOneHour(),
|
|
35
|
+
email: "a@b.c",
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe("resolveTokens", () => {
|
|
39
|
+
it("reads the CLI's shape: access token in accessToken", () => {
|
|
40
|
+
const resolved = (0, credstore_1.resolveTokens)({ accessToken: accessTokenJwt, jwtAccessToken: accessTokenJwt }, "production");
|
|
41
|
+
(0, chai_1.expect)(resolved.apiAccessToken).to.equal(accessTokenJwt);
|
|
42
|
+
});
|
|
43
|
+
it("reads the extension's shape: id token in accessToken, access token in jwtAccessToken", () => {
|
|
44
|
+
// This is the case that motivates claim-based resolution. Reading
|
|
45
|
+
// `accessToken` by name here would hand an id token to the control
|
|
46
|
+
// plane as a Bearer credential.
|
|
47
|
+
const resolved = (0, credstore_1.resolveTokens)({ accessToken: idTokenJwt, jwtAccessToken: accessTokenJwt }, "production");
|
|
48
|
+
(0, chai_1.expect)(resolved.apiAccessToken).to.equal(accessTokenJwt);
|
|
49
|
+
(0, chai_1.expect)(resolved.idToken).to.equal(idTokenJwt);
|
|
50
|
+
});
|
|
51
|
+
it("prefers the explicit idToken field when this CLI wrote it", () => {
|
|
52
|
+
const otherIdToken = jwt({ aud: PROD.clientId, exp: inOneHour() });
|
|
53
|
+
const resolved = (0, credstore_1.resolveTokens)({
|
|
54
|
+
accessToken: accessTokenJwt,
|
|
55
|
+
jwtAccessToken: accessTokenJwt,
|
|
56
|
+
idToken: otherIdToken,
|
|
57
|
+
}, "production");
|
|
58
|
+
(0, chai_1.expect)(resolved.apiAccessToken).to.equal(accessTokenJwt);
|
|
59
|
+
(0, chai_1.expect)(resolved.idToken).to.equal(otherIdToken);
|
|
60
|
+
});
|
|
61
|
+
// The CLI wrote `idToken`; the extension then refreshed, putting a new id
|
|
62
|
+
// token in `accessToken` and leaving the CLI's field behind. The explicit
|
|
63
|
+
// field used to win, so `getIdToken` returned the stale one.
|
|
64
|
+
it("prefers an id token the extension wrote after the CLI's explicit field", () => {
|
|
65
|
+
const staleIdToken = jwt({
|
|
66
|
+
aud: PROD.clientId,
|
|
67
|
+
exp: inOneHour() - 60,
|
|
68
|
+
});
|
|
69
|
+
const resolved = (0, credstore_1.resolveTokens)({
|
|
70
|
+
accessToken: idTokenJwt,
|
|
71
|
+
jwtAccessToken: accessTokenJwt,
|
|
72
|
+
idToken: staleIdToken,
|
|
73
|
+
}, "production");
|
|
74
|
+
(0, chai_1.expect)(resolved.apiAccessToken).to.equal(accessTokenJwt);
|
|
75
|
+
(0, chai_1.expect)(resolved.idToken).to.equal(idTokenJwt);
|
|
76
|
+
});
|
|
77
|
+
it("returns nothing for a token whose audience it cannot recognise", () => {
|
|
78
|
+
// There used to be a `?? stored.accessToken` fallback here, justified
|
|
79
|
+
// by service-account tokens. `getApiAccessToken` returns those before
|
|
80
|
+
// it calls this (asserted below), so the fallback could only ever fire
|
|
81
|
+
// for a *user* token — where an unrecognised `accessToken` is most
|
|
82
|
+
// likely the extension's id token, which then went into a Bearer
|
|
83
|
+
// header. Better to say we have nothing than to send the wrong thing.
|
|
84
|
+
const opaque = jwt({ exp: inOneHour() });
|
|
85
|
+
const resolved = (0, credstore_1.resolveTokens)({ accessToken: opaque }, "production");
|
|
86
|
+
(0, chai_1.expect)(resolved.apiAccessToken).to.equal(undefined);
|
|
87
|
+
(0, chai_1.expect)(resolved.idToken).to.equal(undefined);
|
|
88
|
+
});
|
|
89
|
+
it("tolerates an undecodable token without throwing", () => {
|
|
90
|
+
const resolved = (0, credstore_1.resolveTokens)({ accessToken: "not-a-jwt" }, "production");
|
|
91
|
+
(0, chai_1.expect)(resolved.apiAccessToken).to.equal(undefined);
|
|
92
|
+
});
|
|
93
|
+
// The exact state the VS Code extension's `clearState()` leaves behind:
|
|
94
|
+
// `jwtAccessToken` and `refreshToken` blanked, `accessToken` still
|
|
95
|
+
// holding a stale id token. Returning that as the API token got a 401
|
|
96
|
+
// from the control plane; returning nothing gets "run `cred login`".
|
|
97
|
+
it("does not hand back the id token the extension leaves after a sign-out", () => {
|
|
98
|
+
const staleIdToken = jwt({
|
|
99
|
+
aud: environments_1.auth0ConfigsByEnv.production.clientId,
|
|
100
|
+
exp: inOneHour(),
|
|
101
|
+
});
|
|
102
|
+
const resolved = (0, credstore_1.resolveTokens)({ accessToken: staleIdToken, jwtAccessToken: "" }, "production");
|
|
103
|
+
(0, chai_1.expect)(resolved.apiAccessToken).to.equal(undefined);
|
|
104
|
+
(0, chai_1.expect)(resolved.idToken).to.equal(staleIdToken);
|
|
105
|
+
});
|
|
106
|
+
it("resolves against the audience of the deployment env it is given", () => {
|
|
107
|
+
const devToken = jwt({
|
|
108
|
+
aud: environments_1.auth0ConfigsByEnv.dev.audience,
|
|
109
|
+
exp: inOneHour(),
|
|
110
|
+
});
|
|
111
|
+
// Audienced to dev, so it is NOT the production API token: production
|
|
112
|
+
// resolution finds no match and falls back.
|
|
113
|
+
(0, chai_1.expect)((0, credstore_1.resolveTokens)({ jwtAccessToken: devToken }, "production")
|
|
114
|
+
.apiAccessToken).to.equal(undefined);
|
|
115
|
+
(0, chai_1.expect)((0, credstore_1.resolveTokens)({ jwtAccessToken: devToken }, "dev").apiAccessToken).to.equal(devToken);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe("ClientConfiguration against a real file", () => {
|
|
119
|
+
let configPath;
|
|
120
|
+
beforeEach(() => {
|
|
121
|
+
configPath = (0, path_1.join)(fs_1.default.mkdtempSync((0, path_1.join)(os_1.default.tmpdir(), "credstore-")), ".cred");
|
|
122
|
+
});
|
|
123
|
+
afterEach(() => {
|
|
124
|
+
fs_1.default.rmSync(configPath, { force: true });
|
|
125
|
+
});
|
|
126
|
+
function write(envConfig) {
|
|
127
|
+
fs_1.default.writeFileSync(configPath, JSON.stringify({
|
|
128
|
+
configPerEnvironment: { production: envConfig },
|
|
129
|
+
activeEnvironment: "production",
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
it("sends the access token as Bearer even when the extension wrote the file last", () => {
|
|
133
|
+
write({ accessToken: idTokenJwt, jwtAccessToken: accessTokenJwt });
|
|
134
|
+
const config = new credstore_1.ClientConfiguration(configPath);
|
|
135
|
+
(0, chai_1.expect)(config.getAuthenticationHeader()).to.equal(`Bearer ${accessTokenJwt}`);
|
|
136
|
+
});
|
|
137
|
+
it("sends a service-account token as ApiKey and does not classify it", () => {
|
|
138
|
+
write({ accessToken: "sa-token", isServiceAccountToken: true });
|
|
139
|
+
const config = new credstore_1.ClientConfiguration(configPath);
|
|
140
|
+
(0, chai_1.expect)(config.getAuthenticationHeader()).to.equal("ApiKey sa-token");
|
|
141
|
+
(0, chai_1.expect)(config.isTokenValid().valid).to.equal(true);
|
|
142
|
+
});
|
|
143
|
+
it("setTokenPair writes a shape the extension can still read", () => {
|
|
144
|
+
const config = new credstore_1.ClientConfiguration(configPath);
|
|
145
|
+
config.setTokenPair({
|
|
146
|
+
accessToken: accessTokenJwt,
|
|
147
|
+
idToken: idTokenJwt,
|
|
148
|
+
refreshToken: "refresh-me",
|
|
149
|
+
});
|
|
150
|
+
const onDisk = JSON.parse(fs_1.default.readFileSync(configPath, "utf-8"))
|
|
151
|
+
.configPerEnvironment.production;
|
|
152
|
+
// The extension takes the access token from `jwtAccessToken`; keeping
|
|
153
|
+
// it correct is what makes this change invisible to it.
|
|
154
|
+
(0, chai_1.expect)(onDisk.jwtAccessToken).to.equal(accessTokenJwt);
|
|
155
|
+
(0, chai_1.expect)(onDisk.accessToken).to.equal(accessTokenJwt);
|
|
156
|
+
(0, chai_1.expect)(onDisk.idToken).to.equal(idTokenJwt);
|
|
157
|
+
(0, chai_1.expect)(onDisk.refreshToken).to.equal("refresh-me");
|
|
158
|
+
(0, chai_1.expect)(onDisk.isServiceAccountToken).to.equal(false);
|
|
159
|
+
});
|
|
160
|
+
it("keeps the stored refresh token when a refresh does not rotate it", () => {
|
|
161
|
+
const config = new credstore_1.ClientConfiguration(configPath);
|
|
162
|
+
config.setTokenPair({
|
|
163
|
+
accessToken: accessTokenJwt,
|
|
164
|
+
refreshToken: "original",
|
|
165
|
+
});
|
|
166
|
+
config.setTokenPair({ accessToken: accessTokenJwt });
|
|
167
|
+
(0, chai_1.expect)(config.getRefreshToken()).to.equal("original");
|
|
168
|
+
});
|
|
169
|
+
it("clearTokens removes the tokens from disk and keeps the organization and environment", () => {
|
|
170
|
+
write({
|
|
171
|
+
accessToken: accessTokenJwt,
|
|
172
|
+
jwtAccessToken: accessTokenJwt,
|
|
173
|
+
idToken: idTokenJwt,
|
|
174
|
+
refreshToken: "dead",
|
|
175
|
+
isServiceAccountToken: false,
|
|
176
|
+
organization: "acme",
|
|
177
|
+
project: "sales",
|
|
178
|
+
});
|
|
179
|
+
// Not pinned to a deployment, so clearTokens resolves it from the
|
|
180
|
+
// file, which reloads the config it is about to edit.
|
|
181
|
+
new credstore_1.ClientConfiguration(configPath).clearTokens();
|
|
182
|
+
const onDisk = JSON.parse(fs_1.default.readFileSync(configPath, "utf-8"))
|
|
183
|
+
.configPerEnvironment.production;
|
|
184
|
+
(0, chai_1.expect)(onDisk).to.eql({ organization: "acme", project: "sales" });
|
|
185
|
+
});
|
|
186
|
+
describe("secondsUntilExpiry", () => {
|
|
187
|
+
it("is positive for a live token and negative for a dead one", () => {
|
|
188
|
+
write({ jwtAccessToken: accessTokenJwt });
|
|
189
|
+
(0, chai_1.expect)(new credstore_1.ClientConfiguration(configPath).secondsUntilExpiry()).to.be.greaterThan(3500);
|
|
190
|
+
write({
|
|
191
|
+
jwtAccessToken: jwt({
|
|
192
|
+
aud: PROD.audience,
|
|
193
|
+
exp: Math.floor(Date.now() / 1000) - 60,
|
|
194
|
+
}),
|
|
195
|
+
});
|
|
196
|
+
(0, chai_1.expect)(new credstore_1.ClientConfiguration(configPath).secondsUntilExpiry()).to.be.lessThan(0);
|
|
197
|
+
});
|
|
198
|
+
it("is undefined when there is no decodable expiry", () => {
|
|
199
|
+
write({ accessToken: "sa-token", isServiceAccountToken: true });
|
|
200
|
+
(0, chai_1.expect)(new credstore_1.ClientConfiguration(configPath).secondsUntilExpiry()).to.equal(undefined);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
describe("isTokenValid", () => {
|
|
204
|
+
it("names the specific problem rather than a generic failure", () => {
|
|
205
|
+
write({});
|
|
206
|
+
(0, chai_1.expect)(new credstore_1.ClientConfiguration(configPath).isTokenValid()).to.eql({
|
|
207
|
+
valid: false,
|
|
208
|
+
reason: "No token found. Please login.",
|
|
209
|
+
});
|
|
210
|
+
write({
|
|
211
|
+
jwtAccessToken: jwt({
|
|
212
|
+
aud: PROD.audience,
|
|
213
|
+
exp: Math.floor(Date.now() / 1000) - 60,
|
|
214
|
+
}),
|
|
215
|
+
});
|
|
216
|
+
(0, chai_1.expect)(new credstore_1.ClientConfiguration(configPath).isTokenValid()).to.eql({
|
|
217
|
+
valid: false,
|
|
218
|
+
reason: "Token expired. Please login again.",
|
|
219
|
+
});
|
|
220
|
+
write({ accessToken: "not-a-jwt" });
|
|
221
|
+
(0, chai_1.expect)(new credstore_1.ClientConfiguration(configPath).isTokenValid()).to.eql({
|
|
222
|
+
valid: false,
|
|
223
|
+
reason: "Invalid token format. Please login again.",
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
it("reports a non-string token field as an invalid token, not a crash", () => {
|
|
227
|
+
for (const bad of [42, true, {}, ["a.b.c"]]) {
|
|
228
|
+
write({ accessToken: bad });
|
|
229
|
+
(0, chai_1.expect)(new credstore_1.ClientConfiguration(configPath).isTokenValid()).to.eql({
|
|
230
|
+
valid: false,
|
|
231
|
+
reason: "Invalid token format. Please login again.",
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
//# sourceMappingURL=credstore.spec.js.map
|