-
Notifications
You must be signed in to change notification settings - Fork 23
[STORY-3093] feat(dbng): add firewall rules commands #1171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
10d0d9a to
ea3aaaa
Compare
sc-david-voisin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, however I have few questions/suggestions
dbng/firewall_rules.go
Outdated
| } | ||
|
|
||
| io.Statusf("Firewall rule '%s' has been added to database '%s'.\n", rule.ID, databaseID) | ||
| io.Warning("Firewall rules take time to be applied due to infrastructure provisioning.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe reformulate a bit. A proposition:
"Expect some delay for the firewall rules to be applied, due to infrastructure provisioning."
| return cli.ShowCommandHelp(ctx, c, "database-firewall-rules") | ||
| } | ||
|
|
||
| utils.CheckForConsent(ctx, databaseID, utils.ConsentTypeDBs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: is the consent required here?
| switch c.Args().Len() { | ||
| case 0: | ||
| // No positional arg, database from --database flag | ||
| databaseID, addonID = detect.GetCurrentDatabase(ctx, c) | ||
| case 1: | ||
| // database-id provided as positional arg | ||
| databaseID = c.Args().First() | ||
| addonID, err = detect.GetAddonIDFromDatabase(ctx, databaseID) | ||
| if err != nil { | ||
| errorQuit(ctx, err) | ||
| } | ||
| default: | ||
| io.Error("Too many arguments") | ||
| return cli.ShowCommandHelp(ctx, c, "database-firewall-rules-add") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: this is done 3 times? What do you about about making a small function out it?
| } else { | ||
| params = scalingo.FirewallRuleCreateParams{ | ||
| Type: scalingo.FirewallRuleTypeManagedRange, | ||
| RangeID: managedRange, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: here the label isn't used, is it on purpose? Otherwise, shouldn't we block the flag for manages rules?
|
|
||
| utils.CheckForConsent(ctx, databaseID, utils.ConsentTypeDBs) | ||
|
|
||
| err = dbng.FirewallManagedRangesList(ctx, databaseID, addonID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why do you need the DB ID to list the ranges?
| } | ||
|
|
||
| io.Statusf("Firewall rule '%s' has been added to database '%s'.\n", rule.ID, databaseID) | ||
| io.Warning("Expect some delay for the firewall rules to be applied, due to infrastructure provisioning.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: is this the good wording? We are not really provisioning anything at this point/
| } | ||
|
|
||
| io.Statusf("Firewall rule '%s' has been removed from database '%s'.\n", ruleID, databaseID) | ||
| io.Warning("Expect some delay for the firewall rules to be applied, due to infrastructure provisioning.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: do we want to use applied here?
Summary
Add firewall rules management commands for DBNG databases:
database-firewall-rules- List firewall rulesdatabase-firewall-rules-add- Add custom CIDR or managed range ruledatabase-firewall-rules-remove- Remove a ruledatabase-firewall-managed-ranges- List available managed rangesCommands support both positional arguments and
--databaseflag, matching existing DBNG command patterns (database-info,database-destroy).Usage examples
Changes
GetAddonIDFromDatabasehelper indetect/app.goto resolve addon ID from database IDTest plan
Tested on staging (
osc-st-fr1) with databasetest-firewall-rules-db:Positional argument style:
database-firewall-rules test-firewall-rules-db- List rulesdatabase-firewall-managed-ranges test-firewall-rules-db- List managed rangesdatabase-firewall-rules-add test-firewall-rules-db --cidr 203.0.113.0/24 --label "Test office"- Add custom ruledatabase-firewall-rules-remove test-firewall-rules-db <rule-id>- Remove rule--database flag style:
--database test-firewall-rules-db database-firewall-rules- List rules--database test-firewall-rules-db database-firewall-rules-add --managed-range man-osc-st-fr1-egress- Add managed range--database test-firewall-rules-db database-firewall-rules-remove <rule-id>- Remove rule