Add configurable expiration for Seal and Hose assistance links
This commit is contained in:
1 parent
f6cd2c68b0
commit
932957ea08
9 files changed
+323
-30
No files matched your search
+90
-2
@@ -48,7 +48,7 @@ export const VALUE_FLAGS = new Set([
|
||||
"docIdPrefix", "docIdSuffix", "document-id", "document-sn", "document-sns", "document-type",
|
||||
"documentId", "documentLimit", "documentSn", "documentType", "domain", "enable",
|
||||
"end", "end-date", "end-time", "endDate", "endTime", "env",
|
||||
"environment", "expire", "expiresIn", "fields", "file", "file-id", "file-name", "flow-concurrency",
|
||||
"environment", "expire", "expires-in", "expiresIn", "fields", "file", "file-id", "file-name", "flow-concurrency",
|
||||
"flow-ids", "flow-status-list", "flowIds", "flowStatusList", "format", "from",
|
||||
"from-link", "host", "humanResult", "id", "input", "integration",
|
||||
"json", "json-path", "key-id", "keyId", "keyword", "level", "limit",
|
||||
@@ -98,7 +98,7 @@ export const KNOWN_FLAGS = new Set([
|
||||
"documentId", "documentLimit", "documentSn", "documentType", "domain", "download",
|
||||
"downloads", "dry-run", "dryRun", "elevate-hose", "enable", "enabled",
|
||||
"end", "end-date", "end-time", "endDate", "endTime", "env",
|
||||
"environment", "exclude-deleted", "extract", "extract-expenses", "extractExpenses", "expire", "expiresIn", "f", "fail-on-flips",
|
||||
"environment", "exclude-deleted", "extract", "extract-expenses", "extractExpenses", "expire", "expires-in", "expiresIn", "f", "fail-on-flips",
|
||||
"fields", "file", "file-id", "file-name", "flow", "flow-concurrency", "flow-ids", "flow-status-list",
|
||||
"flowIds", "flowStatusList", "force", "format", "from", "from-link",
|
||||
"full", "h", "has-input", "has-output", "help", "hose", "hose-sso", "hoseSso",
|
||||
@@ -436,3 +436,91 @@ export function materialPackFilePolicyOptions(
|
||||
allowedExtensions
|
||||
};
|
||||
}
|
||||
|
||||
export function parseDelegationExpireHours(value: string | boolean | number | undefined, defaultHours = 24): number {
|
||||
if (value === undefined || value === null || value === "") {
|
||||
return defaultHours;
|
||||
}
|
||||
let hours: number;
|
||||
if (typeof value === "number") {
|
||||
if (!Number.isFinite(value) || value <= 0) {
|
||||
throw usageError(`Invalid --expire: ${value}. Must be a positive duration (e.g. '7d', '24h', or 1..168).`);
|
||||
}
|
||||
if (value > 168 && value % 3600 === 0 && value / 3600 <= 168) {
|
||||
hours = Math.round(value / 3600);
|
||||
} else {
|
||||
hours = Math.round(value);
|
||||
}
|
||||
} else if (typeof value === "string") {
|
||||
const trimmed = value.trim();
|
||||
const match = trimmed.match(/^(\d+(?:\.\d+)?)\s*(d|day|days|h|hr|hrs|hour|hours|m|min|mins|minute|minutes|s|sec|secs|second|seconds)?$/i);
|
||||
if (!match || !match[1]) {
|
||||
throw usageError(`Invalid --expire: '${value}'. Must be a valid duration (e.g. '7d', '24h', or 1..168).`);
|
||||
}
|
||||
const val = parseFloat(match[1]);
|
||||
const unit = (match[2] ?? "").toLowerCase();
|
||||
if (!unit) {
|
||||
if (val > 168 && val % 3600 === 0 && val / 3600 <= 168) {
|
||||
hours = Math.round(val / 3600);
|
||||
} else {
|
||||
hours = Math.round(val);
|
||||
}
|
||||
} else if (unit.startsWith("d")) {
|
||||
hours = Math.round(val * 24);
|
||||
} else if (unit.startsWith("h")) {
|
||||
hours = Math.round(val);
|
||||
} else if (unit.startsWith("m")) {
|
||||
hours = Math.round(val / 60);
|
||||
} else if (unit.startsWith("s")) {
|
||||
hours = Math.round(val / 3600);
|
||||
} else {
|
||||
hours = Math.round(val);
|
||||
}
|
||||
} else {
|
||||
throw usageError(`Invalid --expire: ${String(value)}.`);
|
||||
}
|
||||
|
||||
if (hours < 1 || hours > 168) {
|
||||
throw usageError(`Invalid --expire: computed ${hours} hours. Seal delegation 有效期必须在 1 到 168 小时(最大 7 天)之间。例如:--expire 7d 或 --expire 24h。`);
|
||||
}
|
||||
return hours;
|
||||
}
|
||||
|
||||
export function parseHoseExpireSeconds(value: string | boolean | number | undefined, defaultSeconds = 7200): number {
|
||||
if (value === undefined || value === null || value === "") {
|
||||
return defaultSeconds;
|
||||
}
|
||||
let seconds: number;
|
||||
if (typeof value === "number") {
|
||||
if (!Number.isFinite(value) || value <= 0) {
|
||||
throw usageError(`Invalid --expire: ${value}. Must be a positive duration.`);
|
||||
}
|
||||
seconds = Math.round(value);
|
||||
} else if (typeof value === "string") {
|
||||
const trimmed = value.trim();
|
||||
const match = trimmed.match(/^(\d+(?:\.\d+)?)\s*(d|day|days|h|hr|hrs|hour|hours|m|min|mins|minute|minutes|s|sec|secs|second|seconds)?$/i);
|
||||
if (!match || !match[1]) {
|
||||
throw usageError(`Invalid --expire: '${value}'. Must be a valid duration (e.g. '7d', '2h', '7200').`);
|
||||
}
|
||||
const val = parseFloat(match[1]);
|
||||
const unit = (match[2] ?? "").toLowerCase();
|
||||
if (!unit || unit.startsWith("s")) {
|
||||
seconds = Math.round(val);
|
||||
} else if (unit.startsWith("d")) {
|
||||
seconds = Math.round(val * 86400);
|
||||
} else if (unit.startsWith("h")) {
|
||||
seconds = Math.round(val * 3600);
|
||||
} else if (unit.startsWith("m")) {
|
||||
seconds = Math.round(val * 60);
|
||||
} else {
|
||||
seconds = Math.round(val);
|
||||
}
|
||||
} else {
|
||||
throw usageError(`Invalid --expire: ${String(value)}.`);
|
||||
}
|
||||
|
||||
if (seconds <= 0) {
|
||||
throw usageError(`Invalid --expire: computed ${seconds} seconds. Must be a positive number of seconds.`);
|
||||
}
|
||||
return seconds;
|
||||
}
|
||||
Reference in new issue
Block a user