Created
April 15, 2015 20:40
-
-
Save derekwaynecarr/13534fd404e4cdd27210 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectTyper, admit admission.Interface) restful.RouteFunction { | |
return func(req *restful.Request, res *restful.Response) { | |
w := res.ResponseWriter | |
// TODO: we either want to remove timeout or document it (if we document, move timeout out of this function and declare it in api_installer) | |
timeout := parseTimeout(req.Request.URL.Query().Get("timeout")) | |
namespace, name, err := scope.Namer.Name(req) | |
if err != nil { | |
errorJSON(err, scope.Codec, w) | |
return | |
} | |
ctx := scope.ContextFunc(req) | |
ctx = api.WithNamespace(ctx, namespace) | |
body, err := readBody(req.Request) | |
if err != nil { | |
errorJSON(err, scope.Codec, w) | |
return | |
} | |
obj := r.New() | |
if err := scope.Codec.DecodeInto(body, obj); err != nil { | |
err = transformDecodeError(typer, err, obj, body) | |
errorJSON(err, scope.Codec, w) | |
return | |
} | |
if err := checkName(obj, name, namespace, scope.Namer); err != nil { | |
errorJSON(err, scope.Codec, w) | |
return | |
} | |
_, kind, err := typer.ObjectVersionAndKind(obj) | |
if err != nil { | |
errorJSON(err, scope.Codec, w) | |
return | |
} | |
err = admit.Admit(admission.NewAttributesRecord(obj, kind, namespace, scope.Resource, "UPDATE")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment