Skip to content
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

Add support for NSG references #224

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ require (

require (
github.com/Microsoft/go-winio v0.6.1
github.com/golang/protobuf v1.5.3
github.com/golang/protobuf v1.5.4
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
google.golang.org/protobuf v1.32.0
google.golang.org/protobuf v1.33.0
)

replace (
github.com/Azure/go-autorest v11.1.2+incompatible => github.com/Azure/go-autorest/autorest v0.10.0
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.1.0
github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
github.com/microsoft/moc => github.com/microsoft/moc v0.16.3-0.20240322055251-824710ef5544
github.com/miekg/dns => github.com/miekg/dns v1.1.25
github.com/nats-io/nkeys => github.com/nats-io/nkeys v0.4.6
golang.org/x/net => golang.org/x/net v0.0.0-20220822230855-b0a4917ee28c
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1322,8 +1322,9 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
Expand Down Expand Up @@ -1506,8 +1507,8 @@ github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/microsoft/moc v0.15.1 h1:Xb5G6BQZmytj6uKR9g1EA/iC3ijYi04cEDNR9FNSVd0=
github.com/microsoft/moc v0.15.1/go.mod h1:9QyScbyUC39Wknj5qRXWT+ny05uXCk7R+cAbRYevkK4=
github.com/microsoft/moc v0.16.3-0.20240322055251-824710ef5544 h1:kRxa0/O9UU3R31tdVEHtFdutFojAsoZ9qJ2DaSaGC6A=
github.com/microsoft/moc v0.16.3-0.20240322055251-824710ef5544/go.mod h1:Xq5OoPMwNdJDmXbFNTwZuu3u0ehx2P00ChgWGFpAtbQ=
github.com/miekg/dns v1.1.25/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY=
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
Expand Down Expand Up @@ -2210,8 +2211,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a/go.
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405/go.mod h1:67X1fPuzjcrkymZzZV1vvkFeTn2Rvc6lYF9MYFGCcwE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8 h1:IR+hp6ypxjH24bkMfEJ0yHR21+gwPWdV+/IBrPQyn3k=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8/go.mod h1:UCOku4NytXMJuLQE5VuqA5lX3PcHCBo8pxNyvkf4xBs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
Expand Down Expand Up @@ -2280,8 +2281,8 @@ google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
21 changes: 20 additions & 1 deletion services/network/logicalnetwork/logicalnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ func getWssdNetworkSubnets(subnets *[]network.LogicalSubnet) (wssdsubnets []*wss
wssdsubnet.IsPublic = *subnet.Public
}

if subnet.NetworkSecurityGroup != nil {
wssdsubnet.NetworkSecurityGroup = &wssdcommonproto.NsgGroup{
NsgName: *subnet.NetworkSecurityGroup.ID,
GroupName: *subnet.NetworkSecurityGroup.Group,
}
}

wssdsubnets = append(wssdsubnets, wssdsubnet)
}

Expand Down Expand Up @@ -210,7 +217,8 @@ func getNetworkSubnets(wssdsubnets []*wssdcloudnetwork.LogicalSubnet) *[]network
DhcpOptions: &network.DhcpOptions{
DNSServers: &dnsservers,
},
Public: &subnet.IsPublic,
NetworkSecurityGroup: getNetworkSecurityGroup(subnet.NetworkSecurityGroup),
Public: &subnet.IsPublic,
},
})
}
Expand Down Expand Up @@ -269,3 +277,14 @@ func getVlan(wssdvlan uint32) *uint16 {
vlan := uint16(wssdvlan)
return &vlan
}

func getNetworkSecurityGroup(wssdNsg *wssdcommonproto.NsgGroup) *network.GroupSubResource {
if wssdNsg == nil || wssdNsg.NsgName == "" {
return nil
}

return &network.GroupSubResource{
ID: &wssdNsg.NsgName,
Group: &wssdNsg.GroupName,
}
}
18 changes: 15 additions & 3 deletions services/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ type SubResource struct {
ID *string `json:"id,omitempty"`
}

// GroupSubResource referes to another subresource, and the group that subresource belongs to
type GroupSubResource struct {
// ID - Resource ID.
ID *string `json:"id,omitempty"`
// Group name
Group *string `json:"group,omitempty"`
}

// APIEntityReference the API entity reference.
type APIEntityReference struct {
// ID - The ARM resource id in the form of /subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/...
Expand Down Expand Up @@ -829,10 +837,12 @@ type SecurityGroupPropertiesFormat struct {
SecurityRules *[]SecurityRule `json:"securityRules,omitempty"`
// DefaultSecurityRules - The default security rules of network security group.
DefaultSecurityRules *[]SecurityRule `json:"defaultSecurityRules,omitempty"`
// NetworkInterfaces - READ-ONLY; A collection of references to network interfaces.
NetworkInterfaces *[]Interface `json:"networkInterfaces,omitempty"`
// Subnets - READ-ONLY; A collection of references to subnets.
// NetworkInterfaces - READ-ONLY; A collection of references to network interface configurations.
IpConfigurations *[]InterfaceIPConfiguration `json:"ipConfigs,omitempty"`
// Subnets - READ-ONLY; A collection of references to virtual subnets.
Subnets *[]Subnet `json:"subnets,omitempty"`
// LogicalSubnets - READ-ONLY; A collection of references to logical subnets.
LogicalSubnets *[]LogicalSubnet `json:"logicalSubnets,omitempty"`
// ResourceGUID - The resource GUID property of the network security group resource.
ResourceGUID *string `json:"resourceGuid,omitempty"`
// ProvisioningState - The provisioning state of the network security group resource. Possible values are: 'Updating', 'Deleting', and 'Failed'.
Expand Down Expand Up @@ -1061,6 +1071,8 @@ type LogicalSubnetPropertiesFormat struct {
DhcpOptions *DhcpOptions `json:"dhcpOptions,omitempty"`
// Public - Gets whether this is a public subnet on a virtual machine.
Public *bool `json:"primary,omitempty"`
// NetworkSecurityGroup - The reference of the NetworkSecurityGroup resource.
NetworkSecurityGroup *GroupSubResource `json:"networkSecurityGroup,omitempty"`
}

// LogicalSubnet is a subnet in a Logical network resource.
Expand Down
64 changes: 64 additions & 0 deletions services/network/networksecuritygroup/wssd.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ func getWssdNetworkSecurityGroup(networkNSG *network.SecurityGroup, group string
wssdCloudNSG.Networksecuritygrouprules = append(nsgRules, defaultNsgRules...)
}

if networkNSG.Subnets != nil {
subnets := []string{}
for _, subnet := range *networkNSG.Subnets {
subnets = append(subnets, *subnet.Name)
}
wssdCloudNSG.VnetRefs = subnets
}

if networkNSG.LogicalSubnets != nil {
subnets := []string{}
for _, subnet := range *networkNSG.LogicalSubnets {
subnets = append(subnets, *subnet.Name)
}
wssdCloudNSG.LnetRefs = subnets
}

if networkNSG.IpConfigurations != nil {
ipConfigs := []string{}
for _, ipConfig := range *networkNSG.IpConfigurations {
ipConfigs = append(ipConfigs, *ipConfig.Name)
}
wssdCloudNSG.IpRefs = ipConfigs
}

return wssdCloudNSG, nil
}

Expand Down Expand Up @@ -317,6 +341,10 @@ func getNetworkSecurityGroup(wssdNSG *wssdcloudnetwork.NetworkSecurityGroup) (ne
},
}

if wssdNSG.Tags != nil {
networkNSG.Tags = tags.ProtoToMap(wssdNSG.Tags)
}

if len(wssdNSG.Networksecuritygrouprules) > 0 {
networkNSGRules := []network.SecurityRule{}
networkDefaultNSGRules := []network.SecurityRule{}
Expand Down Expand Up @@ -382,5 +410,41 @@ func getNetworkSecurityGroup(wssdNSG *wssdcloudnetwork.NetworkSecurityGroup) (ne
networkNSG.SecurityGroupPropertiesFormat.DefaultSecurityRules = &networkDefaultNSGRules
}

if len(wssdNSG.VnetRefs) > 0 {
subnets := []network.Subnet{}

for _, ref := range wssdNSG.VnetRefs {
subnets = append(subnets, network.Subnet{
Name: &ref,
})
}

networkNSG.Subnets = &subnets
}

if len(wssdNSG.LnetRefs) > 0 {
subnets := []network.LogicalSubnet{}

for _, ref := range wssdNSG.LnetRefs {
subnets = append(subnets, network.LogicalSubnet{
Name: &ref,
})
}

networkNSG.LogicalSubnets = &subnets
}

if len(wssdNSG.IpRefs) > 0 {
ipConfigs := []network.InterfaceIPConfiguration{}

for _, ref := range wssdNSG.IpRefs {
ipConfigs = append(ipConfigs, network.InterfaceIPConfiguration{
Name: &ref,
})
}

networkNSG.IpConfigurations = &ipConfigs
}

return networkNSG, nil
}
Loading