Skip to content

Commit

Permalink
NOISSUE - Fix cert response (#19)
Browse files Browse the repository at this point in the history
* Remove cert and key field in cert response

Signed-off-by: nyagamunene <[email protected]>

* Pointer to cert and key response

Signed-off-by: nyagamunene <[email protected]>

* Fix linter

Signed-off-by: nyagamunene <[email protected]>

* Fix list with entity id

Signed-off-by: nyagamunene <[email protected]>

---------

Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene authored Sep 20, 2024
1 parent f5485e8 commit 358bd11
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
19 changes: 14 additions & 5 deletions api/http/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,21 @@ func listCertsEndpoint(svc certs.Service) endpoint.Endpoint {
return listCertsRes{}, err
}

var crts []viewCertRes
for _, c := range certPage.Certificates {
crts = append(crts, viewCertRes{
SerialNumber: c.SerialNumber,
Revoked: c.Revoked,
EntityID: c.EntityID,
ExpiryTime: c.ExpiryTime,
})
}

return listCertsRes{
Total: certPage.Total,
Offset: certPage.Offset,
Limit: certPage.Limit,
Certificates: certPage.Certificates,
Certificates: crts,
}, nil
}
}
Expand All @@ -131,12 +141,11 @@ func viewCertEndpoint(svc certs.Service) endpoint.Endpoint {
if err != nil {
return viewCertRes{}, err
}
crt := string(cert.Certificate)
key := string(cert.Key)

return viewCertRes{
SerialNumber: cert.SerialNumber,
Certificate: &crt,
Key: &key,
Certificate: string(cert.Certificate),
Key: string(cert.Key),
Revoked: cert.Revoked,
ExpiryTime: cert.ExpiryTime,
EntityID: cert.EntityID,
Expand Down
13 changes: 6 additions & 7 deletions api/http/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"time"

"github.com/absmach/certs"
"golang.org/x/crypto/ocsp"
)

Expand Down Expand Up @@ -122,10 +121,10 @@ func (res issueCertRes) Empty() bool {
}

type listCertsRes struct {
Total uint64 `json:"total"`
Offset uint64 `json:"offset"`
Limit uint64 `json:"limit"`
Certificates []certs.Certificate `json:"certificates"`
Total uint64 `json:"total"`
Offset uint64 `json:"offset"`
Limit uint64 `json:"limit"`
Certificates []viewCertRes `json:"certificates"`
}

func (res listCertsRes) Code() int {
Expand All @@ -138,8 +137,8 @@ func (res listCertsRes) Headers() map[string]string {

type viewCertRes struct {
SerialNumber string `json:"serial_number"`
Certificate *string `json:"certificate"`
Key *string `json:"key"`
Certificate string `json:"certificate"`
Key string `json:"key"`
Revoked bool `json:"revoked"`
ExpiryTime time.Time `json:"expiry_time"`
EntityID string `json:"entity_id"`
Expand Down
16 changes: 8 additions & 8 deletions certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import (
)

type Certificate struct {
SerialNumber string `json:"serial_number" db:"serial_number"`
Certificate []byte `json:"certificate" db:"certificate"`
Key []byte `json:"key" db:"key"`
Revoked bool `json:"revoked" db:"revoked"`
ExpiryTime time.Time `json:"expiry_time" db:"expiry_time"`
EntityID string `json:"entity_id" db:"entity_id"`
DownloadUrl string `json:"-" db:"-"`
SerialNumber string `db:"serial_number"`
Certificate []byte `db:"certificate"`
Key []byte `db:"key"`
Revoked bool `db:"revoked"`
ExpiryTime time.Time `db:"expiry_time"`
EntityID string `db:"entity_id"`
DownloadUrl string `db:"-"`
}

type CertificatePage struct {
PageMetadata
Certificates []Certificate `json:"certificates"`
Certificates []Certificate
}

type PageMetadata struct {
Expand Down
7 changes: 5 additions & 2 deletions sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type Token struct {

type Certificate struct {
SerialNumber string `json:"serial_number"`
Certificate *string `json:"certificate,omitempty"`
Key *string `json:"key,omitempty"`
Certificate string `json:"certificate,omitempty"`
Key string `json:"key,omitempty"`
Revoked bool `json:"revoked"`
ExpiryTime time.Time `json:"expiry_time"`
EntityID string `json:"entity_id"`
Expand Down Expand Up @@ -336,6 +336,9 @@ func (pm PageMetadata) query() (string, error) {
if pm.Total != 0 {
q.Add("total", strconv.FormatUint(pm.Total, 10))
}
if pm.EntityID != "" {
q.Add("entity_id", pm.EntityID)
}
if pm.Token != "" {
q.Add("token", pm.Token)
}
Expand Down

0 comments on commit 358bd11

Please sign in to comment.