Group OIDC schemas into an array

This commit is contained in:
Michael B. Gale
2026-04-25 17:07:33 +01:00
parent 2acf81942b
commit 530fcb3bbf
6 changed files with 51 additions and 52 deletions
+7
View File
@@ -118,6 +118,13 @@ export function isJFrogConfig(
return json.validateSchema(jfrogConfigSchema, config);
}
/** An array of all OIDC configuration schemas along with output-friendly names. */
export const oidcSchemas = [
{ schema: azureConfigSchema, name: "Azure" },
{ schema: awsConfigSchema, name: "AWS" },
{ schema: jfrogConfigSchema, name: "JFrog" },
];
/** Represents all supported OIDC configurations. */
export type OIDC = AzureConfig | AWSConfig | JFrogConfig;
+3 -22
View File
@@ -1,6 +1,7 @@
import test from "ava";
import * as json from "../json";
import { makeFromSchema } from "../json/testing-util";
import { setupTests } from "../testing-utils";
import * as types from "./types";
@@ -8,27 +9,7 @@ import { getAuthConfig } from "./validation";
setupTests(test);
function makeFromSchema(
includeOptional: boolean,
schema: json.Schema,
): json.FromSchema<typeof schema> {
const result = {};
for (const [key, validator] of Object.entries(schema)) {
if (!validator.required && !includeOptional) {
continue;
}
result[key] = `value-for-${key}`;
}
return result;
}
const schemaTests = [
{ schema: types.azureConfigSchema, name: "isAzureConfig" },
{ schema: types.awsConfigSchema, name: "isAWSConfig" },
{ schema: types.jfrogConfigSchema, name: "isJFrogConfig" },
] as Array<{ schema: json.Schema; name: string }>;
for (const schemaTest of schemaTests) {
for (const schemaTest of types.oidcSchemas) {
for (const includeOptional of [true, false]) {
const minimalName = includeOptional ? "full" : "minimal";
@@ -39,7 +20,7 @@ for (const schemaTest of schemaTests) {
getAuthConfig({
...config,
unexpected: "unexpected-value",
} as json.UnvalidatedObject<types.AuthConfig>),
} as unknown as json.UnvalidatedObject<types.AuthConfig>),
config,
);
});
+8 -7
View File
@@ -30,13 +30,14 @@ export function getAuthConfig(
): AuthConfig {
// Start by checking for the OIDC configurations, since they have required properties
// which we can use to identify them.
if (types.isAzureConfig(config)) {
return cloneCredential(types.azureConfigSchema, config);
} else if (types.isAWSConfig(config)) {
return cloneCredential(types.awsConfigSchema, config);
} else if (types.isJFrogConfig(config)) {
return cloneCredential(types.jfrogConfigSchema, config);
} else if (types.isToken(config)) {
for (const oidcSchema of types.oidcSchemas) {
if (json.validateSchema(oidcSchema.schema, config)) {
return cloneCredential(oidcSchema.schema, config);
}
}
// Otherwise, try the basic configuration types.
if (types.isToken(config)) {
// There are three scenarios for non-OIDC authentication based on the registry type:
//
// 1. `username`+`token`