Skip to content

Commit

Permalink
perf(oauth): update suffix for oauth in spec parser (#11468)
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethBWSong authored Apr 25, 2024
1 parent 54aac78 commit 2d5f978
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion packages/spec-parser/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ export class ConstantString {
static readonly TextBlockType = "TextBlock";
static readonly ImageType = "Image";
static readonly ContainerType = "Container";
static readonly RegistrationIdPostfix = "REGISTRATION_ID";
static readonly RegistrationIdPostfix: { [key: string]: string } = {
apiKey: "REGISTRATION_ID",
oauth2: "CONFIGURATION_ID",
http: "REGISTRATION_ID",
openIdConnect: "REGISTRATION_ID",
};
static readonly ResponseCodeFor20X = [
"200",
"201",
Expand Down
6 changes: 3 additions & 3 deletions packages/spec-parser/src/manifestUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class ManifestUpdater {

if (pluginAuthObj.type !== "None") {
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(
`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`
`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`
);

pluginAuthObj.reference_id = `\${{${safeRegistrationIdName}}}`;
Expand Down Expand Up @@ -384,11 +384,11 @@ export class ManifestUpdater {
if (authInfo) {
const auth = authInfo.authScheme;
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(
`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`
`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`
);
if (Utils.isAPIKeyAuth(auth) || Utils.isBearerTokenAuth(auth)) {
const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(
`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`
`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`
);
(composeExtension as any).authorization = {
authType: "apiSecretServiceAuth",
Expand Down
4 changes: 2 additions & 2 deletions packages/spec-parser/test/manifestUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ describe("updateManifestWithAiPlugin", () => {
type: "OpenApi",
auth: {
type: "OAuthPluginVault",
reference_id: "${{OAUTH_REGISTRATION_ID}}",
reference_id: "${{OAUTH_CONFIGURATION_ID}}",
},
spec: {
url: "spec/outputSpec.yaml",
Expand Down Expand Up @@ -3685,7 +3685,7 @@ describe("manifestUpdater", () => {
authorization: {
authType: "oAuth2.0",
oAuthConfiguration: {
oauthConfigurationId: "${{OAUTH_AUTH_REGISTRATION_ID}}",
oauthConfigurationId: "${{OAUTH_AUTH_CONFIGURATION_ID}}",
},
},
commands: [
Expand Down

0 comments on commit 2d5f978

Please sign in to comment.