-
Notifications
You must be signed in to change notification settings - Fork 3
feat: multitenancy support #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 61 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
0f9eaa9
add manual req
SirSimon04 e6bc5a9
fixes
SirSimon04 6089a7b
fix
SirSimon04 851d861
fix
SirSimon04 c30b6bb
update to bearer
SirSimon04 4f8f9c8
update to jwt
SirSimon04 b3e70be
update for print function
SirSimon04 261684c
update
SirSimon04 83198a1
update
SirSimon04 8d60225
fix
SirSimon04 b276440
update to fetch
SirSimon04 5432176
use res.jsn
SirSimon04 bcb1310
fixes
SirSimon04 1543052
fix
SirSimon04 355018d
update
SirSimon04 e62a8cf
udpate
SirSimon04 762764b
add tentant id t request
SirSimon04 946aa31
refactoring to use cache and utils
SirSimon04 fefd202
update token cache
SirSimon04 2c0fd98
fixes
SirSimon04 a8829d5
fix
SirSimon04 5ca8d2a
update
SirSimon04 590038b
remove cloud sdk
SirSimon04 edfa1b2
fix
SirSimon04 cfde832
fix
SirSimon04 ec61dcd
update
SirSimon04 6d59a06
update
SirSimon04 b841e83
changes
SirSimon04 e1dd342
polished
SirSimon04 3b5475a
comment
SirSimon04 5fc0bb4
update lint config
SirSimon04 1cc406f
Update srv/BTPPrintService.js
SirSimon04 52400f0
Update srv/BTPPrintService.js
SirSimon04 4afcded
Update srv/BTPPrintService.js
SirSimon04 3cbe484
update error handling
SirSimon04 445e5c9
update error handling
SirSimon04 e892f13
updates
SirSimon04 48a4abd
update creds
SirSimon04 a9dc1ae
try to use xssec
SirSimon04 2d6eedb
update vcap.tag
SirSimon04 09dd720
update cds.requires
SirSimon04 11a974f
update label
SirSimon04 e9e4466
remove param
SirSimon04 c2d4ce7
add cache back in
SirSimon04 f3f6064
update deps
SirSimon04 4adbcdd
try
SirSimon04 d91b008
change name to PrintService
SirSimon04 b0fd21d
try
SirSimon04 8c731c1
Revert "try"
SirSimon04 4a6b5d8
add zone id
SirSimon04 24942bc
remoce zid
SirSimon04 9b8d9be
add zoneid back in
SirSimon04 4d4e9e0
lint
SirSimon04 2d6a7c9
change name to print again
SirSimon04 249dd54
only add zid when needed
SirSimon04 fb0ecd1
make service internal
SirSimon04 72ef3fc
remove package update
SirSimon04 4c06fb6
Update srv/BTPPrintService.js
SirSimon04 b9842f1
update error handling
SirSimon04 160ffec
update test package.json
SirSimon04 9dc8de2
Changelog
SirSimon04 977dd0c
Update srv/localPrintService.js
SirSimon04 4ad8c84
prettier
SirSimon04 b47407e
update error handling
SirSimon04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| const { XsuaaService } = require("@sap/xssec"); | ||
|
|
||
| const getServiceCredentials = (name) => (cds?.env?.requires[name] || [])?.credentials; | ||
|
|
||
| async function getServiceToken(serviceName) { | ||
| const srvCredentials = getServiceCredentials(serviceName); | ||
| if (!srvCredentials) { | ||
| throw new Error(`Missing binding credentials for service "${serviceName}"`); | ||
| } | ||
|
|
||
| const tenantId = cds.context?.tenant; | ||
| const xsuaaService = new XsuaaService(srvCredentials.uaa); | ||
| const { access_token: jwt, expires_in } = await xsuaaService.fetchClientCredentialsToken({ | ||
| ...(tenantId && { zid: tenantId }), | ||
| }); | ||
|
|
||
| if (!jwt) { | ||
| throw new Error( | ||
| `Empty JWT returned from authorization service for bound service "${serviceName}"`, | ||
| ); | ||
| } | ||
|
|
||
| return { jwt, expires_in }; | ||
| } | ||
|
|
||
| module.exports = { | ||
| getServiceToken, | ||
| getServiceCredentials, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| const cds = require("@sap/cds"); | ||
| const LOG = cds.log("print"); | ||
|
|
||
| module.exports = class TokenCache { | ||
| constructor() { | ||
| this.cache = new Map(); | ||
| } | ||
|
|
||
| set(key, token, expiresIn) { | ||
| const expiresAt = Date.now() + expiresIn * 1000; | ||
| this.cache.set(key, { token, expiresAt }); | ||
| LOG.debug(`Token set for key: ${key}, expires in ${expiresIn} seconds.`); | ||
| } | ||
|
|
||
| get(key) { | ||
| const entry = this.cache.get(key); | ||
| if (!entry) { | ||
| LOG.debug(`No token found for key: ${key}.`); | ||
| return undefined; | ||
| } | ||
| if (Date.now() >= entry.expiresAt) { | ||
| this.cache.delete(key); | ||
| LOG.debug(`Token expired for key: ${key}.`); | ||
| return undefined; | ||
| } | ||
| LOG.debug(`Token retrieved for key: ${key}.`); | ||
| return entry.token; | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.