Skip to content

Commit b84c135

Browse files
authored
Fix bug in the set policy command where --none flag no longer works. (#8330)
* Fix bug in the set policy command where --none flag no longer works. * Add changelog. * Fix changelog.
1 parent dcd24da commit b84c135

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix bug where functions:artifacts:setpolicy command's --none option didn't work as expected (#8330)

src/commands/functions-artifacts-setpolicy.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,12 @@ export const command = new Command("functions:artifacts:setpolicy")
2626
)
2727
.option(
2828
"--days <days>",
29-
"Number of days to keep container images before deletion. Default is 3 days.",
30-
"3",
29+
`Number of days to keep container images before deletion. Default is ${artifacts.DEFAULT_CLEANUP_DAYS} day.`,
3130
)
3231
.option(
3332
"--none",
3433
"Opt-out from cleanup policy. This will prevent suggestions to set up a cleanup policy during initialization and deployment.",
3534
)
36-
.before((options) => {
37-
if (options.days && options.none) {
38-
throw new FirebaseError("Cannot specify both --days and --none options.");
39-
}
40-
})
4135
.withForce("Automatically create or modify cleanup policy")
4236
.before(requireAuth)
4337
.before(async (options) => {
@@ -49,9 +43,12 @@ export const command = new Command("functions:artifacts:setpolicy")
4943
"artifactregistry.versions.delete",
5044
])
5145
.action(async (options: any) => {
46+
if (options.days && options.none) {
47+
throw new FirebaseError("Cannot specify both --days and --none options.");
48+
}
5249
const projectId = needProjectId(options);
5350
const location = options.location || "us-central1";
54-
let daysToKeep = parseInt(options.days || "3", 10);
51+
let daysToKeep = parseInt(options.days || artifacts.DEFAULT_CLEANUP_DAYS, 10);
5552

5653
const repoPath = artifacts.makeRepoPath(projectId, location);
5754
let repository: artifactregistry.Repository;

src/functions/artifacts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export const CLEANUP_POLICY_ID = "firebase-functions-cleanup";
1717
*/
1818
export const OPT_OUT_LABEL_KEY = "firebase-functions-cleanup-opted-out";
1919

20+
/**
21+
* Default number of days to keep container images for cleanup policies
22+
*/
23+
export const DEFAULT_CLEANUP_DAYS = 1;
24+
2025
const SECONDS_IN_DAY = 24 * 60 * 60;
2126

2227
/**

0 commit comments

Comments
 (0)