Skip to content

Commit

Permalink
Issue 1640: sg from data on fe (#1641)
Browse files Browse the repository at this point in the history
* feat: power vs v2 enhancements

* fix: changelog

* feat: fe functionality

* hide duplicate rules in v2 when selecting imported sg
  • Loading branch information
jvallexm authored and GitHub Enterprise committed Mar 8, 2024
1 parent f914230 commit 9c02912
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
- When bringing your own certificate for VPN Servers, two separate certificates are now imported. Additional variables have been added to support the new imported certificate
- Users can now create, update, and delete Classic Security Groups and their rules from the Classic Security Groups page `/forms/classicSecurityGroups`
- Users can now add IBM i licenses to Power VS instances with IBM i images
- Users can now import existing VPC security groups for existing VPCs

### Fixes

Expand Down
14 changes: 12 additions & 2 deletions client/src/components/forms/duplicate-rules/CopyRuleObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,18 @@ const CopyRuleObject = (props) => {
className: "fieldWidthSmaller",
groups: (props.source ? [""] : []).concat(
props.isSecurityGroup
? splat(props.craig.store.json.security_groups, "name")
: splat(props.data.acls, "name")
? splat(
props.craig.store.json.security_groups.filter((sg) => {
if (!sg.use_data) return sg;
}),
"name"
)
: splat(
props.data.acls.filter((acl) => {
if (!acl.use_data) return acl;
}),
"name"
)
),
disabled: (stateData) => {
return stateData.v2;
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/pages/CraigForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,9 @@ function craigForms(craig) {
security_groups: {
jsonField: "security_groups",
groups: [
{
use_data: craig.security_groups.use_data,
},
{
name: craig.security_groups.name,
resource_group: craig.security_groups.resource_group,
Expand Down
5 changes: 4 additions & 1 deletion client/src/components/pages/vpc/VpcDeployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,10 @@ class VpcDeploymentsDiagramPage extends React.Component {
vpc_name: this.vpcName(),
}}
/>
{this.state.selectedItem === "security_groups" ? (
{this.state.selectedItem === "security_groups" &&
!craig.store.json[this.state.selectedItem][
this.state.selectedIndex
].use_data ? (
<CopyRuleForm
craig={this.props.craig}
sourceSg={this.getServiceData().name}
Expand Down
3 changes: 2 additions & 1 deletion client/src/lib/docs/release-notes.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"VPC Virtual Server primary IPs and floating IPs are exported as outputs",
"When bringing your own certificate for VPN Servers, two separate certificates are now imported. Additional variables have been added to support the new imported certificate",
"Users can now create, update, and delete Classic Security Groups and their rules from the Classic Security Groups page `/forms/classicSecurityGroups`",
"Users can now add IBM i licenses to Power VS instances with IBM i images"
"Users can now add IBM i licenses to Power VS instances with IBM i images",
"Users can now import existing VPC security groups for existing VPCs"
],
"fixes": [
"Fixed an issue causing certificates imported into an existing Secrets Manager instance to have incorrect references within Terraform",
Expand Down
19 changes: 19 additions & 0 deletions client/src/lib/state/security-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
getObjectFromArray,
contains,
isIpv4CidrOrAddress,
isNullOrEmptyString,
} = require("lazy-z");
const { lazyZstate } = require("lazy-z/lib/store");
const { newDefaultVpeSecurityGroups } = require("./defaults");
Expand Down Expand Up @@ -61,6 +62,7 @@ function securityGroupOnStoreUpdate(config) {
setUnfoundResourceGroup(config, sg);
if (!splatContains(config.store.json.vpcs, "name", sg.vpc)) {
sg.vpc = null;
sg.use_data = false;
sg.rules.forEach((rule) => {
rule.vpc = null;
rule.sg = sg.name;
Expand Down Expand Up @@ -256,6 +258,20 @@ function initSecurityGroupStore(store) {
"security_groups"
),
schema: {
use_data: {
type: "toggle",
default: false,
labelText: "Use Existing Security Group",
hideWhen: function (stateData, componentProps) {
return (
getObjectFromArray(
componentProps.craig.store.json.vpcs,
"name",
stateData.vpc || "" // modal
)?.use_data !== true
);
},
},
name: nameField("security_groups", { size: "small" }),
resource_group: resourceGroupsField(true),
vpc: {
Expand All @@ -266,6 +282,9 @@ function initSecurityGroupStore(store) {
invalidText: selectInvalidText("vpc"),
size: "small",
groups: vpcGroups,
disabled: function (stateData) {
return stateData.use_data && !isNullOrEmptyString(stateData.vpc);
},
},
},
subComponents: {
Expand Down
40 changes: 40 additions & 0 deletions unit-tests/state/security-groups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,46 @@ describe("security groups", () => {
);
});
});
describe("security_groups.schema", () => {
let craig;
beforeEach(() => {
craig = newState();
});
it("should hide use_data", () => {
assert.isTrue(
craig.security_groups.use_data.hideWhen({}, { craig: craig }),
"it should hide when in modal"
);
assert.isTrue(
craig.security_groups.use_data.hideWhen(
{ vpc: "management" },
{ craig: craig }
),
"it should hide when vpc does not use data"
);
craig.store.json.vpcs.push({
name: "data",
use_data: true,
});
assert.isFalse(
craig.security_groups.use_data.hideWhen(
{ vpc: "data" },
{ craig: craig }
),
"it should be shown"
);
});
it("should disable vpc when using data for security group", () => {
assert.isFalse(
craig.security_groups.vpc.disabled({ use_data: true, vpc: "" }),
"it should not be disabled"
);
assert.isTrue(
craig.security_groups.vpc.disabled({ use_data: true, vpc: "frog" }),
"it should be disabled"
);
});
});
describe("security_group.rules", () => {
describe("security_groups.rules.create", () => {
it("should add a new rule", () => {
Expand Down

0 comments on commit 9c02912

Please sign in to comment.