Use schema/validation for existing OIDC config types

This commit is contained in:
Michael B. Gale
2026-04-25 15:41:11 +01:00
parent 243c274daf
commit 0752451507
2 changed files with 142 additions and 153 deletions
+112 -89
View File
@@ -49285,7 +49285,7 @@ var require_validator = __commonJS({
if (typeof ref == "string") return ref;
return false;
}
Validator2.prototype.validateSchema = function validateSchema(instance, schema2, options, ctx) {
Validator2.prototype.validateSchema = function validateSchema2(instance, schema2, options, ctx) {
var result = new ValidatorResult(instance, schema2, options, ctx);
if (typeof schema2 === "boolean") {
if (schema2 === true) {
@@ -96412,14 +96412,14 @@ var require_reflection_json_writer = __commonJS({
/**
* Returns `null` as the default for google.protobuf.NullValue.
*/
enum(type2, value, fieldName, optional, emitDefaultValues, enumAsInteger) {
enum(type2, value, fieldName, optional2, emitDefaultValues, enumAsInteger) {
if (type2[0] == "google.protobuf.NullValue")
return !emitDefaultValues && !optional ? void 0 : null;
return !emitDefaultValues && !optional2 ? void 0 : null;
if (value === void 0) {
assert_1.assert(optional);
assert_1.assert(optional2);
return void 0;
}
if (value === 0 && !emitDefaultValues && !optional)
if (value === 0 && !emitDefaultValues && !optional2)
return void 0;
assert_1.assert(typeof value == "number");
assert_1.assert(Number.isInteger(value));
@@ -96434,12 +96434,12 @@ var require_reflection_json_writer = __commonJS({
return options.emitDefaultValues ? null : void 0;
return type2.internalJsonWrite(value, options);
}
scalar(type2, value, fieldName, optional, emitDefaultValues) {
scalar(type2, value, fieldName, optional2, emitDefaultValues) {
if (value === void 0) {
assert_1.assert(optional);
assert_1.assert(optional2);
return void 0;
}
const ed = emitDefaultValues || optional;
const ed = emitDefaultValues || optional2;
switch (type2) {
// int32, fixed32, uint32: JSON value will be a decimal number. Either numbers or strings are accepted.
case reflection_info_1.ScalarType.INT32:
@@ -118242,10 +118242,10 @@ function extend(target, source) {
}
return target;
}
function repeat(string, count) {
function repeat(string2, count) {
var result = "", cycle;
for (cycle = 0; cycle < count; cycle += 1) {
result += string;
result += string2;
}
return result;
}
@@ -118314,8 +118314,8 @@ function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
// relative position
};
}
function padStart(string, max) {
return common.repeat(" ", max - string.length) + string;
function padStart(string2, max) {
return common.repeat(" ", max - string2.length) + string2;
}
function makeSnippet(mark, options) {
options = Object.create(options || null);
@@ -120253,8 +120253,8 @@ function compileStyleMap(schema2, map2) {
return result;
}
function encodeHex(character) {
var string, handle, length;
string = character.toString(16).toUpperCase();
var string2, handle, length;
string2 = character.toString(16).toUpperCase();
if (character <= 255) {
handle = "x";
length = 2;
@@ -120267,7 +120267,7 @@ function encodeHex(character) {
} else {
throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
}
return "\\" + handle + common.repeat("0", length - string.length) + string;
return "\\" + handle + common.repeat("0", length - string2.length) + string2;
}
var QUOTING_TYPE_SINGLE = 1;
var QUOTING_TYPE_DOUBLE = 2;
@@ -120293,15 +120293,15 @@ function State(options) {
this.duplicates = [];
this.usedDuplicates = null;
}
function indentString(string, spaces) {
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
function indentString(string2, spaces) {
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string2.length;
while (position < length) {
next = string.indexOf("\n", position);
next = string2.indexOf("\n", position);
if (next === -1) {
line = string.slice(position);
line = string2.slice(position);
position = length;
} else {
line = string.slice(position, next + 1);
line = string2.slice(position, next + 1);
position = next + 1;
}
if (line.length && line !== "\n") result += ind;
@@ -120348,26 +120348,26 @@ function isPlainSafeFirst(c) {
function isPlainSafeLast(c) {
return !isWhitespace(c) && c !== CHAR_COLON;
}
function codePointAt(string, pos) {
var first = string.charCodeAt(pos), second;
if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
second = string.charCodeAt(pos + 1);
function codePointAt(string2, pos) {
var first = string2.charCodeAt(pos), second;
if (first >= 55296 && first <= 56319 && pos + 1 < string2.length) {
second = string2.charCodeAt(pos + 1);
if (second >= 56320 && second <= 57343) {
return (first - 55296) * 1024 + second - 56320 + 65536;
}
}
return first;
}
function needIndentIndicator(string) {
function needIndentIndicator(string2) {
var leadingSpaceRe = /^\n* /;
return leadingSpaceRe.test(string);
return leadingSpaceRe.test(string2);
}
var STYLE_PLAIN = 1;
var STYLE_SINGLE = 2;
var STYLE_LITERAL = 3;
var STYLE_FOLDED = 4;
var STYLE_DOUBLE = 5;
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
function chooseScalarStyle(string2, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
var i;
var char = 0;
var prevChar = null;
@@ -120375,10 +120375,10 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te
var hasFoldableLine = false;
var shouldTrackWidth = lineWidth !== -1;
var previousLineBreak = -1;
var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
var plain = isPlainSafeFirst(codePointAt(string2, 0)) && isPlainSafeLast(codePointAt(string2, string2.length - 1));
if (singleLineOnly || forceQuotes) {
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
char = codePointAt(string, i);
for (i = 0; i < string2.length; char >= 65536 ? i += 2 : i++) {
char = codePointAt(string2, i);
if (!isPrintable(char)) {
return STYLE_DOUBLE;
}
@@ -120386,13 +120386,13 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te
prevChar = char;
}
} else {
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
char = codePointAt(string, i);
for (i = 0; i < string2.length; char >= 65536 ? i += 2 : i++) {
char = codePointAt(string2, i);
if (char === CHAR_LINE_FEED) {
hasLineBreak = true;
if (shouldTrackWidth) {
hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
i - previousLineBreak - 1 > lineWidth && string2[previousLineBreak + 1] !== " ";
previousLineBreak = i;
}
} else if (!isPrintable(char)) {
@@ -120401,15 +120401,15 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te
plain = plain && isPlainSafe(char, prevChar, inblock);
prevChar = char;
}
hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string2[previousLineBreak + 1] !== " ");
}
if (!hasLineBreak && !hasFoldableLine) {
if (plain && !forceQuotes && !testAmbiguousType(string)) {
if (plain && !forceQuotes && !testAmbiguousType(string2)) {
return STYLE_PLAIN;
}
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
}
if (indentPerLevel > 9 && needIndentIndicator(string)) {
if (indentPerLevel > 9 && needIndentIndicator(string2)) {
return STYLE_DOUBLE;
}
if (!forceQuotes) {
@@ -120417,24 +120417,24 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te
}
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
}
function writeScalar(state, string, level, iskey, inblock) {
function writeScalar(state, string2, level, iskey, inblock) {
state.dump = (function() {
if (string.length === 0) {
if (string2.length === 0) {
return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
}
if (!state.noCompatMode) {
if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string2) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string2)) {
return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string2 + '"' : "'" + string2 + "'";
}
}
var indent = state.indent * Math.max(1, level);
var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
function testAmbiguity(string2) {
return testImplicitResolving(state, string2);
function testAmbiguity(string3) {
return testImplicitResolving(state, string3);
}
switch (chooseScalarStyle(
string,
string2,
singleLineOnly,
state.indent,
lineWidth,
@@ -120444,42 +120444,42 @@ function writeScalar(state, string, level, iskey, inblock) {
inblock
)) {
case STYLE_PLAIN:
return string;
return string2;
case STYLE_SINGLE:
return "'" + string.replace(/'/g, "''") + "'";
return "'" + string2.replace(/'/g, "''") + "'";
case STYLE_LITERAL:
return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
return "|" + blockHeader(string2, state.indent) + dropEndingNewline(indentString(string2, indent));
case STYLE_FOLDED:
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
return ">" + blockHeader(string2, state.indent) + dropEndingNewline(indentString(foldString(string2, lineWidth), indent));
case STYLE_DOUBLE:
return '"' + escapeString(string) + '"';
return '"' + escapeString(string2) + '"';
default:
throw new exception("impossible error: invalid scalar style");
}
})();
}
function blockHeader(string, indentPerLevel) {
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
var clip = string[string.length - 1] === "\n";
var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
function blockHeader(string2, indentPerLevel) {
var indentIndicator = needIndentIndicator(string2) ? String(indentPerLevel) : "";
var clip = string2[string2.length - 1] === "\n";
var keep = clip && (string2[string2.length - 2] === "\n" || string2 === "\n");
var chomp = keep ? "+" : clip ? "" : "-";
return indentIndicator + chomp + "\n";
}
function dropEndingNewline(string) {
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
function dropEndingNewline(string2) {
return string2[string2.length - 1] === "\n" ? string2.slice(0, -1) : string2;
}
function foldString(string, width) {
function foldString(string2, width) {
var lineRe = /(\n+)([^\n]*)/g;
var result = (function() {
var nextLF = string.indexOf("\n");
nextLF = nextLF !== -1 ? nextLF : string.length;
var nextLF = string2.indexOf("\n");
nextLF = nextLF !== -1 ? nextLF : string2.length;
lineRe.lastIndex = nextLF;
return foldLine(string.slice(0, nextLF), width);
return foldLine(string2.slice(0, nextLF), width);
})();
var prevMoreIndented = string[0] === "\n" || string[0] === " ";
var prevMoreIndented = string2[0] === "\n" || string2[0] === " ";
var moreIndented;
var match;
while (match = lineRe.exec(string)) {
while (match = lineRe.exec(string2)) {
var prefix = match[1], line = match[2];
moreIndented = line[0] === " ";
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
@@ -120510,16 +120510,16 @@ function foldLine(line, width) {
}
return result.slice(1);
}
function escapeString(string) {
function escapeString(string2) {
var result = "";
var char = 0;
var escapeSeq;
for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
char = codePointAt(string, i);
for (var i = 0; i < string2.length; char >= 65536 ? i += 2 : i++) {
char = codePointAt(string2, i);
escapeSeq = ESCAPE_SEQUENCES[char];
if (!escapeSeq && isPrintable(char)) {
result += string[i];
if (char >= 65536) result += string[i + 1];
result += string2[i];
if (char >= 65536) result += string2[i + 1];
} else {
result += escapeSeq || encodeHex(char);
}
@@ -120824,6 +120824,33 @@ function isString(value) {
function isStringOrUndefined(value) {
return value === void 0 || isString(value);
}
var string = {
validate: isString,
required: true
};
function optional(validator) {
return {
validate: (val) => {
return val === void 0 || val === null || validator.validate(val);
},
required: false
};
}
function validateSchema(schema2, obj) {
for (const [key, validator] of Object.entries(schema2)) {
const hasKey = key in obj;
if (validator.required && !hasKey) {
return false;
}
if (validator.required && (obj[key] === void 0 || obj[key] === null)) {
return false;
}
if (hasKey && !validator.validate(obj[key])) {
return false;
}
}
return true;
}
// src/util.ts
var GITHUB_DOTCOM_URL = "https://github.com";
@@ -121981,35 +122008,31 @@ function isToken(config) {
}
return "token" in config && isStringOrUndefined(config.token);
}
var azureConfigSchema = {
"tenant-id": string,
"client-id": string
};
function isAzureConfig(config) {
return "tenant-id" in config && "client-id" in config && isDefined2(config["tenant-id"]) && isDefined2(config["client-id"]) && isString(config["tenant-id"]) && isString(config["client-id"]);
return validateSchema(azureConfigSchema, config);
}
var awsConfigSchema = {
"aws-region": string,
"account-id": string,
"role-name": string,
domain: string,
"domain-owner": string,
audience: optional(string)
};
function isAWSConfig(config) {
const requiredProperties = [
"aws-region",
"account-id",
"role-name",
"domain",
"domain-owner"
];
for (const property of requiredProperties) {
if (!(property in config) || !isDefined2(config[property]) || !isString(config[property])) {
return false;
}
}
if ("audience" in config && !isStringOrUndefined(config.audience)) {
return false;
}
return true;
return validateSchema(awsConfigSchema, config);
}
var jfrogConfigSchema = {
"jfrog-oidc-provider-name": string,
audience: optional(string),
"identity-mapping-name": optional(string)
};
function isJFrogConfig(config) {
if ("audience" in config && !isStringOrUndefined(config.audience)) {
return false;
}
if ("identity-mapping-name" in config && !isStringOrUndefined(config["identity-mapping-name"])) {
return false;
}
return "jfrog-oidc-provider-name" in config && isDefined2(config["jfrog-oidc-provider-name"]) && isString(config["jfrog-oidc-provider-name"]);
return validateSchema(jfrogConfigSchema, config);
}
function credentialToStr(credential) {
let result = `Type: ${credential.type};`;