mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-28 22:16:04 +00:00
Adding nil guards to the wait operations (#2936)
<!-- This change is generated by MagicModules. --> /cc @chrisst
This commit is contained in:
parent
d1f1222c01
commit
cf489d4909
@ -18,6 +18,9 @@ type AppEngineOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
matches := appEngineOperationIdRegexp.FindStringSubmatch(w.Op.Name)
|
||||
if len(matches) != 2 {
|
||||
return nil, fmt.Errorf("Expected %d results of parsing operation name, got %d from %s", 2, len(matches), w.Op.Name)
|
||||
|
@ -1,6 +1,8 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/api/cloudfunctions/v1"
|
||||
)
|
||||
|
||||
@ -10,6 +12,9 @@ type CloudFunctionsOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *CloudFunctionsOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
return w.Service.Operations.Get(w.Op.Name).Do()
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ func (w *CommonOperationWaiter) State() string {
|
||||
}
|
||||
|
||||
func (w *CommonOperationWaiter) Error() error {
|
||||
if w.Op.Error != nil {
|
||||
if w != nil && w.Op.Error != nil {
|
||||
return fmt.Errorf("Error code %v, message: %s", w.Op.Error.Code, w.Op.Error.Message)
|
||||
}
|
||||
return nil
|
||||
|
@ -1,6 +1,8 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
composer "google.golang.org/api/composer/v1beta1"
|
||||
)
|
||||
|
||||
@ -10,6 +12,9 @@ type ComposerOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *ComposerOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
return w.Service.Operations.Get(w.Op.Name).Do()
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ type ComputeOperationWaiter struct {
|
||||
|
||||
func (w *ComputeOperationWaiter) State() string {
|
||||
if w == nil || w.Op == nil {
|
||||
return fmt.Sprintf("Operation is nil!")
|
||||
return "<nil>"
|
||||
}
|
||||
|
||||
return w.Op.Status
|
||||
@ -39,6 +39,9 @@ func (w *ComputeOperationWaiter) SetOp(op interface{}) error {
|
||||
}
|
||||
|
||||
func (w *ComputeOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil || w.Op == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
if w.Op.Zone != "" {
|
||||
zone := GetResourceNameFromSelfLink(w.Op.Zone)
|
||||
return w.Service.ZoneOperations.Get(w.Project, zone, w.Op.Name).Do()
|
||||
|
@ -3,7 +3,7 @@ package google
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/api/container/v1beta1"
|
||||
container "google.golang.org/api/container/v1beta1"
|
||||
)
|
||||
|
||||
type ContainerOperationWaiter struct {
|
||||
@ -14,28 +14,41 @@ type ContainerOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *ContainerOperationWaiter) State() string {
|
||||
if w == nil || w.Op == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return w.Op.Status
|
||||
}
|
||||
|
||||
func (w *ContainerOperationWaiter) Error() error {
|
||||
if w.Op.StatusMessage != "" {
|
||||
if w != nil && w.Op != nil {
|
||||
return fmt.Errorf(w.Op.StatusMessage)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *ContainerOperationWaiter) SetOp(op interface{}) error {
|
||||
w.Op = op.(*container.Operation)
|
||||
var ok bool
|
||||
w.Op, ok = op.(*container.Operation)
|
||||
if !ok {
|
||||
return fmt.Errorf("Unable to set operation. Bad type!")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *ContainerOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil || w.Op == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
name := fmt.Sprintf("projects/%s/locations/%s/operations/%s",
|
||||
w.Project, w.Location, w.Op.Name)
|
||||
return w.Service.Projects.Locations.Operations.Get(name).Do()
|
||||
}
|
||||
|
||||
func (w *ContainerOperationWaiter) OpName() string {
|
||||
if w == nil || w.Op == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return w.Op.Name
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/api/dataproc/v1"
|
||||
)
|
||||
|
||||
@ -10,6 +12,9 @@ type DataprocClusterOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *DataprocClusterOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
return w.Service.Projects.Regions.Operations.Get(w.Op.Name).Do()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"google.golang.org/api/dataproc/v1"
|
||||
@ -15,6 +16,9 @@ type DataprocJobOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *DataprocJobOperationWaiter) State() string {
|
||||
if w == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return w.Status
|
||||
}
|
||||
|
||||
@ -32,6 +36,9 @@ func (w *DataprocJobOperationWaiter) SetOp(job interface{}) error {
|
||||
}
|
||||
|
||||
func (w *DataprocJobOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
job, err := w.Service.Projects.Regions.Jobs.Get(w.ProjectId, w.Region, w.JobId).Do()
|
||||
if job != nil {
|
||||
w.Status = job.Status.State
|
||||
@ -40,6 +47,9 @@ func (w *DataprocJobOperationWaiter) QueryOp() (interface{}, error) {
|
||||
}
|
||||
|
||||
func (w *DataprocJobOperationWaiter) OpName() string {
|
||||
if w == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return w.JobId
|
||||
}
|
||||
|
||||
@ -74,6 +84,9 @@ func (w *DataprocDeleteJobOperationWaiter) TargetStates() []string {
|
||||
}
|
||||
|
||||
func (w *DataprocDeleteJobOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
job, err := w.Service.Projects.Regions.Jobs.Get(w.ProjectId, w.Region, w.JobId).Do()
|
||||
if err != nil {
|
||||
if isGoogleApiErrorWithCode(err, http.StatusNotFound) {
|
||||
|
@ -1,7 +1,9 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"google.golang.org/api/redis/v1beta1"
|
||||
"fmt"
|
||||
|
||||
redis "google.golang.org/api/redis/v1beta1"
|
||||
)
|
||||
|
||||
type RedisOperationWaiter struct {
|
||||
@ -10,6 +12,9 @@ type RedisOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *RedisOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
return w.Service.Operations.Get(w.Op.Name).Do()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/api/cloudresourcemanager/v1"
|
||||
resourceManagerV2Beta1 "google.golang.org/api/cloudresourcemanager/v2beta1"
|
||||
)
|
||||
@ -11,6 +13,9 @@ type ResourceManagerOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *ResourceManagerOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
return w.Service.Operations.Get(w.Op.Name).Do()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/api/googleapi"
|
||||
"google.golang.org/api/servicemanagement/v1"
|
||||
)
|
||||
@ -11,6 +13,9 @@ type ServiceManagementOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *ServiceManagementOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
return w.Service.Operations.Get(w.Op.Name).Do()
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"google.golang.org/api/serviceusage/v1beta1"
|
||||
"fmt"
|
||||
|
||||
serviceusage "google.golang.org/api/serviceusage/v1beta1"
|
||||
)
|
||||
|
||||
type ServiceUsageOperationWaiter struct {
|
||||
@ -10,6 +12,9 @@ type ServiceUsageOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *ServiceUsageOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
return w.Service.Operations.Get(w.Op.Name).Do()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/api/spanner/v1"
|
||||
)
|
||||
|
||||
@ -10,6 +12,9 @@ type SpannerInstanceOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *SpannerInstanceOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
return w.Service.Projects.Instances.Operations.Get(w.Op.Name).Do()
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,9 @@ package google
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/api/sqladmin/v1beta4"
|
||||
sqladmin "google.golang.org/api/sqladmin/v1beta4"
|
||||
)
|
||||
|
||||
type SqlAdminOperationWaiter struct {
|
||||
@ -13,26 +14,44 @@ type SqlAdminOperationWaiter struct {
|
||||
}
|
||||
|
||||
func (w *SqlAdminOperationWaiter) State() string {
|
||||
if w == nil || w.Op == nil {
|
||||
return "Operation is nil!"
|
||||
}
|
||||
|
||||
return w.Op.Status
|
||||
}
|
||||
|
||||
func (w *SqlAdminOperationWaiter) Error() error {
|
||||
if w.Op.Error != nil {
|
||||
if w != nil && w.Op != nil && w.Op.Error != nil {
|
||||
return SqlAdminOperationError(*w.Op.Error)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *SqlAdminOperationWaiter) SetOp(op interface{}) error {
|
||||
w.Op = op.(*sqladmin.Operation)
|
||||
var ok bool
|
||||
w.Op, ok = op.(*sqladmin.Operation)
|
||||
if !ok {
|
||||
return fmt.Errorf("Unable to set operation. Bad type!")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *SqlAdminOperationWaiter) QueryOp() (interface{}, error) {
|
||||
if w == nil || w.Op == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
|
||||
}
|
||||
if w.Service == nil {
|
||||
return nil, fmt.Errorf("Cannot query operation, service is nil.")
|
||||
}
|
||||
return w.Service.Operations.Get(w.Project, w.Op.Name).Do()
|
||||
}
|
||||
|
||||
func (w *SqlAdminOperationWaiter) OpName() string {
|
||||
if w == nil || w.Op == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return w.Op.Name
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user