mirror of
https://github.com/github/codeql-action
synced 2026-05-23 20:00:54 +03:00
Group OIDC schemas into an array
This commit is contained in:
Generated
+11
-7
@@ -122045,6 +122045,11 @@ var jfrogConfigSchema = {
|
|||||||
function isJFrogConfig(config) {
|
function isJFrogConfig(config) {
|
||||||
return validateSchema(jfrogConfigSchema, config);
|
return validateSchema(jfrogConfigSchema, config);
|
||||||
}
|
}
|
||||||
|
var oidcSchemas = [
|
||||||
|
{ schema: azureConfigSchema, name: "Azure" },
|
||||||
|
{ schema: awsConfigSchema, name: "AWS" },
|
||||||
|
{ schema: jfrogConfigSchema, name: "JFrog" }
|
||||||
|
];
|
||||||
function credentialToStr(credential) {
|
function credentialToStr(credential) {
|
||||||
let result = `Type: ${credential.type};`;
|
let result = `Type: ${credential.type};`;
|
||||||
const appendIfDefined = (name, val) => {
|
const appendIfDefined = (name, val) => {
|
||||||
@@ -122107,13 +122112,12 @@ function cloneCredential(schema2, obj) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
function getAuthConfig(config) {
|
function getAuthConfig(config) {
|
||||||
if (isAzureConfig(config)) {
|
for (const oidcSchema of oidcSchemas) {
|
||||||
return cloneCredential(azureConfigSchema, config);
|
if (validateSchema(oidcSchema.schema, config)) {
|
||||||
} else if (isAWSConfig(config)) {
|
return cloneCredential(oidcSchema.schema, config);
|
||||||
return cloneCredential(awsConfigSchema, config);
|
}
|
||||||
} else if (isJFrogConfig(config)) {
|
}
|
||||||
return cloneCredential(jfrogConfigSchema, config);
|
if (isToken(config)) {
|
||||||
} else if (isToken(config)) {
|
|
||||||
if (isDefined2(config.token)) {
|
if (isDefined2(config.token)) {
|
||||||
core8.setSecret(config.token);
|
core8.setSecret(config.token);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import * as json from ".";
|
||||||
|
|
||||||
|
export function makeFromSchema<S extends json.Schema>(
|
||||||
|
includeOptional: boolean,
|
||||||
|
schema: S,
|
||||||
|
): json.FromSchema<S> {
|
||||||
|
const result = {};
|
||||||
|
for (const [key, validator] of Object.entries(schema)) {
|
||||||
|
if (!validator.required && !includeOptional) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result[key] = `value-for-${key}`;
|
||||||
|
}
|
||||||
|
return result as json.FromSchema<S>;
|
||||||
|
}
|
||||||
+7
-16
@@ -8,6 +8,7 @@ import sinon from "sinon";
|
|||||||
import * as apiClient from "./api-client";
|
import * as apiClient from "./api-client";
|
||||||
import * as defaults from "./defaults.json";
|
import * as defaults from "./defaults.json";
|
||||||
import { setUpFeatureFlagTests } from "./feature-flags/testing-util";
|
import { setUpFeatureFlagTests } from "./feature-flags/testing-util";
|
||||||
|
import { makeFromSchema } from "./json/testing-util";
|
||||||
import { BuiltInLanguage } from "./languages";
|
import { BuiltInLanguage } from "./languages";
|
||||||
import { getRunnerLogger, Logger } from "./logging";
|
import { getRunnerLogger, Logger } from "./logging";
|
||||||
import * as startProxyExports from "./start-proxy";
|
import * as startProxyExports from "./start-proxy";
|
||||||
@@ -457,23 +458,13 @@ test("getCredentials throws an error when non-printable characters are used for
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("getCredentials accepts OIDC configurations", (t) => {
|
test("getCredentials accepts OIDC configurations", (t) => {
|
||||||
const oidcConfigurations = [
|
const oidcConfigurations = startProxyExports.oidcSchemas.map(
|
||||||
{
|
(schemaInfo) => ({
|
||||||
type: "nuget_feed",
|
type: "nuget_feed",
|
||||||
host: "azure.pkg.github.com",
|
host: `${schemaInfo.name.toLowerCase()}.pkg.github.com`,
|
||||||
...validAzureCredential,
|
...makeFromSchema(true, schemaInfo.schema),
|
||||||
},
|
}),
|
||||||
{
|
);
|
||||||
type: "nuget_feed",
|
|
||||||
host: "aws.pkg.github.com",
|
|
||||||
...validAwsCredential,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "nuget_feed",
|
|
||||||
host: "jfrog.pkg.github.com",
|
|
||||||
...validJFrogCredential,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const credentials = startProxyExports.getCredentials(
|
const credentials = startProxyExports.getCredentials(
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
|
|||||||
@@ -118,6 +118,13 @@ export function isJFrogConfig(
|
|||||||
return json.validateSchema(jfrogConfigSchema, config);
|
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. */
|
/** Represents all supported OIDC configurations. */
|
||||||
export type OIDC = AzureConfig | AWSConfig | JFrogConfig;
|
export type OIDC = AzureConfig | AWSConfig | JFrogConfig;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import test from "ava";
|
import test from "ava";
|
||||||
|
|
||||||
import * as json from "../json";
|
import * as json from "../json";
|
||||||
|
import { makeFromSchema } from "../json/testing-util";
|
||||||
import { setupTests } from "../testing-utils";
|
import { setupTests } from "../testing-utils";
|
||||||
|
|
||||||
import * as types from "./types";
|
import * as types from "./types";
|
||||||
@@ -8,27 +9,7 @@ import { getAuthConfig } from "./validation";
|
|||||||
|
|
||||||
setupTests(test);
|
setupTests(test);
|
||||||
|
|
||||||
function makeFromSchema(
|
for (const schemaTest of types.oidcSchemas) {
|
||||||
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 includeOptional of [true, false]) {
|
for (const includeOptional of [true, false]) {
|
||||||
const minimalName = includeOptional ? "full" : "minimal";
|
const minimalName = includeOptional ? "full" : "minimal";
|
||||||
|
|
||||||
@@ -39,7 +20,7 @@ for (const schemaTest of schemaTests) {
|
|||||||
getAuthConfig({
|
getAuthConfig({
|
||||||
...config,
|
...config,
|
||||||
unexpected: "unexpected-value",
|
unexpected: "unexpected-value",
|
||||||
} as json.UnvalidatedObject<types.AuthConfig>),
|
} as unknown as json.UnvalidatedObject<types.AuthConfig>),
|
||||||
config,
|
config,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,13 +30,14 @@ export function getAuthConfig(
|
|||||||
): AuthConfig {
|
): AuthConfig {
|
||||||
// Start by checking for the OIDC configurations, since they have required properties
|
// Start by checking for the OIDC configurations, since they have required properties
|
||||||
// which we can use to identify them.
|
// which we can use to identify them.
|
||||||
if (types.isAzureConfig(config)) {
|
for (const oidcSchema of types.oidcSchemas) {
|
||||||
return cloneCredential(types.azureConfigSchema, config);
|
if (json.validateSchema(oidcSchema.schema, config)) {
|
||||||
} else if (types.isAWSConfig(config)) {
|
return cloneCredential(oidcSchema.schema, config);
|
||||||
return cloneCredential(types.awsConfigSchema, config);
|
}
|
||||||
} else if (types.isJFrogConfig(config)) {
|
}
|
||||||
return cloneCredential(types.jfrogConfigSchema, config);
|
|
||||||
} else if (types.isToken(config)) {
|
// Otherwise, try the basic configuration types.
|
||||||
|
if (types.isToken(config)) {
|
||||||
// There are three scenarios for non-OIDC authentication based on the registry type:
|
// There are three scenarios for non-OIDC authentication based on the registry type:
|
||||||
//
|
//
|
||||||
// 1. `username`+`token`
|
// 1. `username`+`token`
|
||||||
|
|||||||
Reference in New Issue
Block a user