github.com/oam-dev/cluster-gateway@v1.9.0/pkg/apis/cluster/v1alpha1/virtualcluster_errors.go (about) 1 /* 2 Copyright 2023 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1alpha1 18 19 import "errors" 20 21 type emptyCredentialTypeClusterSecretError struct{} 22 23 func (e emptyCredentialTypeClusterSecretError) Error() string { 24 return "secret is not a valid cluster secret, no credential type found" 25 } 26 27 // NewEmptyCredentialTypeClusterSecretError create an invalid cluster secret error due to empty credential type 28 func NewEmptyCredentialTypeClusterSecretError() error { 29 return emptyCredentialTypeClusterSecretError{} 30 } 31 32 type emptyEndpointClusterSecretError struct{} 33 34 func (e emptyEndpointClusterSecretError) Error() string { 35 return "secret is not a valid cluster secret, no credential type found" 36 } 37 38 // NewEmptyEndpointClusterSecretError create an invalid cluster secret error due to empty endpoint 39 func NewEmptyEndpointClusterSecretError() error { 40 return emptyEndpointClusterSecretError{} 41 } 42 43 // IsInvalidClusterSecretError check if an error is an invalid cluster secret error 44 func IsInvalidClusterSecretError(err error) bool { 45 return errors.As(err, &emptyCredentialTypeClusterSecretError{}) || errors.As(err, &emptyEndpointClusterSecretError{}) 46 } 47 48 type invalidManagedClusterError struct{} 49 50 func (e invalidManagedClusterError) Error() string { 51 return "managed cluster has no client config" 52 } 53 54 // NewInvalidManagedClusterError create an invalid managed cluster error 55 func NewInvalidManagedClusterError() error { 56 return invalidManagedClusterError{} 57 } 58 59 // IsInvalidManagedClusterError check if an error is an invalid managed cluster error 60 func IsInvalidManagedClusterError(err error) bool { 61 return errors.As(err, &invalidManagedClusterError{}) 62 }