-
Notifications
You must be signed in to change notification settings - Fork 6
/
certs.go
52 lines (38 loc) · 1.3 KB
/
certs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright (c) 2020 Entrust Datacard Corporation.
* All rights reserved.
*/
package main
import (
"context"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
func opListCerts(ctx context.Context, req *logical.Request, data *framework.FieldData, path string) (response *logical.Response, retErr error) {
roleName := data.Get("roleName").(string)
entries, err := req.Storage.List(ctx, path+"/"+roleName+"/")
if err != nil {
return nil, err
}
return logical.ListResponse(entries), nil
}
func opReadCert(ctx context.Context, req *logical.Request, data *framework.FieldData, path string) (*logical.Response, error) {
roleName := data.Get("roleName").(string)
serial := data.Get("serial").(string)
storageEntry, err := req.Storage.Get(ctx, path+"/"+roleName+"/"+serial)
if err != nil {
return logical.ErrorResponse("could not read certificate with the serial number: " + serial), err
}
if storageEntry == nil {
return logical.ErrorResponse("could not find certificate with the serial number: " + serial), nil
}
var rawData map[string]interface{}
err = storageEntry.DecodeJSON(&rawData)
if err != nil {
return logical.ErrorResponse("json decoding failed for certificate: " + serial), err
}
resp := &logical.Response{
Data: rawData,
}
return resp, nil
}