-
Notifications
You must be signed in to change notification settings - Fork 227
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
feat(subscription): support oidcToken #865
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 contains 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 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 |
---|---|---|
|
@@ -47,9 +47,12 @@ import {noop} from './util'; | |
|
||
export type PushConfig = google.pubsub.v1.IPushConfig; | ||
|
||
export type OidcToken = google.pubsub.v1.PushConfig.IOidcToken; | ||
|
||
export type SubscriptionMetadata = { | ||
messageRetentionDuration?: google.protobuf.IDuration | number; | ||
pushEndpoint?: string; | ||
oidcToken?: OidcToken; | ||
} & Omit<google.pubsub.v1.ISubscription, 'messageRetentionDuration'>; | ||
|
||
export type SubscriptionOptions = SubscriberOptions & {topic?: Topic}; | ||
|
@@ -739,6 +742,10 @@ export class Subscription extends EventEmitter { | |
* @param {string} config.pushEndpoint A URL locating the endpoint to which | ||
* messages should be published. | ||
* @param {object} config.attributes [PushConfig attributes](https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#google.pubsub.v1.PushConfig). | ||
* @param {object} config.oidcToken If specified, Pub/Sub will generate and | ||
* attach an OIDC JWT token as an `Authorization` header in the HTTP | ||
* request for every pushed message. This object should have the same | ||
* structure as [OidcToken]{@link google.pubsub.v1.OidcToken} | ||
* @param {object} [gaxOpts] Request configuration options, outlined | ||
* here: https://googleapis.github.io/gax-nodejs/CallSettings.html. | ||
* @param {ModifyPushConfigCallback} [callback] Callback function. | ||
|
@@ -755,6 +762,10 @@ export class Subscription extends EventEmitter { | |
* pushEndpoint: 'https://mydomain.com/push', | ||
* attributes: { | ||
* key: 'value' | ||
* }, | ||
* oidcToken: { | ||
* serviceAccountEmail: '[email protected]', | ||
* audience: 'myaudience' | ||
* } | ||
* }; | ||
* | ||
|
@@ -1039,6 +1050,14 @@ export class Subscription extends EventEmitter { | |
delete formatted.pushEndpoint; | ||
} | ||
|
||
if (metadata.oidcToken) { | ||
formatted.pushConfig = { | ||
...formatted.pushConfig, | ||
oidcToken: metadata.oidcToken, | ||
}; | ||
delete formatted.oidcToken; | ||
} | ||
|
||
return formatted as google.pubsub.v1.ISubscription; | ||
} | ||
/*! | ||
|
This file contains 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 |
---|---|---|
|
@@ -249,6 +249,53 @@ describe('Subscription', () => { | |
undefined | ||
); | ||
}); | ||
|
||
it('should format oidcToken', () => { | ||
const oidcToken = { | ||
serviceAccount: '[email protected]', | ||
audience: 'audience', | ||
}; | ||
|
||
const metadata = { | ||
oidcToken, | ||
}; | ||
|
||
const formatted = Subscription.formatMetadata_(metadata); | ||
|
||
assert.strictEqual(formatted.pushConfig!.oidcToken, oidcToken); | ||
assert.strictEqual( | ||
(formatted as subby.SubscriptionMetadata).oidcToken, | ||
undefined | ||
); | ||
}); | ||
|
||
it('should format both pushEndpoint and oidcToken', () => { | ||
const pushEndpoint = 'http://noop.com/push'; | ||
|
||
const oidcToken = { | ||
serviceAccount: '[email protected]', | ||
audience: 'audience', | ||
}; | ||
|
||
const metadata = { | ||
pushEndpoint, | ||
oidcToken, | ||
}; | ||
|
||
const formatted = Subscription.formatMetadata_(metadata); | ||
|
||
assert.strictEqual(formatted.pushConfig!.pushEndpoint, pushEndpoint); | ||
assert.strictEqual( | ||
(formatted as subby.SubscriptionMetadata).pushEndpoint, | ||
undefined | ||
); | ||
|
||
assert.strictEqual(formatted.pushConfig!.oidcToken, oidcToken); | ||
assert.strictEqual( | ||
(formatted as subby.SubscriptionMetadata).oidcToken, | ||
undefined | ||
); | ||
}); | ||
}); | ||
|
||
describe('formatName_', () => { | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm relatively green in this codebase, but mind clarifying why we need to delete the key off the
formatted
object?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does seem to already be happening above it for
formatted.pushEndpoint
and as well...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was my take as well, oidcToken is just being treated like what's above. My main question is on the sort of systemic goodness of the patch - I don't understand the gestalt of the library enough to say yay or nay yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the changes here just expose access to the underlying API call, and is already exposed in other client libraries. With the exception of deleting the key (is this for memory management?) this is LGTM.