|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +// ---------------------------------------------------------------------------- |
| 5 | +// |
| 6 | +// *** AUTO GENERATED CODE *** Type: MMv1 *** |
| 7 | +// |
| 8 | +// ---------------------------------------------------------------------------- |
| 9 | +// |
| 10 | +// This file is automatically generated by Magic Modules and manual |
| 11 | +// changes will be clobbered when the file is regenerated. |
| 12 | +// |
| 13 | +// Please read more about how to change this file in |
| 14 | +// .github/CONTRIBUTING.md. |
| 15 | +// |
| 16 | +// ---------------------------------------------------------------------------- |
| 17 | + |
| 18 | +package cloudsecuritycompliance |
| 19 | + |
| 20 | +import ( |
| 21 | + "encoding/json" |
| 22 | + "errors" |
| 23 | + "fmt" |
| 24 | + "log" |
| 25 | + "strings" |
| 26 | + "time" |
| 27 | + |
| 28 | + "github.com/hashicorp/terraform-provider-google/google/tpgresource" |
| 29 | + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" |
| 30 | + |
| 31 | + "google.golang.org/api/googleapi" |
| 32 | +) |
| 33 | + |
| 34 | +var ( |
| 35 | + _ = json.Marshal |
| 36 | + _ = errors.New |
| 37 | + _ = fmt.Sprintf |
| 38 | + _ = log.Print |
| 39 | + _ = strings.Trim |
| 40 | + _ = time.Now |
| 41 | + _ = tpgresource.SetLabels |
| 42 | + _ = transport_tpg.Config{} |
| 43 | + _ = googleapi.Error{} |
| 44 | +) |
| 45 | + |
| 46 | +type CloudSecurityComplianceOperationWaiter struct { |
| 47 | + Config *transport_tpg.Config |
| 48 | + UserAgent string |
| 49 | + tpgresource.CommonOperationWaiter |
| 50 | +} |
| 51 | + |
| 52 | +func (w *CloudSecurityComplianceOperationWaiter) QueryOp() (interface{}, error) { |
| 53 | + if w == nil { |
| 54 | + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") |
| 55 | + } |
| 56 | + // Returns the proper get. |
| 57 | + url := fmt.Sprintf("%s%s", w.Config.CloudSecurityComplianceBasePath, w.CommonOperationWaiter.Op.Name) |
| 58 | + |
| 59 | + return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| 60 | + Config: w.Config, |
| 61 | + Method: "GET", |
| 62 | + RawURL: url, |
| 63 | + UserAgent: w.UserAgent, |
| 64 | + }) |
| 65 | +} |
| 66 | + |
| 67 | +func createCloudSecurityComplianceWaiter(config *transport_tpg.Config, op map[string]interface{}, activity, userAgent string) (*CloudSecurityComplianceOperationWaiter, error) { |
| 68 | + w := &CloudSecurityComplianceOperationWaiter{ |
| 69 | + Config: config, |
| 70 | + UserAgent: userAgent, |
| 71 | + } |
| 72 | + if err := w.CommonOperationWaiter.SetOp(op); err != nil { |
| 73 | + return nil, err |
| 74 | + } |
| 75 | + return w, nil |
| 76 | +} |
| 77 | + |
| 78 | +// nolint: deadcode,unused |
| 79 | +func CloudSecurityComplianceOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, activity, userAgent string, timeout time.Duration) error { |
| 80 | + w, err := createCloudSecurityComplianceWaiter(config, op, activity, userAgent) |
| 81 | + if err != nil { |
| 82 | + return err |
| 83 | + } |
| 84 | + if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil { |
| 85 | + return err |
| 86 | + } |
| 87 | + rawResponse := []byte(w.CommonOperationWaiter.Op.Response) |
| 88 | + if len(rawResponse) == 0 { |
| 89 | + return errors.New("`resource` not set in operation response") |
| 90 | + } |
| 91 | + return json.Unmarshal(rawResponse, response) |
| 92 | +} |
| 93 | + |
| 94 | +func CloudSecurityComplianceOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, activity, userAgent string, timeout time.Duration) error { |
| 95 | + if val, ok := op["name"]; !ok || val == "" { |
| 96 | + // This was a synchronous call - there is no operation to wait for. |
| 97 | + return nil |
| 98 | + } |
| 99 | + w, err := createCloudSecurityComplianceWaiter(config, op, activity, userAgent) |
| 100 | + if err != nil { |
| 101 | + // If w is nil, the op was synchronous. |
| 102 | + return err |
| 103 | + } |
| 104 | + return tpgresource.OperationWait(w, activity, timeout, config.PollInterval) |
| 105 | +} |
0 commit comments