Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
keystore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
id
keystore
Commits
f4dec10e
Commit
f4dec10e
authored
5 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Use a response field instead of a 404 when no keys are found
This makes it easier to detect unexpected errors.
parent
9f1f2da0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
client/client.go
+12
-3
12 additions, 3 deletions
client/client.go
protocol.go
+2
-1
2 additions, 1 deletion
protocol.go
server/server.go
+9
-5
9 additions, 5 deletions
server/server.go
with
23 additions
and
9 deletions
client/client.go
+
12
−
3
View file @
f4dec10e
...
...
@@ -2,12 +2,16 @@ package client
import
(
"context"
"errors"
"git.autistici.org/ai3/go-common/clientutil"
"git.autistici.org/id/keystore"
)
// ErrNoKeys indicates that the user has no encryption keys.
var
ErrNoKeys
=
errors
.
New
(
"no keys available"
)
// Client for the keystore API.
type
Client
interface
{
Open
(
context
.
Context
,
string
,
string
,
string
,
int
)
error
...
...
@@ -19,9 +23,8 @@ type ksClient struct {
be
clientutil
.
Backend
}
// New returns a new Client with the given Config. Use this when the
// keystore service runs on a single global instance.
func
New
(
config
*
clientutil
.
BackendConfig
)
(
*
ksClient
,
error
)
{
// New returns a new Client with the given backend Config.
func
New
(
config
*
clientutil
.
BackendConfig
)
(
Client
,
error
)
{
be
,
err
:=
clientutil
.
NewBackend
(
config
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -46,6 +49,12 @@ func (c *ksClient) Get(ctx context.Context, shard, username, ssoTicket string) (
}
var
resp
keystore
.
GetResponse
err
:=
c
.
be
.
Call
(
ctx
,
shard
,
"/api/get_key"
,
&
req
,
&
resp
)
if
err
!=
nil
{
return
nil
,
err
}
if
!
resp
.
HasKey
{
return
nil
,
ErrNoKeys
}
return
resp
.
Key
,
err
}
...
...
This diff is collapsed.
Click to expand it.
protocol.go
+
2
−
1
View file @
f4dec10e
...
...
@@ -14,7 +14,8 @@ type GetRequest struct {
}
type
GetResponse
struct
{
Key
[]
byte
`json:"key"`
HasKey
bool
`json:"has_key"`
Key
[]
byte
`json:"key"`
}
type
CloseRequest
struct
{
...
...
This diff is collapsed.
Click to expand it.
server/server.go
+
9
−
5
View file @
f4dec10e
...
...
@@ -41,22 +41,26 @@ func (s *keyStoreServer) handleGet(w http.ResponseWriter, r *http.Request) {
return
}
var
resp
keystore
.
GetResponse
key
,
err
:=
s
.
KeyStore
.
Get
(
req
.
Username
,
req
.
SSOTicket
)
if
err
!=
nil
{
log
.
Printf
(
"Get(%s) error: %v"
,
req
.
Username
,
err
)
if
err
==
errNoKeys
{
log
.
Printf
(
"no keys for %s"
,
req
.
Username
)
}
else
if
err
!=
nil
{
// Return an appropriate error code.
switch
err
{
case
errUnauthorized
,
errBadUser
:
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusForbidden
)
case
errNoKeys
:
http
.
NotFound
(
w
,
r
)
default
:
log
.
Printf
(
"Get(%s) error: %v"
,
req
.
Username
,
err
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
}
return
}
else
{
resp
.
HasKey
=
true
resp
.
Key
=
key
}
serverutil
.
EncodeJSONResponse
(
w
,
&
keystore
.
GetResponse
{
Key
:
key
}
)
serverutil
.
EncodeJSONResponse
(
w
,
&
resp
)
}
func
(
s
*
keyStoreServer
)
handleClose
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment