Extend the API with a function which updates the client configuration

This commit is contained in:
Cosmin Cojocar
2018-08-08 17:21:02 +02:00
parent 57b1031352
commit 9926a0dced
3 changed files with 233 additions and 68 deletions

View File

@@ -80,6 +80,38 @@ func (d dexAPI) CreateClient(ctx context.Context, req *api.CreateClientReq) (*ap
}, nil
}
func (d dexAPI) UpdateClient(ctx context.Context, req *api.UpdateClientReq) (*api.UpdateClientResp, error) {
if req.Id == "" {
return nil, errors.New("update client: no client ID supplied")
}
err := d.s.UpdateClient(req.Id, func(old storage.Client) (storage.Client, error) {
if req.RedirectUris != nil && len(req.RedirectUris) > 0 {
old.RedirectURIs = req.RedirectUris
}
if req.TrustedPeers != nil && len(req.TrustedPeers) > 0 {
old.TrustedPeers = req.TrustedPeers
}
old.Public = req.Public
if req.Name != "" {
old.Name = req.Name
}
if req.LogoUrl != "" {
old.LogoURL = req.LogoUrl
}
return old, nil
})
if err != nil {
if err == storage.ErrNotFound {
return &api.UpdateClientResp{NotFound: true}, nil
}
d.logger.Errorf("api: failed to update the client: %v", err)
return nil, fmt.Errorf("update client: %v", err)
}
return &api.UpdateClientResp{}, nil
}
func (d dexAPI) DeleteClient(ctx context.Context, req *api.DeleteClientReq) (*api.DeleteClientResp, error) {
err := d.s.DeleteClient(req.Id)
if err != nil {