...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gcp/errors.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gcp

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package gcp
    16  
    17  import (
    18  	"fmt"
    19  	"net/http"
    20  	"strings"
    21  
    22  	"google.golang.org/api/googleapi"
    23  	sqladmin "google.golang.org/api/sqladmin/v1beta4"
    24  )
    25  
    26  func IsNotAuthorizedError(err error) bool {
    27  	return isGoogleErrorWithCode(err, http.StatusForbidden)
    28  }
    29  
    30  func IsNotFoundError(err error) bool {
    31  	return isGoogleErrorWithCode(err, http.StatusNotFound)
    32  }
    33  
    34  func isGoogleErrorWithCode(err error, code int) bool {
    35  	if err == nil {
    36  		return false
    37  	}
    38  	if ge, ok := err.(*googleapi.Error); ok {
    39  		return ge.Code == code
    40  	}
    41  	return false
    42  }
    43  
    44  func FormatSQLOperationErrorMessages(opErrs []*sqladmin.OperationError) string {
    45  	var errMessages []string
    46  	for _, opErr := range opErrs {
    47  		errMessages = append(errMessages, fmt.Sprintf("%v %v", opErr.Code, opErr.Message))
    48  	}
    49  	return strings.Join(errMessages, ", ")
    50  }
    51  

View as plain text