Skip to content

Commit

Permalink
API refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Feb 6, 2024
1 parent 1d75046 commit 641a2a6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 43 deletions.
6 changes: 3 additions & 3 deletions cmd/metal-api/internal/service/machine-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,10 +1039,10 @@ func createMachineAllocationSpec(ds *datastore.RethinkStore, machineRequest v1.M
role = metal.RoleMachine
)

if firewallRequest != nil {
if firewallRequest != nil && firewallRequest.FirewallRules != nil {
role = metal.RoleFirewall

for _, ruleSpec := range firewallRequest.Egress {
for _, ruleSpec := range firewallRequest.FirewallRules.Egress {
ruleSpec := ruleSpec

protocol, err := metal.ProtocolFromString(ruleSpec.Protocol)
Expand All @@ -1064,7 +1064,7 @@ func createMachineAllocationSpec(ds *datastore.RethinkStore, machineRequest v1.M
egress = append(egress, rule)
}

for _, ruleSpec := range firewallRequest.Ingress {
for _, ruleSpec := range firewallRequest.FirewallRules.Ingress {
ruleSpec := ruleSpec

protocol, err := metal.ProtocolFromString(ruleSpec.Protocol)
Expand Down
3 changes: 1 addition & 2 deletions cmd/metal-api/internal/service/v1/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ type FirewallCreateRequest struct {
}

type FirewallAllocateRequest struct {
Egress []FirewallEgressRule `json:"egress,omitempty" description:"list of egress rules to be deployed during firewall allocation" optional:"true"`
Ingress []FirewallIngressRule `json:"ingress,omitempty" description:"list of ingress rules to be deployed during firewall allocation" optional:"true"`
FirewallRules *FirewallRules `json:"firewall_rules" description:"optional egress and ingress firewall rules to deploy during firewall allocation" optional:"true"`
}

type FirewallEgressRule struct {
Expand Down
12 changes: 6 additions & 6 deletions cmd/metal-api/internal/service/v1/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type MachineAllocation struct {
}

type FirewallRules struct {
Egress []*FirewallEgressRule `json:"egress"`
Ingress []*FirewallIngressRule `json:"ingress"`
Egress []FirewallEgressRule `json:"egress,omitempty" description:"list of egress rules to be deployed during firewall allocation" optional:"true"`
Ingress []FirewallIngressRule `json:"ingress,omitempty" description:"list of ingress rules to be deployed during firewall allocation" optional:"true"`
}

type BootInfo struct {
Expand Down Expand Up @@ -521,13 +521,13 @@ func NewMachineResponse(m *metal.Machine, s *metal.Size, p *metal.Partition, i *
var firewallRules *FirewallRules
if m.Allocation.Role == metal.RoleFirewall {
var (
egressRules []*FirewallEgressRule
ingressRules []*FirewallIngressRule
egressRules []FirewallEgressRule
ingressRules []FirewallIngressRule
)

for _, r := range m.Allocation.Egress {
r := r
egressRules = append(egressRules, &FirewallEgressRule{
egressRules = append(egressRules, FirewallEgressRule{
Protocol: string(r.Protocol),
Ports: r.Ports,
ToCIDRs: r.ToCIDRs,
Expand All @@ -536,7 +536,7 @@ func NewMachineResponse(m *metal.Machine, s *metal.Size, p *metal.Partition, i *
}
for _, r := range m.Allocation.Ingress {
r := r
egressRules = append(egressRules, &FirewallEgressRule{
egressRules = append(egressRules, FirewallEgressRule{
Protocol: string(r.Protocol),
Ports: r.Ports,
ToCIDRs: r.FromCIDRs,
Expand Down
42 changes: 10 additions & 32 deletions spec/metal-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1017,19 +1017,9 @@
},
"v1.FirewallAllocateRequest": {
"properties": {
"egress": {
"description": "list of egress rules to be deployed during firewall allocation",
"items": {
"$ref": "#/definitions/v1.FirewallEgressRule"
},
"type": "array"
},
"ingress": {
"description": "list of ingress rules to be deployed during firewall allocation",
"items": {
"$ref": "#/definitions/v1.FirewallIngressRule"
},
"type": "array"
"firewall_rules": {
"$ref": "#/definitions/v1.FirewallRules",
"description": "optional egress and ingress firewall rules to deploy during firewall allocation"
}
}
},
Expand All @@ -1039,17 +1029,14 @@
"description": "a description for this entity",
"type": "string"
},
"egress": {
"description": "list of egress rules to be deployed during firewall allocation",
"items": {
"$ref": "#/definitions/v1.FirewallEgressRule"
},
"type": "array"
},
"filesystemlayoutid": {
"description": "the filesystemlayout id to assing to this machine",
"type": "string"
},
"firewall_rules": {
"$ref": "#/definitions/v1.FirewallRules",
"description": "optional egress and ingress firewall rules to deploy during firewall allocation"
},
"hostname": {
"description": "the hostname for the allocated machine (defaults to metal)",
"type": "string"
Expand All @@ -1058,13 +1045,6 @@
"description": "the image id to assign this machine to",
"type": "string"
},
"ingress": {
"description": "list of ingress rules to be deployed during firewall allocation",
"items": {
"$ref": "#/definitions/v1.FirewallIngressRule"
},
"type": "array"
},
"ips": {
"description": "the ips to attach to this machine additionally",
"items": {
Expand Down Expand Up @@ -1477,22 +1457,20 @@
"v1.FirewallRules": {
"properties": {
"egress": {
"description": "list of egress rules to be deployed during firewall allocation",
"items": {
"$ref": "#/definitions/v1.FirewallEgressRule"
},
"type": "array"
},
"ingress": {
"description": "list of ingress rules to be deployed during firewall allocation",
"items": {
"$ref": "#/definitions/v1.FirewallIngressRule"
},
"type": "array"
}
},
"required": [
"egress",
"ingress"
]
}
},
"v1.FirmwaresResponse": {
"properties": {
Expand Down

0 comments on commit 641a2a6

Please sign in to comment.