Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k8s-crt-dnldr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
k8s
k8s-crt-dnldr
Commits
ca52e7ff
Commit
ca52e7ff
authored
Jul 24, 2020
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
REST API error response body on Not Found for DELETE.
parent
c80e65e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
8 deletions
+46
-8
handlers.go
pkg/rest/handlers.go
+10
-2
handlers_test.go
pkg/rest/handlers_test.go
+36
-6
No files found.
pkg/rest/handlers.go
View file @
ca52e7ff
...
...
@@ -31,6 +31,7 @@ package rest
import
(
"encoding/json"
"net/http"
"os"
"regexp"
"strconv"
"strings"
...
...
@@ -83,6 +84,11 @@ var (
Detail
:
"/v1/pems/ URL path does not match "
+
"/v1/pems/{namespace}/{name}"
,
}
errPemDeleteNotFound
=
ErrorDetails
{
Type
:
"/errors/pems/delete/notFound"
,
Title
:
"PEM file to be deleted not found"
,
Detail
:
""
,
}
)
// Problem Details object per RFC7807
...
...
@@ -238,8 +244,10 @@ func (h *pemsHndlr) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
ns
,
name
:=
matches
[
1
],
matches
[
2
]
if
req
.
Method
==
http
.
MethodDelete
{
if
exist
,
err
:=
h
.
files
.
Delete
(
ns
,
name
);
!
exist
{
status
=
http
.
StatusNotFound
if
exist
,
err
:=
h
.
files
.
Delete
(
ns
,
name
);
!
exist
||
(
err
!=
nil
&&
os
.
IsNotExist
(
err
))
{
h
.
errorResponse
(
resp
,
req
,
now
,
http
.
StatusNotFound
,
errPemDeleteNotFound
,
err
)
}
else
if
err
!=
nil
{
// XXX problem description in body
status
=
http
.
StatusInternalServerError
...
...
pkg/rest/handlers_test.go
View file @
ca52e7ff
...
...
@@ -53,6 +53,8 @@ import (
"k8s.io/client-go/tools/cache"
)
var
errInstancePattern
=
regexp
.
MustCompile
(
`^/log/errors/\d+$`
)
func
TestHealthz
(
t
*
testing
.
T
)
{
version
:=
"47.11"
hndlr
:=
&
healthzHndlr
{
...
...
@@ -656,10 +658,40 @@ func TestDeletePem(t *testing.T) {
t
.
Errorf
(
"2nd DELETE /v1/pems/ns1/secret1 status: "
+
"got %d want %d"
,
rr
.
Code
,
http
.
StatusNotFound
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
)
!=
"0"
{
t
.
Errorf
(
"DELETE /v1/pems/ns1/secret1 Content-Length: "
+
"got %s want 0"
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
))
if
rr
.
Header
()
.
Get
(
"Content-Type"
)
!=
problemContentType
{
t
.
Errorf
(
"2nd DELETE /v1/pems/ns1/secret1 Content-Type: "
+
"got %s want %s"
,
rr
.
Header
()
.
Get
(
"Content-Type"
),
problemContentType
)
}
bodylen
:=
len
(
rr
.
Body
.
String
())
if
rr
.
Header
()
.
Get
(
"Content-Length"
)
!=
strconv
.
Itoa
(
bodylen
)
{
t
.
Errorf
(
"2nd DELETE /v1/pems/ns1/secret1 Content-Length: "
+
"got %s want %d"
,
rr
.
Header
()
.
Get
(
"Content-Length"
),
bodylen
)
}
problem
:=
&
Problem
{}
if
err
=
json
.
Unmarshal
(
rr
.
Body
.
Bytes
(),
problem
);
err
!=
nil
{
t
.
Fatalf
(
"2nd DELETE /v1/pems/ns1/secret1 body unmarshal: %v"
,
err
)
}
if
problem
.
Type
!=
errPemDeleteNotFound
.
Type
{
t
.
Errorf
(
"2nd DELETE /v1/pems/ns1/secret1 problem type: "
+
"got %s want %s"
,
problem
.
Type
,
errPemDeleteNotFound
.
Type
)
}
if
problem
.
Title
!=
errPemDeleteNotFound
.
Title
{
t
.
Errorf
(
"2nd DELETE /v1/pems/ns1/secret1 problem title: "
+
"got %s want %s"
,
problem
.
Title
,
errPemDeleteNotFound
.
Title
)
}
if
problem
.
Status
!=
http
.
StatusNotFound
{
t
.
Errorf
(
"2nd DELETE /v1/pems/ns1/secret1 problem status: "
+
"got %d want %d"
,
problem
.
Status
,
http
.
StatusNotFound
)
}
if
!
errInstancePattern
.
Match
([]
byte
(
problem
.
Instance
))
{
t
.
Errorf
(
"2nd DELETE /v1/pems/ns1/secret1 problem instance: "
+
"got %s want /log/errors/N"
,
problem
.
Instance
)
}
req
=
httptest
.
NewRequest
(
http
.
MethodDelete
,
"/v1/pems/foo/bar"
,
nil
)
...
...
@@ -817,8 +849,6 @@ func TestAllPem(t *testing.T) {
}
}
var
errInstancePattern
=
regexp
.
MustCompile
(
`^/log/errors/\d+$`
)
func
TestErrors
(
t
*
testing
.
T
)
{
client
:=
fake
.
NewSimpleClientset
()
lister
:=
setupSecretLister
(
client
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment