-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When restoring a backup, you may need to "bump" the counter of namespaces to avoid conflicts with ASNs registered after the backup was made. This commit adds a new CLI command to bump the counter of a namespace. You can specify the namespace to bump or bump all namespaces. Use the `stats` command to get a sense of how much you need to bump.
- Loading branch information
Showing
5 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import z from "@collinhacks/zod"; | ||
import { | ||
allManagedNamespaces, | ||
CONFIG, | ||
generateASN, | ||
isManagedNamespace, | ||
} from "$common/mod.ts"; | ||
|
||
const bumpArgs = z.object({ | ||
namespace: z.number({ coerce: true }).optional(), | ||
_: z.tuple([z.literal("bump"), z.number({ coerce: true }).min(1).int()]), | ||
}); | ||
|
||
/** | ||
* Prints statistics about the ASNs. | ||
* @param args the arguments to the command | ||
* @param args.count the number of ASNs to generate (default: 1) | ||
*/ | ||
export async function runBump(args: unknown) { | ||
const parsedParams = bumpArgs.parse(args); | ||
|
||
if (parsedParams.namespace && !isManagedNamespace(parsedParams.namespace)) { | ||
console.error( | ||
`Namespace ${parsedParams.namespace} (${CONFIG.ASN_PREFIX}${parsedParams.namespace}XXX) is not managed by the system.`, | ||
); | ||
console.error("It therefore cannot be bumped."); | ||
console.error( | ||
"Managed namespace numbers are:", | ||
allManagedNamespaces().join(", "), | ||
); | ||
Deno.exit(1); | ||
} | ||
|
||
const namespaces = parsedParams.namespace | ||
? [parsedParams.namespace] | ||
: allManagedNamespaces(); | ||
|
||
const bumpDelta = parsedParams._[1]; | ||
const bumpedAt = new Date().toISOString(); | ||
|
||
console.log( | ||
"Bumping namespaces:", | ||
namespaces.map((n) => `${CONFIG.ASN_PREFIX}${n}XXX`).join(", "), | ||
); | ||
console.log("---"); | ||
await Promise.all( | ||
namespaces.map((namespace) => | ||
generateASN( | ||
{ | ||
bumpedBy: bumpDelta, | ||
bumpedAt, | ||
}, | ||
namespace, | ||
bumpDelta, | ||
).then((asn) => { | ||
console.log( | ||
"Bumped", | ||
`${CONFIG.ASN_PREFIX}${namespace}XXX. ` + | ||
`Next registered ASN will be ${CONFIG.ASN_PREFIX}${namespace}${ | ||
(asn.counter + 1).toString().padStart(3, "0") | ||
}.`, | ||
); | ||
}) | ||
), | ||
); | ||
console.log("---"); | ||
console.log("Done."); | ||
|
||
await Promise.resolve(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters