|
| 1 | +// ---------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** |
| 4 | +// |
| 5 | +// ---------------------------------------------------------------------------- |
| 6 | +// |
| 7 | +// This file is automatically generated by Magic Modules and manual |
| 8 | +// changes will be clobbered when the file is regenerated. |
| 9 | +// |
| 10 | +// Please read more about how to change this file in |
| 11 | +// .github/CONTRIBUTING.md. |
| 12 | +// |
| 13 | +// ---------------------------------------------------------------------------- |
| 14 | +package google |
| 15 | + |
| 16 | +import ( |
| 17 | + "encoding/json" |
| 18 | + "fmt" |
| 19 | + "time" |
| 20 | +) |
| 21 | + |
| 22 | +type GKEHubOperationWaiter struct { |
| 23 | + Config *Config |
| 24 | + UserAgent string |
| 25 | + Project string |
| 26 | + CommonOperationWaiter |
| 27 | +} |
| 28 | + |
| 29 | +func (w *GKEHubOperationWaiter) QueryOp() (interface{}, error) { |
| 30 | + if w == nil { |
| 31 | + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") |
| 32 | + } |
| 33 | + // Returns the proper get. |
| 34 | + url := fmt.Sprintf("https://gkehub.googleapis.com/v1beta1/%s", w.CommonOperationWaiter.Op.Name) |
| 35 | + |
| 36 | + return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil) |
| 37 | +} |
| 38 | + |
| 39 | +func createGKEHubWaiter(config *Config, op map[string]interface{}, project, activity, userAgent string) (*GKEHubOperationWaiter, error) { |
| 40 | + if val, ok := op["name"]; !ok || val == "" { |
| 41 | + // An operation could also be indicated with a "metadata" field. |
| 42 | + if _, ok := op["metadata"]; !ok { |
| 43 | + // This was a synchronous call - there is no operation to wait for. |
| 44 | + return nil, nil |
| 45 | + } |
| 46 | + } |
| 47 | + w := &GKEHubOperationWaiter{ |
| 48 | + Config: config, |
| 49 | + UserAgent: userAgent, |
| 50 | + Project: project, |
| 51 | + } |
| 52 | + if err := w.CommonOperationWaiter.SetOp(op); err != nil { |
| 53 | + return nil, err |
| 54 | + } |
| 55 | + return w, nil |
| 56 | +} |
| 57 | + |
| 58 | +// nolint: deadcode,unused |
| 59 | +func gKEHubOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error { |
| 60 | + w, err := createGKEHubWaiter(config, op, project, activity, userAgent) |
| 61 | + if err != nil || w == nil { |
| 62 | + // If w is nil, the op was synchronous. |
| 63 | + return err |
| 64 | + } |
| 65 | + if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil { |
| 66 | + return err |
| 67 | + } |
| 68 | + return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response) |
| 69 | +} |
| 70 | + |
| 71 | +func gKEHubOperationWaitTime(config *Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error { |
| 72 | + w, err := createGKEHubWaiter(config, op, project, activity, userAgent) |
| 73 | + if err != nil || w == nil { |
| 74 | + // If w is nil, the op was synchronous. |
| 75 | + return err |
| 76 | + } |
| 77 | + return OperationWait(w, activity, timeout, config.PollInterval) |
| 78 | +} |
0 commit comments