diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index 09b4a0047..d37b6ac11 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -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" @@ -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" @@ -13117,6 +13123,9 @@ const docTemplate = `{ "type": "string" } }, + "connectionConfig": { + "$ref": "#/definitions/model.ConnConfig" + }, "connectionName": { "type": "string" }, @@ -13405,6 +13414,9 @@ const docTemplate = `{ "type": "string" } }, + "connectionConfig": { + "$ref": "#/definitions/model.ConnConfig" + }, "connectionName": { "type": "string" }, @@ -13683,6 +13695,9 @@ const docTemplate = `{ "type": "string" } }, + "connectionConfig": { + "$ref": "#/definitions/model.ConnConfig" + }, "connectionName": { "type": "string" }, @@ -13795,6 +13810,9 @@ const docTemplate = `{ "$ref": "#/definitions/model.BastionNode" } }, + "connectionConfig": { + "$ref": "#/definitions/model.ConnConfig" + }, "connectionName": { "type": "string" }, @@ -13897,6 +13915,9 @@ const docTemplate = `{ "cidrBlock": { "type": "string" }, + "connectionConfig": { + "$ref": "#/definitions/model.ConnConfig" + }, "connectionName": { "type": "string" }, diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index c04087071..337f91212 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -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" @@ -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" @@ -13110,6 +13116,9 @@ "type": "string" } }, + "connectionConfig": { + "$ref": "#/definitions/model.ConnConfig" + }, "connectionName": { "type": "string" }, @@ -13398,6 +13407,9 @@ "type": "string" } }, + "connectionConfig": { + "$ref": "#/definitions/model.ConnConfig" + }, "connectionName": { "type": "string" }, @@ -13676,6 +13688,9 @@ "type": "string" } }, + "connectionConfig": { + "$ref": "#/definitions/model.ConnConfig" + }, "connectionName": { "type": "string" }, @@ -13788,6 +13803,9 @@ "$ref": "#/definitions/model.BastionNode" } }, + "connectionConfig": { + "$ref": "#/definitions/model.ConnConfig" + }, "connectionName": { "type": "string" }, @@ -13890,6 +13908,9 @@ "cidrBlock": { "type": "string" }, + "connectionConfig": { + "$ref": "#/definitions/model.ConnConfig" + }, "connectionName": { "type": "string" }, diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index 3a1637781..9e9c6959e 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -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 @@ -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 @@ -9777,6 +9781,8 @@ components: type: array items: type: string + connectionConfig: + $ref: '#/components/schemas/model.ConnConfig' connectionName: type: string createdTime: @@ -9985,6 +9991,8 @@ components: type: array items: type: string + connectionConfig: + $ref: '#/components/schemas/model.ConnConfig' connectionName: type: string cspResourceId: @@ -10186,6 +10194,8 @@ components: type: array items: type: string + connectionConfig: + $ref: '#/components/schemas/model.ConnConfig' connectionName: type: string cspResourceId: @@ -10270,6 +10280,8 @@ components: type: array items: $ref: '#/components/schemas/model.BastionNode' + connectionConfig: + $ref: '#/components/schemas/model.ConnConfig' connectionName: type: string cspResourceId: @@ -10345,6 +10357,8 @@ components: type: string cidrBlock: type: string + connectionConfig: + $ref: '#/components/schemas/model.ConnConfig' connectionName: type: string cspResourceId: diff --git a/src/core/model/customimage.go b/src/core/model/customimage.go index 80eede2d9..f95fa8a58 100644 --- a/src/core/model/customimage.go +++ b/src/core/model/customimage.go @@ -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"` diff --git a/src/core/model/datadisk.go b/src/core/model/datadisk.go index 407e0c691..4dd37379e 100644 --- a/src/core/model/datadisk.go +++ b/src/core/model/datadisk.go @@ -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, ... diff --git a/src/core/model/nlb.go b/src/core/model/nlb.go index 27e58c8ad..528fff306 100644 --- a/src/core/model/nlb.go +++ b/src/core/model/nlb.go @@ -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 diff --git a/src/core/model/securitygroup.go b/src/core/model/securitygroup.go index 8c8e33229..41b7cbd90 100644 --- a/src/core/model/securitygroup.go +++ b/src/core/model/securitygroup.go @@ -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"` diff --git a/src/core/model/sshkey.go b/src/core/model/sshkey.go index 2a7e96fa4..f6ae7969a 100644 --- a/src/core/model/sshkey.go +++ b/src/core/model/sshkey.go @@ -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"` diff --git a/src/core/model/subnet.go b/src/core/model/subnet.go index 78821e424..26987c45e 100644 --- a/src/core/model/subnet.go +++ b/src/core/model/subnet.go @@ -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 diff --git a/src/core/model/vnet.go b/src/core/model/vnet.go index 60b395673..1cd19f927 100644 --- a/src/core/model/vnet.go +++ b/src/core/model/vnet.go @@ -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"` diff --git a/src/core/resource/customimage.go b/src/core/resource/customimage.go index 764234985..c8623c1b1 100644 --- a/src/core/resource/customimage.go +++ b/src/core/resource/customimage.go @@ -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 != "" { diff --git a/src/core/resource/datadisk.go b/src/core/resource/datadisk.go index 917aefdc4..58784ed1b 100644 --- a/src/core/resource/datadisk.go +++ b/src/core/resource/datadisk.go @@ -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 == "" { diff --git a/src/core/resource/securitygroup.go b/src/core/resource/securitygroup.go index c3ee00c13..75ff07d34 100644 --- a/src/core/resource/securitygroup.go +++ b/src/core/resource/securitygroup.go @@ -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{} diff --git a/src/core/resource/sshkey.go b/src/core/resource/sshkey.go index 94110efdb..5c8e83b8d 100644 --- a/src/core/resource/sshkey.go +++ b/src/core/resource/sshkey.go @@ -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 == "" { diff --git a/src/core/resource/subnet.go b/src/core/resource/subnet.go index 2ad803993..d6c73126d 100644 --- a/src/core/resource/subnet.go +++ b/src/core/resource/subnet.go @@ -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 diff --git a/src/core/resource/vnet.go b/src/core/resource/vnet.go index af5b35743..eed7fbacd 100644 --- a/src/core/resource/vnet.go +++ b/src/core/resource/vnet.go @@ -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