mirror of
https://github.com/github/codeql-action.git
synced 2026-05-08 14:50:21 +00:00
Group OIDC schemas into an array
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user