数据库安全服务 DBSS-添加RDS数据库(废弃):Go

时间:2025-02-12 14:58:33

Go

 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
package mainimport ("fmt""github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"    dbss "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dbss/v1""github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dbss/v1/model"    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dbss/v1/region")func main() {    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment    ak := os.Getenv("CLOUD_SDK_AK")    sk := os.Getenv("CLOUD_SDK_SK")    auth := basic.NewCredentialsBuilder().        WithAk(ak).        WithSk(sk).        Build()    client := dbss.NewDbssClient(        dbss.DbssClientBuilder().            WithRegion(region.ValueOf("xx-xx")).            WithCredential(auth).            Build())    request := &model.AddRdsNoAgentDatabaseRequest{}enterpriseNameDatabases:= "default"enterpriseNameDatabases1:= "default"var listDatabasesbody = []model.RdsNoAgentDbRequestDatabases{        {            Id: "123751d3ee2f47aea64822e98318c6a8in01",            DbName: "rds1",            Status: "ACTIVE",            Port: "3306",            Ip: "192.168.0.119",            InstanceName: "rds1",            Version: "8.0",            Type: "MySQL",            EnterpriseId: "0",            EnterpriseName: &enterpriseNameDatabases,        },        {            Id: "2343f7285d684fed8b09fac201c3fc7ain01",            DbName: "rds2",            Status: "ACTIVE",            Port: "3306",            Ip: "192.168.0.92",            InstanceName: "rds2",            Version: "8.0",            Type: "MySQL",            EnterpriseId: "0",            EnterpriseName: &enterpriseNameDatabases1,        },    }request.Body = &model.RdsNoAgentDbRequest{Databases: listDatabasesbody,}response, err := client.AddRdsNoAgentDatabase(request)if err == nil {        fmt.Printf("%+v\n", response)    } else {        fmt.Println(err)    }}
support.huaweicloud.com/api-dbss/AddRdsNoAgentDatabase.html