Secrets: Manage secure values inside any resource (#107803)
This commit is contained in:
@@ -4,13 +4,14 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
grpcstatus "google.golang.org/grpc/status"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
grpcstatus "google.golang.org/grpc/status"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/utils"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/resourcepb"
|
||||
"github.com/grafana/grafana/pkg/util/scheduler"
|
||||
)
|
||||
@@ -59,6 +60,58 @@ func NewTooManyRequestsError(msg string) *resourcepb.ErrorResult {
|
||||
}
|
||||
}
|
||||
|
||||
func newInvalidFieldError(
|
||||
obj utils.GrafanaMetaAccessor,
|
||||
detail string,
|
||||
path string,
|
||||
morePath ...string,
|
||||
) *resourcepb.ErrorResult {
|
||||
gvk := obj.GetGroupVersionKind()
|
||||
return &resourcepb.ErrorResult{
|
||||
Message: detail,
|
||||
Code: http.StatusUnprocessableEntity,
|
||||
Reason: string(metav1.StatusReasonInvalid),
|
||||
Details: &resourcepb.ErrorDetails{
|
||||
Name: obj.GetName(),
|
||||
Group: gvk.Group,
|
||||
Kind: gvk.Kind,
|
||||
Uid: string(obj.GetUID()),
|
||||
Causes: []*resourcepb.ErrorCause{
|
||||
{
|
||||
Reason: string(field.ErrorTypeForbidden),
|
||||
Field: field.NewPath(path, morePath...).String(),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newRequiredFieldError(
|
||||
obj utils.GrafanaMetaAccessor,
|
||||
detail string,
|
||||
path string,
|
||||
morePath ...string,
|
||||
) *resourcepb.ErrorResult {
|
||||
gvk := obj.GetGroupVersionKind()
|
||||
return &resourcepb.ErrorResult{
|
||||
Message: detail,
|
||||
Code: http.StatusUnprocessableEntity,
|
||||
Reason: string(metav1.StatusReasonInvalid),
|
||||
Details: &resourcepb.ErrorDetails{
|
||||
Name: obj.GetName(),
|
||||
Group: gvk.Group,
|
||||
Kind: gvk.Kind,
|
||||
Uid: string(obj.GetUID()),
|
||||
Causes: []*resourcepb.ErrorCause{
|
||||
{
|
||||
Reason: string(field.ErrorTypeRequired),
|
||||
Field: field.NewPath(path, morePath...).String(),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Convert golang errors to status result errors that can be returned to a client
|
||||
func AsErrorResult(err error) *resourcepb.ErrorResult {
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user