|
| 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 lustre |
| 19 | + |
| 20 | +import ( |
| 21 | + "encoding/json" |
| 22 | + "errors" |
| 23 | + "fmt" |
| 24 | + "time" |
| 25 | + |
| 26 | + "github.com/hashicorp/terraform-provider-google/google/tpgresource" |
| 27 | + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" |
| 28 | +) |
| 29 | + |
| 30 | +type LustreOperationWaiter struct { |
| 31 | + Config *transport_tpg.Config |
| 32 | + UserAgent string |
| 33 | + Project string |
| 34 | + tpgresource.CommonOperationWaiter |
| 35 | +} |
| 36 | + |
| 37 | +func (w *LustreOperationWaiter) QueryOp() (interface{}, error) { |
| 38 | + if w == nil { |
| 39 | + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") |
| 40 | + } |
| 41 | + // Returns the proper get. |
| 42 | + url := fmt.Sprintf("%s%s", w.Config.LustreBasePath, w.CommonOperationWaiter.Op.Name) |
| 43 | + |
| 44 | + return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| 45 | + Config: w.Config, |
| 46 | + Method: "GET", |
| 47 | + Project: w.Project, |
| 48 | + RawURL: url, |
| 49 | + UserAgent: w.UserAgent, |
| 50 | + }) |
| 51 | +} |
| 52 | + |
| 53 | +func createLustreWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*LustreOperationWaiter, error) { |
| 54 | + w := &LustreOperationWaiter{ |
| 55 | + Config: config, |
| 56 | + UserAgent: userAgent, |
| 57 | + Project: project, |
| 58 | + } |
| 59 | + if err := w.CommonOperationWaiter.SetOp(op); err != nil { |
| 60 | + return nil, err |
| 61 | + } |
| 62 | + return w, nil |
| 63 | +} |
| 64 | + |
| 65 | +// nolint: deadcode,unused |
| 66 | +func LustreOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error { |
| 67 | + w, err := createLustreWaiter(config, op, project, activity, userAgent) |
| 68 | + if err != nil { |
| 69 | + return err |
| 70 | + } |
| 71 | + if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil { |
| 72 | + return err |
| 73 | + } |
| 74 | + rawResponse := []byte(w.CommonOperationWaiter.Op.Response) |
| 75 | + if len(rawResponse) == 0 { |
| 76 | + return errors.New("`resource` not set in operation response") |
| 77 | + } |
| 78 | + return json.Unmarshal(rawResponse, response) |
| 79 | +} |
| 80 | + |
| 81 | +func LustreOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error { |
| 82 | + if val, ok := op["name"]; !ok || val == "" { |
| 83 | + // This was a synchronous call - there is no operation to wait for. |
| 84 | + return nil |
| 85 | + } |
| 86 | + w, err := createLustreWaiter(config, op, project, activity, userAgent) |
| 87 | + if err != nil { |
| 88 | + // If w is nil, the op was synchronous. |
| 89 | + return err |
| 90 | + } |
| 91 | + return tpgresource.OperationWait(w, activity, timeout, config.PollInterval) |
| 92 | +} |
0 commit comments