How to use adb method of adb Package

Best Syzkaller code snippet using adb.adb

service_alicloud_adb.go

Source:service_alicloud_adb.go Github

copy

Full Screen

...3 "log"4 "regexp"5 "strings"6 "time"7 "github.com/aliyun/alibaba-cloud-sdk-go/services/adb"8 "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"9 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"10 "github.com/hashicorp/terraform-plugin-sdk/helper/schema"11)12type AdbService struct {13 client *connectivity.AliyunClient14}15func (s *AdbService) DescribeAdbCluster(id string) (instance *adb.DBClusterInDescribeDBClusters, err error) {16 request := adb.CreateDescribeDBClustersRequest()17 request.RegionId = s.client.RegionId18 dbClusterIds := []string{}19 dbClusterIds = append(dbClusterIds, id)20 request.DBClusterIds = id21 raw, err := s.client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {22 return adbClient.DescribeDBClusters(request)23 })24 if err != nil {25 if IsExpectedErrors(err, []string{"InvalidDBClusterId.NotFound"}) {26 return nil, WrapErrorf(err, NotFoundMsg, AlibabaCloudSdkGoERROR)27 }28 return nil, WrapErrorf(err, DefaultErrorMsg, id, request.GetActionName(), AlibabaCloudSdkGoERROR)29 }30 addDebug(request.GetActionName(), raw, request.RpcRequest, request)31 response, _ := raw.(*adb.DescribeDBClustersResponse)32 if len(response.Items.DBCluster) < 1 {33 return nil, WrapErrorf(Error(GetNotFoundMessage("Cluster", id)), NotFoundMsg, ProviderERROR)34 }35 return &response.Items.DBCluster[0], nil36}37func (s *AdbService) DescribeAdbClusterAttribute(id string) (instance *adb.DBCluster, err error) {38 request := adb.CreateDescribeDBClusterAttributeRequest()39 request.RegionId = s.client.RegionId40 request.DBClusterId = id41 raw, err := s.client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {42 return adbClient.DescribeDBClusterAttribute(request)43 })44 if err != nil {45 if IsExpectedErrors(err, []string{"InvalidDBClusterId.NotFound"}) {46 return instance, WrapErrorf(err, NotFoundMsg, AlibabaCloudSdkGoERROR)47 }48 return instance, WrapErrorf(err, DefaultErrorMsg, id, request.GetActionName(), AlibabaCloudSdkGoERROR)49 }50 addDebug(request.GetActionName(), raw, request.RpcRequest, request)51 response, _ := raw.(*adb.DescribeDBClusterAttributeResponse)52 if len(response.Items.DBCluster) < 1 {53 return nil, WrapErrorf(Error(GetNotFoundMessage("Cluster", id)), NotFoundMsg, ProviderERROR)54 }55 return &response.Items.DBCluster[0], nil56}57func (s *AdbService) DescribeAdbAutoRenewAttribute(id string) (instance *adb.AutoRenewAttribute, err error) {58 request := adb.CreateDescribeAutoRenewAttributeRequest()59 request.RegionId = s.client.RegionId60 request.DBClusterIds = id61 raw, err := s.client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {62 return adbClient.DescribeAutoRenewAttribute(request)63 })64 if err != nil {65 if IsExpectedErrors(err, []string{"InvalidDBClusterId.NotFound"}) {66 return instance, WrapErrorf(err, NotFoundMsg, AlibabaCloudSdkGoERROR)67 }68 return instance, WrapErrorf(err, DefaultErrorMsg, id, request.GetActionName(), AlibabaCloudSdkGoERROR)69 }70 addDebug(request.GetActionName(), raw, request.RpcRequest, request)71 response, _ := raw.(*adb.DescribeAutoRenewAttributeResponse)72 if len(response.Items.AutoRenewAttribute) < 1 {73 return nil, WrapErrorf(Error(GetNotFoundMessage("Cluster", id)), NotFoundMsg, ProviderERROR)74 }75 return &response.Items.AutoRenewAttribute[0], nil76}77func (s *AdbService) WaitForAdbConnection(id string, status Status, timeout int) error {78 deadline := time.Now().Add(time.Duration(timeout) * time.Second)79 for {80 object, err := s.DescribeAdbConnection(id)81 if err != nil {82 if NotFoundError(err) {83 if status == Deleted {84 return nil85 }86 } else {87 return WrapError(err)88 }89 }90 if status != Deleted && object != nil && object.ConnectionString != "" {91 return nil92 }93 if time.Now().After(deadline) {94 return WrapErrorf(err, WaitTimeoutMsg, id, GetFunc(1), timeout, object.ConnectionString, id, ProviderERROR)95 }96 time.Sleep(DefaultIntervalShort * time.Second)97 }98}99func (s *AdbService) DescribeAdbConnection(id string) (*adb.Address, error) {100 parts, err := ParseResourceId(id, 2)101 if err != nil {102 return nil, WrapError(err)103 }104 deadline := time.Now().Add(time.Duration(DefaultIntervalLong) * time.Second)105 for {106 object, err := s.DescribeAdbClusterNetInfo(parts[0])107 if err != nil {108 if NotFoundError(err) {109 return nil, WrapErrorf(err, NotFoundMsg, AlibabaCloudSdkGoERROR)110 }111 return nil, WrapError(err)112 }113 if object != nil {114 for _, p := range object {115 if p.NetType == "Public" {116 return &p, nil117 }118 }119 }120 time.Sleep(DefaultIntervalMini * time.Second)121 if time.Now().After(deadline) {122 break123 }124 }125 return nil, WrapErrorf(Error(GetNotFoundMessage("DBConnection", id)), NotFoundMsg, ProviderERROR)126}127func (s *AdbService) DescribeAdbClusterNetInfo(id string) ([]adb.Address, error) {128 request := adb.CreateDescribeDBClusterNetInfoRequest()129 request.RegionId = s.client.RegionId130 request.DBClusterId = id131 raw, err := s.client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {132 return adbClient.DescribeDBClusterNetInfo(request)133 })134 if err != nil {135 if IsExpectedErrors(err, []string{"InvalidDBClusterId.NotFound"}) {136 return nil, WrapErrorf(err, NotFoundMsg, AlibabaCloudSdkGoERROR)137 }138 return nil, WrapErrorf(err, DefaultErrorMsg, id, request.GetActionName(), AlibabaCloudSdkGoERROR)139 }140 addDebug(request.GetActionName(), raw, request.RpcRequest, request)141 response, _ := raw.(*adb.DescribeDBClusterNetInfoResponse)142 if len(response.Items.Address) < 1 {143 return nil, WrapErrorf(Error(GetNotFoundMessage("DBInstanceNetInfo", id)), NotFoundMsg, ProviderERROR)144 }145 return response.Items.Address, nil146}147func (s *AdbService) WaitForAdbAccount(id string, status Status, timeout int) error {148 deadline := time.Now().Add(time.Duration(timeout) * time.Second)149 for {150 object, err := s.DescribeAdbAccount(id)151 if err != nil {152 if NotFoundError(err) {153 if status == Deleted {154 return nil155 }156 } else {157 return WrapError(err)158 }159 }160 if object.AccountStatus == string(status) {161 break162 }163 if time.Now().After(deadline) {164 return WrapErrorf(err, WaitTimeoutMsg, id, GetFunc(1), timeout, object.AccountStatus, status, ProviderERROR)165 }166 time.Sleep(DefaultIntervalShort * time.Second)167 }168 return nil169}170func (s *AdbService) DescribeAdbAccount(id string) (ds *adb.DBAccount, err error) {171 parts, err := ParseResourceId(id, 2)172 if err != nil {173 err = WrapError(err)174 return175 }176 request := adb.CreateDescribeAccountsRequest()177 request.RegionId = s.client.RegionId178 request.DBClusterId = parts[0]179 request.AccountName = parts[1]180 invoker := NewInvoker()181 invoker.AddCatcher(DBInstanceStatusCatcher)182 var response *adb.DescribeAccountsResponse183 if err := invoker.Run(func() error {184 raw, err := s.client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {185 return adbClient.DescribeAccounts(request)186 })187 if err != nil {188 return err189 }190 addDebug(request.GetActionName(), raw, request.RpcRequest, request)191 response, _ = raw.(*adb.DescribeAccountsResponse)192 return nil193 }); err != nil {194 if IsExpectedErrors(err, []string{"InvalidDBClusterId.NotFound"}) {195 return nil, WrapErrorf(err, NotFoundMsg, AlibabaCloudSdkGoERROR)196 }197 return nil, WrapErrorf(err, DefaultErrorMsg, id, request.GetActionName(), AlibabaCloudSdkGoERROR)198 }199 if len(response.AccountList.DBAccount) < 1 {200 return nil, WrapErrorf(Error(GetNotFoundMessage("DBAccount", id)), NotFoundMsg, ProviderERROR)201 }202 return &response.AccountList.DBAccount[0], nil203}204// WaitForInstance waits for instance to given status205func (s *AdbService) WaitForAdbInstance(id string, status Status, timeout int) error {206 deadline := time.Now().Add(time.Duration(timeout) * time.Second)207 for {208 object, err := s.DescribeAdbCluster(id)209 if err != nil {210 if NotFoundError(err) {211 if status == Deleted {212 return nil213 }214 } else {215 return WrapError(err)216 }217 }218 if strings.ToLower(object.DBClusterStatus) == strings.ToLower(string(status)) {219 break220 }221 if time.Now().After(deadline) {222 return WrapErrorf(err, WaitTimeoutMsg, id, GetFunc(1), timeout, object.DBClusterStatus, status, ProviderERROR)223 }224 time.Sleep(DefaultIntervalShort * time.Second)225 }226 return nil227}228func (s *AdbService) setClusterTags(d *schema.ResourceData) error {229 if d.HasChange("tags") {230 oraw, nraw := d.GetChange("tags")231 o := oraw.(map[string]interface{})232 n := nraw.(map[string]interface{})233 create, remove := s.diffTags(s.tagsFromMap(o), s.tagsFromMap(n))234 if len(remove) > 0 {235 var tagKey []string236 for _, v := range remove {237 tagKey = append(tagKey, v.Key)238 }239 request := adb.CreateUntagResourcesRequest()240 request.ResourceId = &[]string{d.Id()}241 request.ResourceType = "cluster"242 request.TagKey = &tagKey243 request.RegionId = s.client.RegionId244 raw, err := s.client.WithAdbClient(func(client *adb.Client) (interface{}, error) {245 return client.UntagResources(request)246 })247 if err != nil {248 return WrapErrorf(err, DefaultErrorMsg, d.Id(), request.GetActionName(), AlibabaCloudSdkGoERROR)249 }250 addDebug(request.GetActionName(), raw, request.RpcRequest, request)251 }252 if len(create) > 0 {253 request := adb.CreateTagResourcesRequest()254 request.ResourceId = &[]string{d.Id()}255 request.Tag = &create256 request.ResourceType = "cluster"257 request.RegionId = s.client.RegionId258 raw, err := s.client.WithAdbClient(func(client *adb.Client) (interface{}, error) {259 return client.TagResources(request)260 })261 if err != nil {262 return WrapErrorf(err, DefaultErrorMsg, d.Id(), request.GetActionName(), AlibabaCloudSdkGoERROR)263 }264 addDebug(request.GetActionName(), raw, request.RpcRequest, request)265 }266 d.SetPartial("tags")267 }268 return nil269}270func (s *AdbService) diffTags(oldTags, newTags []adb.TagResourcesTag) ([]adb.TagResourcesTag, []adb.TagResourcesTag) {271 // First, we're creating everything we have272 create := make(map[string]interface{})273 for _, t := range newTags {274 create[t.Key] = t.Value275 }276 // Build the list of what to remove277 var remove []adb.TagResourcesTag278 for _, t := range oldTags {279 old, ok := create[t.Key]280 if !ok || old != t.Value {281 // Delete it!282 remove = append(remove, t)283 }284 }285 return s.tagsFromMap(create), remove286}287func (s *AdbService) tagsToMap(tags []adb.TagResource) map[string]string {288 result := make(map[string]string)289 for _, t := range tags {290 if !s.ignoreTag(t) {291 result[t.TagKey] = t.TagValue292 }293 }294 return result295}296func (s *AdbService) tagsFromMap(m map[string]interface{}) []adb.TagResourcesTag {297 result := make([]adb.TagResourcesTag, 0, len(m))298 for k, v := range m {299 result = append(result, adb.TagResourcesTag{300 Key: k,301 Value: v.(string),302 })303 }304 return result305}306func (s *AdbService) ignoreTag(t adb.TagResource) bool {307 filter := []string{"^aliyun", "^acs:", "^http://", "^https://"}308 for _, v := range filter {309 log.Printf("[DEBUG] Matching prefix %v with %v\n", v, t.TagKey)310 ok, _ := regexp.MatchString(v, t.TagValue)311 if ok {312 log.Printf("[DEBUG] Found Alibaba Cloud specific t %s (val: %s), ignoring.\n", t.TagKey, t.TagValue)313 return true314 }315 }316 return false317}318func (s *AdbService) DescribeTags(resourceId string, resourceType TagResourceType) (tags []adb.TagResource, err error) {319 request := adb.CreateListTagResourcesRequest()320 request.RegionId = s.client.RegionId321 request.ResourceType = string(resourceType)322 request.ResourceId = &[]string{resourceId}323 raw, err := s.client.WithAdbClient(func(client *adb.Client) (interface{}, error) {324 return client.ListTagResources(request)325 })326 if err != nil {327 err = WrapErrorf(err, DefaultErrorMsg, resourceId, request.GetActionName(), AlibabaCloudSdkGoERROR)328 return329 }330 addDebug(request.GetActionName(), raw, request.RpcRequest, request)331 response, _ := raw.(*adb.ListTagResourcesResponse)332 return response.TagResources.TagResource, nil333}334// WaitForCluster waits for cluster to given status335func (s *AdbService) WaitForCluster(id string, status Status, timeout int) error {336 deadline := time.Now().Add(time.Duration(timeout) * time.Second)337 for {338 object, err := s.DescribeAdbClusterAttribute(id)339 if err != nil {340 if NotFoundError(err) {341 if status == Deleted {342 return nil343 }344 } else {345 return WrapError(err)346 }347 }348 if strings.ToLower(object.DBClusterStatus) == strings.ToLower(string(status)) {349 break350 }351 if time.Now().After(deadline) {352 return WrapErrorf(err, WaitTimeoutMsg, id, GetFunc(1), timeout, object.DBClusterStatus, status, ProviderERROR)353 }354 time.Sleep(DefaultIntervalShort * time.Second)355 }356 return nil357}358func (s *AdbService) DescribeDBSecurityIps(clusterId string) (ips []string, err error) {359 request := adb.CreateDescribeDBClusterAccessWhiteListRequest()360 request.RegionId = s.client.RegionId361 request.DBClusterId = clusterId362 raw, err := s.client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {363 return adbClient.DescribeDBClusterAccessWhiteList(request)364 })365 if err != nil {366 return ips, WrapErrorf(err, DefaultErrorMsg, clusterId, request.GetActionName(), AlibabaCloudSdkGoERROR)367 }368 addDebug(request.GetActionName(), raw, request.RpcRequest, request)369 resp, _ := raw.(*adb.DescribeDBClusterAccessWhiteListResponse)370 var ipstr, separator string371 ipsMap := make(map[string]string)372 for _, ip := range resp.Items.IPArray {373 if ip.DBClusterIPArrayAttribute != "hidden" {374 ipstr += separator + ip.SecurityIPList375 separator = COMMA_SEPARATED376 }377 }378 for _, ip := range strings.Split(ipstr, COMMA_SEPARATED) {379 ipsMap[ip] = ip380 }381 var finalIps []string382 if len(ipsMap) > 0 {383 for key := range ipsMap {384 finalIps = append(finalIps, key)385 }386 }387 return finalIps, nil388}389func (s *AdbService) ModifyDBSecurityIps(clusterId, ips string) error {390 request := adb.CreateModifyDBClusterAccessWhiteListRequest()391 request.RegionId = s.client.RegionId392 request.DBClusterId = clusterId393 request.SecurityIps = ips394 raw, err := s.client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {395 return adbClient.ModifyDBClusterAccessWhiteList(request)396 })397 if err != nil {398 return WrapErrorf(err, DefaultErrorMsg, clusterId, request.GetActionName(), AlibabaCloudSdkGoERROR)399 }400 addDebug(request.GetActionName(), raw, request.RpcRequest, request)401 if err := s.WaitForCluster(clusterId, Running, DefaultTimeoutMedium); err != nil {402 return WrapError(err)403 }404 return nil405}406func (s *AdbService) DescribeAdbBackupPolicy(id string) (policy *adb.DescribeBackupPolicyResponse, err error) {407 request := adb.CreateDescribeBackupPolicyRequest()408 request.DBClusterId = id409 request.RegionId = s.client.RegionId410 raw, err := s.client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {411 return adbClient.DescribeBackupPolicy(request)412 })413 if err != nil {414 if IsExpectedErrors(err, []string{"InvalidDBClusterId.NotFound"}) {415 return nil, WrapErrorf(err, NotFoundMsg, AlibabaCloudSdkGoERROR)416 }417 return policy, WrapErrorf(err, DefaultErrorMsg, id, request.GetActionName(), AlibabaCloudSdkGoERROR)418 }419 addDebug(request.GetActionName(), raw, request.RpcRequest, request)420 return raw.(*adb.DescribeBackupPolicyResponse), nil421}422func (s *AdbService) ModifyAdbBackupPolicy(clusterId, backupTime, backupPeriod string) error {423 request := adb.CreateModifyBackupPolicyRequest()424 request.RegionId = s.client.RegionId425 request.DBClusterId = clusterId426 request.PreferredBackupPeriod = backupPeriod427 request.PreferredBackupTime = backupTime428 raw, err := s.client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {429 return adbClient.ModifyBackupPolicy(request)430 })431 if err != nil {432 return WrapErrorf(err, DefaultErrorMsg, clusterId, request.GetActionName(), AlibabaCloudSdkGoERROR)433 }434 addDebug(request.GetActionName(), raw, request.RpcRequest, request)435 if err := s.WaitForCluster(clusterId, Running, DefaultTimeoutMedium); err != nil {436 return WrapError(err)437 }438 return nil439}440func (s *AdbService) AdbClusterStateRefreshFunc(id string, failStates []string) resource.StateRefreshFunc {441 return func() (interface{}, string, error) {442 object, err := s.DescribeAdbClusterAttribute(id)443 if err != nil {...

Full Screen

Full Screen

resource_alicloud_adb_account.go

Source:resource_alicloud_adb_account.go Github

copy

Full Screen

2import (3 "fmt"4 "strings"5 "time"6 "github.com/aliyun/alibaba-cloud-sdk-go/services/adb"7 "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"8 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"9 "github.com/hashicorp/terraform-plugin-sdk/helper/schema"10 "github.com/hashicorp/terraform-plugin-sdk/helper/validation"11)12func resourceAlicloudAdbAccount() *schema.Resource {13 return &schema.Resource{14 Create: resourceAlicloudAdbAccountCreate,15 Read: resourceAlicloudAdbAccountRead,16 Update: resourceAlicloudAdbAccountUpdate,17 Delete: resourceAlicloudAdbAccountDelete,18 Importer: &schema.ResourceImporter{19 State: schema.ImportStatePassthrough,20 },21 Schema: map[string]*schema.Schema{22 "db_cluster_id": {23 Type: schema.TypeString,24 ForceNew: true,25 Required: true,26 },27 "account_name": {28 Type: schema.TypeString,29 ForceNew: true,30 Required: true,31 },32 "account_password": {33 Type: schema.TypeString,34 Optional: true,35 Sensitive: true,36 },37 "kms_encrypted_password": {38 Type: schema.TypeString,39 Optional: true,40 DiffSuppressFunc: kmsDiffSuppressFunc,41 },42 "kms_encryption_context": {43 Type: schema.TypeMap,44 Optional: true,45 DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {46 return d.Get("kms_encrypted_password").(string) == ""47 },48 Elem: schema.TypeString,49 },50 "account_type": {51 Type: schema.TypeString,52 Optional: true,53 ValidateFunc: validation.StringInSlice([]string{string("Super")}, false),54 Default: "Super",55 ForceNew: true,56 Removed: "Field 'account_type' has been removed from provider version 1.81.0.",57 },58 "account_description": {59 Type: schema.TypeString,60 Optional: true,61 },62 },63 }64}65func resourceAlicloudAdbAccountCreate(d *schema.ResourceData, meta interface{}) error {66 client := meta.(*connectivity.AliyunClient)67 adbService := AdbService{client}68 request := adb.CreateCreateAccountRequest()69 request.RegionId = client.RegionId70 request.DBClusterId = d.Get("db_cluster_id").(string)71 request.AccountName = d.Get("account_name").(string)72 password := d.Get("account_password").(string)73 kmsPassword := d.Get("kms_encrypted_password").(string)74 if password == "" && kmsPassword == "" {75 return WrapError(Error("One of the 'password' and 'kms_encrypted_password' should be set."))76 }77 if password != "" {78 request.AccountPassword = password79 } else {80 kmsService := KmsService{client}81 decryptResp, err := kmsService.Decrypt(kmsPassword, d.Get("kms_encryption_context").(map[string]interface{}))82 if err != nil {83 return WrapError(err)84 }85 request.AccountPassword = decryptResp.Plaintext86 }87 // Description will not be set when account type is normal and it is a API bug88 if v, ok := d.GetOk("account_description"); ok && v.(string) != "" {89 request.AccountDescription = v.(string)90 }91 err := resource.Retry(5*time.Minute, func() *resource.RetryError {92 raw, err := client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {93 return adbClient.CreateAccount(request)94 })95 if err != nil {96 if IsExpectedErrors(err, OperationDeniedDBStatus) {97 time.Sleep(5 * time.Second)98 return resource.RetryableError(err)99 }100 return resource.NonRetryableError(err)101 }102 addDebug(request.GetActionName(), raw, request.RpcRequest, request)103 return nil104 })105 if err != nil {106 return WrapErrorf(err, DefaultErrorMsg, "alicloud_adb_account", request.GetActionName(), AlibabaCloudSdkGoERROR)107 }108 d.SetId(fmt.Sprintf("%s%s%s", request.DBClusterId, COLON_SEPARATED, request.AccountName))109 if err := adbService.WaitForAdbAccount(d.Id(), Available, DefaultTimeoutMedium); err != nil {110 return WrapError(err)111 }112 return resourceAlicloudAdbAccountRead(d, meta)113}114func resourceAlicloudAdbAccountRead(d *schema.ResourceData, meta interface{}) error {115 client := meta.(*connectivity.AliyunClient)116 adbService := AdbService{client}117 object, err := adbService.DescribeAdbAccount(d.Id())118 if err != nil {119 if NotFoundError(err) {120 d.SetId("")121 return nil122 }123 return WrapError(err)124 }125 parts, err := ParseResourceId(d.Id(), 2)126 if err != nil {127 return WrapError(err)128 }129 d.Set("db_cluster_id", parts[0])130 d.Set("account_name", object.AccountName)131 d.Set("account_description", object.AccountDescription)132 return nil133}134func resourceAlicloudAdbAccountUpdate(d *schema.ResourceData, meta interface{}) error {135 client := meta.(*connectivity.AliyunClient)136 adbService := AdbService{client}137 d.Partial(true)138 parts := strings.Split(d.Id(), COLON_SEPARATED)139 instanceId := parts[0]140 accountName := parts[1]141 if d.HasChange("account_description") {142 if err := adbService.WaitForAdbAccount(d.Id(), Available, DefaultTimeoutMedium); err != nil {143 return WrapError(err)144 }145 request := adb.CreateModifyAccountDescriptionRequest()146 request.RegionId = client.RegionId147 request.DBClusterId = instanceId148 request.AccountName = accountName149 request.AccountDescription = d.Get("account_description").(string)150 raw, err := client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {151 return adbClient.ModifyAccountDescription(request)152 })153 if err != nil {154 return WrapErrorf(err, DefaultErrorMsg, d.Id(), request.GetActionName(), AlibabaCloudSdkGoERROR)155 }156 addDebug(request.GetActionName(), raw, request.RpcRequest, request)157 d.SetPartial("account_description")158 }159 if d.HasChange("account_password") || d.HasChange("kms_encrypted_password") {160 if err := adbService.WaitForAdbAccount(d.Id(), Available, DefaultTimeoutMedium); err != nil {161 return WrapError(err)162 }163 request := adb.CreateResetAccountPasswordRequest()164 request.RegionId = client.RegionId165 request.DBClusterId = instanceId166 request.AccountName = accountName167 password := d.Get("account_password").(string)168 kmsPassword := d.Get("kms_encrypted_password").(string)169 if password == "" && kmsPassword == "" {170 return WrapError(Error("One of the 'password' and 'kms_encrypted_password' should be set."))171 }172 if password != "" {173 request.AccountPassword = password174 } else {175 kmsService := KmsService{meta.(*connectivity.AliyunClient)}176 decryptResp, err := kmsService.Decrypt(kmsPassword, d.Get("kms_encryption_context").(map[string]interface{}))177 if err != nil {178 return WrapError(err)179 }180 request.AccountPassword = decryptResp.Plaintext181 }182 raw, err := client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {183 return adbClient.ResetAccountPassword(request)184 })185 if err != nil {186 return WrapErrorf(err, DefaultErrorMsg, d.Id(), request.GetActionName(), AlibabaCloudSdkGoERROR)187 }188 addDebug(request.GetActionName(), raw, request.RpcRequest, request)189 d.SetPartial("account_password")190 }191 d.Partial(false)192 return resourceAlicloudAdbAccountRead(d, meta)193}194func resourceAlicloudAdbAccountDelete(d *schema.ResourceData, meta interface{}) error {195 client := meta.(*connectivity.AliyunClient)196 adbService := AdbService{client}197 parts, err := ParseResourceId(d.Id(), 2)198 if err != nil {199 return WrapError(err)200 }201 request := adb.CreateDeleteAccountRequest()202 request.RegionId = client.RegionId203 request.DBClusterId = parts[0]204 request.AccountName = parts[1]205 raw, err := client.WithAdbClient(func(adbClient *adb.Client) (interface{}, error) {206 return adbClient.DeleteAccount(request)207 })208 if err != nil {209 if IsExpectedErrors(err, []string{"InvalidAccountName.NotFound"}) {210 return nil211 }212 return WrapErrorf(err, DefaultErrorMsg, d.Id(), request.GetActionName(), AlibabaCloudSdkGoERROR)213 }214 addDebug(request.GetActionName(), raw, request.RpcRequest, request)215 return adbService.WaitForAdbAccount(d.Id(), Deleted, DefaultTimeoutMedium)216}...

Full Screen

Full Screen

InstallApk.go

Source:InstallApk.go Github

copy

Full Screen

1package adb2import (3 "CPH-SDK/conf"4 "CPH-SDK/httphelper2"5 "CPH-SDK/response2"6 "encoding/json"7 "fmt"8 "log"9 "net/http"10)11type AdbPostBody struct {12 Command string `json:"command"`13 Content string `json:"content"`14 ServerIds []string `json:"server_ids,omitempty"`15 PhoneIds []string `json:"phone_ids,omitempty"`16}17func GetPostBody(r *http.Request, format string) *AdbPostBody {18 var adb AdbPostBody19 err := json.NewDecoder(r.Body).Decode(&adb)20 if err != nil {21 return nil22 }23 if len(adb.PhoneIds) == 0 || len(adb.Content) == 0 {24 return nil25 }26 adb.Command = format27 return &adb28}29func GetInstallApkPostBody(r *http.Request) *AdbPostBody {30 var adb AdbPostBody31 err := json.NewDecoder(r.Body).Decode(&adb)32 if err != nil {33 return nil34 }35 if len(adb.PhoneIds) == 0 || len(adb.Content) == 0 {36 return nil37 }38 return &adb39}40func InstallApk(w http.ResponseWriter, r *http.Request) {41 r.Header.Add("content-type", "application/json")42 resp := response2.NewResp()43 uri := fmt.Sprintf("https://%s/v1/%s/cloud-phone/phones/commands", conf.Config.Huawei.Endpoint, conf.Config.Huawei.ProjectId)44 postbody := GetInstallApkPostBody(r)45 if postbody == nil {46 resp.BadReq(w)47 return48 }49 d, _ := json.Marshal(postbody)50 body, err := httphelper2.HttpPost(uri, d)51 if err != nil {52 log.Println("InstallApk err: ", err)...

Full Screen

Full Screen

adb

Using AI Code Generation

copy

Full Screen

1import (2type adb struct{}3func (a adb) charge() {4 fmt.Println("charging")5}6func (a adb) transfer() {7 fmt.Println("transferring")8}9const (10type connector interface {11 charge()12 transfer()13}14type usbC struct{}15func (u usbC) charge() {16 fmt.Println("charging")17}18func (u usbC) transfer() {19 fmt.Println("transferring")20}21func chargeAndTransfer(c connector) {22 c.charge()23 c.transfer()24}25func main() {26 fmt.Println(reflect.TypeOf(c))27 fmt.Println(reflect.TypeOf(c))28}

Full Screen

Full Screen

adb

Using AI Code Generation

copy

Full Screen

1import (2type adb struct {3}4func (a *adb) connect() {5 fmt.Println("adb connect")6}7func (a *adb) disconnect() {8 fmt.Println("adb disconnect")9}10type phone struct {11}12func (p *phone) call() {13 fmt.Println("phone call")14}15func (p *phone) disconnect() {16 fmt.Println("phone disconnect")17}18func main() {

Full Screen

Full Screen

adb

Using AI Code Generation

copy

Full Screen

1import (2type adb struct {3}4func (a adb) call() {5 fmt.Println("calling from", a.brand)6}7func (a adb) msg() {8 fmt.Println("msg from", a.brand)9}10func (a adb) camera() {11 fmt.Println("camera from", a.brand)12}13func (a adb) price1() {14 fmt.Println("price of", a.brand, a.price)15}16type samsung struct {17}18func main() {19 s1 := samsung{}20 s1.call()21 s1.msg()22 s1.camera()23 s1.price1()24 fmt.Println(reflect.TypeOf(s1))25 fmt.Println(reflect.ValueOf(s1))26}

Full Screen

Full Screen

adb

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cmd := exec.Command("adb", "devices")4 if err := cmd.Start(); err != nil {5 log.Fatal(err)6 }7 fmt.Println("Command started")8 if err := cmd.Wait(); err != nil {9 log.Fatal(err)10 }11 fmt.Println("Command finished successfully")12}

Full Screen

Full Screen

adb

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cmd := exec.Command("adb", "devices")4 out, err := cmd.Output()5 if err != nil {6 log.Fatal(err)7 }8 str := string(out[:])9 split := strings.Split(str, "\n")10 for _, eachline := range split {11 if strings.Index(eachline, "List") == -1 && strings.Index(eachline, "device") != -1 {12 deviceID := strings.Split(eachline, "\t")13 fmt.Println(deviceID[0])14 }15 }16}17import (18func main() {19 cmd := exec.Command("adb", "devices")20 out, err := cmd.Output()21 if err != nil {22 log.Fatal(err)23 }24 str := string(out[:])25 split := strings.Split(str, "\n")26 for _, eachline := range split {27 if strings.Index(eachline, "List") == -1 && strings.Index(eachline, "device") != -1 {28 deviceID := strings.Split(eachline, "\t")29 fmt.Println(deviceID[0])30 }31 }32}33import (34func main() {35 cmd := exec.Command("adb", "devices")36 out, err := cmd.Output()37 if err != nil {38 log.Fatal(err)39 }40 str := string(out[:])

Full Screen

Full Screen

adb

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 adb := adb.New()4 devices, err := adb.Devices()5 if err != nil {6 fmt.Println(err)7 }8 fmt.Println(devices)9}

Full Screen

Full Screen

adb

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 adb.AdbMethod()4 fmt.Println("hello")5}6import (7func main() {8 adb.AdbMethod()9 fmt.Println("hello")10}11import (12func main() {13 adb.AdbMethod()14 fmt.Println("hello")15}16import (17func main() {18 adb.AdbMethod()19 fmt.Println("hello")20}21import (22func main() {23 adb.AdbMethod()24 fmt.Println("hello")25}26import (27func main() {28 adb.AdbMethod()29 fmt.Println("hello")30}31import (32func main() {33 adb.AdbMethod()34 fmt.Println("hello")35}36import (37func main() {38 adb.AdbMethod()39 fmt.Println("hello")40}41import (42func main() {43 adb.AdbMethod()44 fmt.Println("hello")45}

Full Screen

Full Screen

adb

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 adb := adb.Adb{}4 android := adb.NewAndroid()5 adb = android.NewAdb()6 screen := adb.NewScreen()

Full Screen

Full Screen

adb

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 adb.Adb()4}5import (6func main() {7 adb.Adb()8}9import (10func main() {11 adb.Adb()12}13import (14func main() {15 adb.Adb()16}17import (18func main() {19 adb.Adb()20}21import (22func main() {23 adb.Adb()24}25import (26func main() {

Full Screen

Full Screen

adb

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 adb := new(adb)4 reader := bufio.NewReader(os.Stdin)5 for {6 fmt.Println("Enter 1 to enter the data")7 fmt.Println("Enter 2 to display the data")8 fmt.Println("Enter 3 to update the data")9 fmt.Println("Enter 4 to delete the data")10 fmt.Println("Enter 5 to exit")11 input, _ := reader.ReadString('\n')12 option, _ := strconv.Atoi(strings.TrimSpace(input))13 switch option {14 adb.insert()15 adb.display()16 adb.update()17 adb.delete()18 os.Exit(0)19 fmt.Println("Invalid option")20 }21 }22}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful