Skip to content

Commit

Permalink
Provide connection info to all resource types
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-son committed Oct 23, 2024
1 parent e5bfd8c commit ad26346
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 13 deletions.
21 changes: 21 additions & 0 deletions src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12271,6 +12271,9 @@ const docTemplate = `{
"/ns/default/mci/mci01/vm/aws-ap-southeast-1-1"
]
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string",
"example": "aws-ap-southeast-1"
Expand Down Expand Up @@ -12384,6 +12387,9 @@ const docTemplate = `{
"/ns/default/mci/mci01/vm/aws-ap-southeast-1-1"
]
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string",
"example": "aws-ap-southeast-1"
Expand Down Expand Up @@ -13117,6 +13123,9 @@ const docTemplate = `{
"type": "string"
}
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string"
},
Expand Down Expand Up @@ -13405,6 +13414,9 @@ const docTemplate = `{
"type": "string"
}
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string"
},
Expand Down Expand Up @@ -13683,6 +13695,9 @@ const docTemplate = `{
"type": "string"
}
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string"
},
Expand Down Expand Up @@ -13795,6 +13810,9 @@ const docTemplate = `{
"$ref": "#/definitions/model.BastionNode"
}
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string"
},
Expand Down Expand Up @@ -13897,6 +13915,9 @@ const docTemplate = `{
"cidrBlock": {
"type": "string"
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string"
},
Expand Down
21 changes: 21 additions & 0 deletions src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -12264,6 +12264,9 @@
"/ns/default/mci/mci01/vm/aws-ap-southeast-1-1"
]
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string",
"example": "aws-ap-southeast-1"
Expand Down Expand Up @@ -12377,6 +12380,9 @@
"/ns/default/mci/mci01/vm/aws-ap-southeast-1-1"
]
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string",
"example": "aws-ap-southeast-1"
Expand Down Expand Up @@ -13110,6 +13116,9 @@
"type": "string"
}
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string"
},
Expand Down Expand Up @@ -13398,6 +13407,9 @@
"type": "string"
}
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string"
},
Expand Down Expand Up @@ -13676,6 +13688,9 @@
"type": "string"
}
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string"
},
Expand Down Expand Up @@ -13788,6 +13803,9 @@
"$ref": "#/definitions/model.BastionNode"
}
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string"
},
Expand Down Expand Up @@ -13890,6 +13908,9 @@
"cidrBlock": {
"type": "string"
},
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"connectionName": {
"type": "string"
},
Expand Down
14 changes: 14 additions & 0 deletions src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9129,6 +9129,8 @@ components:
- /ns/default/mci/mci01/vm/aws-ap-southeast-1-1
items:
type: string
connectionConfig:
$ref: '#/components/schemas/model.ConnConfig'
connectionName:
type: string
example: aws-ap-southeast-1
Expand Down Expand Up @@ -9213,6 +9215,8 @@ components:
- /ns/default/mci/mci01/vm/aws-ap-southeast-1-1
items:
type: string
connectionConfig:
$ref: '#/components/schemas/model.ConnConfig'
connectionName:
type: string
example: aws-ap-southeast-1
Expand Down Expand Up @@ -9777,6 +9781,8 @@ components:
type: array
items:
type: string
connectionConfig:
$ref: '#/components/schemas/model.ConnConfig'
connectionName:
type: string
createdTime:
Expand Down Expand Up @@ -9985,6 +9991,8 @@ components:
type: array
items:
type: string
connectionConfig:
$ref: '#/components/schemas/model.ConnConfig'
connectionName:
type: string
cspResourceId:
Expand Down Expand Up @@ -10186,6 +10194,8 @@ components:
type: array
items:
type: string
connectionConfig:
$ref: '#/components/schemas/model.ConnConfig'
connectionName:
type: string
cspResourceId:
Expand Down Expand Up @@ -10270,6 +10280,8 @@ components:
type: array
items:
$ref: '#/components/schemas/model.BastionNode'
connectionConfig:
$ref: '#/components/schemas/model.ConnConfig'
connectionName:
type: string
cspResourceId:
Expand Down Expand Up @@ -10345,6 +10357,8 @@ components:
type: string
cidrBlock:
type: string
connectionConfig:
$ref: '#/components/schemas/model.ConnConfig'
connectionName:
type: string
cspResourceId:
Expand Down
8 changes: 5 additions & 3 deletions src/core/model/customimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ type TbCustomImageInfo struct {
CspResourceId string `json:"cspResourceId,omitempty" example:"csp-06eb41e14121c550a"`

// Name is human-readable string to represent the object
Name string `json:"name" example:"aws-ap-southeast-1"`
Namespace string `json:"namespace,omitempty" example:"default"` // required to save in RDB
ConnectionName string `json:"connectionName" example:"aws-ap-southeast-1"`
Name string `json:"name" example:"aws-ap-southeast-1"`
Namespace string `json:"namespace,omitempty" example:"default"` // required to save in RDB
ConnectionName string `json:"connectionName" example:"aws-ap-southeast-1"`
ConnectionConfig ConnConfig `json:"connectionConfig"`

SourceVmId string `json:"sourceVmId" example:"aws-ap-southeast-1-1"`
Description string `json:"description"`
CreationDate time.Time `json:"creationDate,omitempty" example:"2022-10-18T08:12:48Z"`
Expand Down
6 changes: 4 additions & 2 deletions src/core/model/datadisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ type TbDataDiskInfo struct {
CspResourceId string `json:"cspResourceId,omitempty" example:"csp-06eb41e14121c550a"`

// Name is human-readable string to represent the object
Name string `json:"name" example:"aws-ap-southeast-1"`
ConnectionName string `json:"connectionName,omitempty" example:"aws-ap-southeast-1"`
Name string `json:"name" example:"aws-ap-southeast-1"`
ConnectionName string `json:"connectionName,omitempty" example:"aws-ap-southeast-1"`
ConnectionConfig ConnConfig `json:"connectionConfig"`

DiskType string `json:"diskType" example:"standard"`
DiskSize string `json:"diskSize" example:"77"`
Status DiskStatus `json:"status" example:"Available"` // Available, Unavailable, Attached, ...
Expand Down
3 changes: 2 additions & 1 deletion src/core/model/nlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ type TbNLBInfo struct {
// Name is human-readable string to represent the object
Name string `json:"name" example:"aws-ap-southeast-1"`

ConnectionName string `json:"connectionName"`
ConnectionName string `json:"connectionName"`
ConnectionConfig ConnConfig `json:"connectionConfig"`

Type string // PUBLIC(V) | INTERNAL
Scope string // REGION(V) | GLOBAL
Expand Down
4 changes: 3 additions & 1 deletion src/core/model/securitygroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ type TbSecurityGroupInfo struct {
// Name is human-readable string to represent the object
Name string `json:"name" example:"aws-ap-southeast-1"`

ConnectionName string `json:"connectionName"`
ConnectionName string `json:"connectionName"`
ConnectionConfig ConnConfig `json:"connectionConfig"`

VNetId string `json:"vNetId"`
Description string `json:"description"`
FirewallRules []TbFirewallRuleInfo `json:"firewallRules"`
Expand Down
6 changes: 4 additions & 2 deletions src/core/model/sshkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ type TbSshKeyInfo struct {
// Name is human-readable string to represent the object
Name string `json:"name" example:"aws-ap-southeast-1"`

ConnectionName string `json:"connectionName,omitempty"`
Description string `json:"description,omitempty"`
ConnectionName string `json:"connectionName,omitempty"`
ConnectionConfig ConnConfig `json:"connectionConfig"`

Description string `json:"description,omitempty"`

Fingerprint string `json:"fingerprint,omitempty"`
Username string `json:"username,omitempty"`
Expand Down
6 changes: 4 additions & 2 deletions src/core/model/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ type TbSubnetInfo struct { // Tumblebug
CspResourceId string `json:"cspResourceId,omitempty" example:"csp-06eb41e14121c550a"`

// Name is human-readable string to represent the object
Name string `json:"name" example:"aws-ap-southeast-1"`
ConnectionName string `json:"connectionName"`
Name string `json:"name" example:"aws-ap-southeast-1"`
ConnectionName string `json:"connectionName"`
ConnectionConfig ConnConfig `json:"connectionConfig"`

// CspVNetName is identifier to handle CSP vNet resource
CspVNetName string `json:"cspVNetName,omitempty" example:"we12fawefadf1221edcf"`
// CspVNetId is vNet resource identifier managed by CSP
Expand Down
6 changes: 4 additions & 2 deletions src/core/model/vnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ type TbVNetInfo struct {
CspResourceId string `json:"cspResourceId,omitempty" example:"csp-06eb41e14121c550a"`

// Name is human-readable string to represent the object
Name string `json:"name" example:"aws-ap-southeast-1"`
ConnectionName string `json:"connectionName"`
Name string `json:"name" example:"aws-ap-southeast-1"`
ConnectionName string `json:"connectionName"`
ConnectionConfig ConnConfig `json:"connectionConfig"`

CidrBlock string `json:"cidrBlock"`
SubnetInfoList []TbSubnetInfo `json:"subnetInfoList"`
Description string `json:"description"`
Expand Down
6 changes: 6 additions & 0 deletions src/core/resource/customimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ func RegisterCustomImageWithId(nsId string, u *model.TbCustomImageReq) (model.Tb
IsAutoGenerated: false,
}

content.ConnectionConfig, err = common.GetConnConfig(content.ConnectionName)
if err != nil {
err = fmt.Errorf("Cannot retrieve ConnectionConfig" + err.Error())
log.Error().Err(err).Msg("")
}

if u.CspResourceId == "" {
content.SystemLabel = "Registered from CB-Spider resource"
} else if u.CspResourceId != "" {
Expand Down
5 changes: 5 additions & 0 deletions src/core/resource/datadisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func CreateDataDisk(nsId string, u *model.TbDataDiskReq, option string) (model.T
Description: u.Description,
IsAutoGenerated: false,
}
content.ConnectionConfig, err = common.GetConnConfig(content.ConnectionName)
if err != nil {
err = fmt.Errorf("Cannot retrieve ConnectionConfig" + err.Error())
log.Error().Err(err).Msg("")
}

if option == "register" {
if u.CspResourceId == "" {
Expand Down
5 changes: 5 additions & 0 deletions src/core/resource/securitygroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ func CreateSecurityGroup(nsId string, u *model.TbSecurityGroupReq, option string
content.Description = u.Description
content.KeyValueList = tempSpiderSecurityInfo.KeyValueList
content.AssociatedObjectList = []string{}
content.ConnectionConfig, err = common.GetConnConfig(content.ConnectionName)
if err != nil {
err = fmt.Errorf("Cannot retrieve ConnectionConfig" + err.Error())
log.Error().Err(err).Msg("")
}

// content.FirewallRules = tempSpiderSecurityInfo.SecurityRules
tempTbFirewallRules := []model.TbFirewallRuleInfo{}
Expand Down
5 changes: 5 additions & 0 deletions src/core/resource/sshkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func CreateSshKey(nsId string, u *model.TbSshKeyReq, option string) (model.TbSsh
content.Description = u.Description
content.KeyValueList = tempSpiderKeyPairInfo.KeyValueList
content.AssociatedObjectList = []string{}
content.ConnectionConfig, err = common.GetConnConfig(content.ConnectionName)
if err != nil {
err = fmt.Errorf("Cannot retrieve ConnectionConfig" + err.Error())
log.Error().Err(err).Msg("")
}

if option == "register" {
if u.CspResourceId == "" {
Expand Down
5 changes: 5 additions & 0 deletions src/core/resource/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ func CreateSubnet(nsId string, vNetId string, subnetReq *model.TbSubnetReq) (mod
subnetInfo.Uid = uid
subnetInfo.ResourceType = resourceType
subnetInfo.ConnectionName = vNetInfo.ConnectionName
subnetInfo.ConnectionConfig, err = common.GetConnConfig(subnetInfo.ConnectionName)
if err != nil {
err = fmt.Errorf("Cannot retrieve ConnectionConfig" + err.Error())
log.Error().Err(err).Msg("")
}
subnetInfo.CspVNetId = vNetInfo.CspResourceId
subnetInfo.CspVNetName = vNetInfo.CspResourceName

Expand Down
5 changes: 5 additions & 0 deletions src/core/resource/vnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ func CreateVNet(nsId string, vNetReq *model.TbVNetReq) (model.TbVNetInfo, error)
vNetInfo.Id = vNetReq.Name
vNetInfo.Uid = uid
vNetInfo.ConnectionName = vNetReq.ConnectionName
vNetInfo.ConnectionConfig, err = common.GetConnConfig(vNetInfo.ConnectionName)
if err != nil {
err = fmt.Errorf("Cannot retrieve ConnectionConfig" + err.Error())
log.Error().Err(err).Msg("")
}
vNetInfo.Description = vNetReq.Description
// todo: restore the tag list later
// vNetInfo.TagList = vNetReq.TagList
Expand Down

0 comments on commit ad26346

Please sign in to comment.