ShortURL: App platform migration support for dual write (#109221)
This commit is contained in:
@@ -3,6 +3,7 @@ package kinds
|
||||
shorturl: {
|
||||
kind: "ShortURL"
|
||||
pluralName: "ShortURLs"
|
||||
validation: operations: ["CREATE","UPDATE"]
|
||||
schema: {
|
||||
spec: {
|
||||
// The original path to where the short url is linking too e.g. https://localhost:3000/eer8i1kictngga/new-dashboard-with-lib-panel
|
||||
|
||||
@@ -35,7 +35,15 @@ var appManifestData = app.ManifestData{
|
||||
Plural: "ShortURLs",
|
||||
Scope: "Namespaced",
|
||||
Conversion: false,
|
||||
Schema: &versionSchemaShortURLv1alpha1,
|
||||
Admission: &app.AdmissionCapabilities{
|
||||
Validation: &app.ValidationCapability{
|
||||
Operations: []app.AdmissionOperation{
|
||||
app.AdmissionOperationCreate,
|
||||
app.AdmissionOperationUpdate,
|
||||
},
|
||||
},
|
||||
},
|
||||
Schema: &versionSchemaShortURLv1alpha1,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -3,6 +3,8 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/klog/v2"
|
||||
@@ -41,6 +43,24 @@ func New(cfg app.Config) (app.App, error) {
|
||||
ManagedKinds: []simple.AppManagedKind{
|
||||
{
|
||||
Kind: shorturlv1alpha1.ShortURLKind(),
|
||||
Validator: &simple.Validator{
|
||||
ValidateFunc: func(ctx context.Context, req *app.AdmissionRequest) error {
|
||||
// Cast the incoming object to ShortURL for validation
|
||||
shortURL, ok := req.Object.(*shorturlv1alpha1.ShortURL)
|
||||
if !ok {
|
||||
return fmt.Errorf("expected ShortURL object, got %T", req.Object)
|
||||
}
|
||||
|
||||
relPath := strings.TrimSpace(shortURL.Spec.Path)
|
||||
if path.IsAbs(relPath) {
|
||||
return fmt.Errorf("%w: %s", ErrShortURLAbsolutePath, relPath)
|
||||
}
|
||||
if strings.Contains(relPath, "../") {
|
||||
return fmt.Errorf("%w: %s", ErrShortURLInvalidPath, relPath)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user