Skip to content

Commit

Permalink
Enhance registerExistingSG feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jihoon-seo committed Jan 25, 2022
1 parent 6c872c6 commit 3a94dda
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/core/mcir/securitygroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type SpiderSecurityInfo struct { // Spider
// Fields for request
Name string
VPCName string
CSPId string

// Fields for both request and response
SecurityRules *[]SpiderSecurityRuleInfo
Expand All @@ -64,6 +65,9 @@ type TbSecurityGroupReq struct { // Tumblebug
VNetId string `json:"vNetId" validate:"required"`
Description string `json:"description"`
FirewallRules *[]SpiderSecurityRuleInfo `json:"firewallRules"` // validate:"required"`

// CspSecurityGroupId is required to register object from CSP (option=register)
CspSecurityGroupId string `json:"cspSecurityGroupId"`
}

// TbSecurityGroupReqStructLevelValidation is a function to validate 'TbSecurityGroupReq' object.
Expand Down Expand Up @@ -178,6 +182,7 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS
tempReq.ReqInfo.Name = u.Name
tempReq.ReqInfo.VPCName = vNetInfo.CspVNetName
tempReq.ReqInfo.SecurityRules = u.FirewallRules
tempReq.ReqInfo.CSPId = u.CspSecurityGroupId

var tempSpiderSecurityInfo *SpiderSecurityInfo

Expand All @@ -196,10 +201,13 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS
var err error

var url string
if option == "register" {
if option == "register" && u.CspSecurityGroupId == "" {
url = fmt.Sprintf("%s/securitygroup/%s", common.SpiderRestUrl, u.Name)
resp, err = req.Get(url)
} else {
} else if option == "register" && u.CspSecurityGroupId != "" {
url = fmt.Sprintf("%s/regsecuritygroup", common.SpiderRestUrl)
resp, err = req.Post(url)
} else { // option != "register"
url = fmt.Sprintf("%s/securitygroup", common.SpiderRestUrl)
resp, err = req.Post(url)
}
Expand Down Expand Up @@ -275,7 +283,9 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS
content.KeyValueList = tempSpiderSecurityInfo.KeyValueList
content.AssociatedObjectList = []string{}

if option == "register" {
if option == "register" && u.CspSecurityGroupId == "" {
content.SystemLabel = "Registered from CB-Spider resource"
} else if option == "register" && u.CspSecurityGroupId != "" {
content.SystemLabel = "Registered from CSP resource"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

function CallTB() {
echo "- Register securityGroup in ${MCIRRegionName}"

resp=$(
curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/resources/securityGroup?option=register -H 'Content-Type: application/json' -d @- <<EOF
{
"name": "${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX}",
"connectionName": "${CONN_CONFIG[$INDEX,$REGION]}",
"vNetId": "${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX}",
"cspSecurityGroupId": "sg-06b67660aa959e005"
}
EOF
); echo ${resp} | jq ''
echo ""
}

#function register_securityGroup() {

echo "####################################################################"
echo "## 4. SecurityGroup: Register"
echo "####################################################################"

source ../init.sh

if [ "${INDEX}" == "0" ]; then
echo "[Parallel execution for all CSP regions]"
INDEXX=${NumCSP}
for ((cspi = 1; cspi <= INDEXX; cspi++)); do
INDEXY=${NumRegion[$cspi]}
CSP=${CSPType[$cspi]}
echo "[$cspi] $CSP details"
for ((cspj = 1; cspj <= INDEXY; cspj++)); do
echo "[$cspi,$cspj] ${RegionName[$cspi,$cspj]}"

MCIRRegionName=${RegionName[$cspi,$cspj]}

CallTB

done

done
wait

else
echo ""

MCIRRegionName=${CONN_CONFIG[$INDEX,$REGION]}

CallTB

fi

#}

#register_securityGroup

0 comments on commit 3a94dda

Please sign in to comment.