fix(http): Return an empty array if organization has no secret keys (#15363)
* fix(http): Return an empty array if organization has no secret keys * fix(http): Return an empty array if organization has no secret keys instead nilpull/16137/head
parent
01452752ec
commit
f25fe8c5a2
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
bolt "github.com/coreos/bbolt"
|
||||
influxdb "github.com/influxdata/influxdb"
|
||||
|
@ -103,7 +102,10 @@ func (c *Client) getSecretKeys(ctx context.Context, tx *bolt.Tx, orgID influxdb.
|
|||
}
|
||||
|
||||
if id != orgID {
|
||||
return nil, fmt.Errorf("organization has no secret keys")
|
||||
return []string{}, &influxdb.Error{
|
||||
Code: influxdb.ENotFound,
|
||||
Msg: "organization has no secret keys",
|
||||
}
|
||||
}
|
||||
|
||||
keys := []string{key}
|
||||
|
|
|
@ -462,7 +462,7 @@ func (h *OrgHandler) handleGetSecrets(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
ks, err := h.SecretService.GetSecretKeys(ctx, req.orgID)
|
||||
if err != nil {
|
||||
if err != nil && influxdb.ErrorCode(err) != influxdb.ENotFound {
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -144,6 +144,36 @@ func TestSecretService_handleGetSecrets(t *testing.T) {
|
|||
},
|
||||
"secrets": []
|
||||
}
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "get secrets when organization has no secret keys",
|
||||
fields: fields{
|
||||
&mock.SecretService{
|
||||
GetSecretKeysFn: func(ctx context.Context, orgID platform.ID) ([]string, error) {
|
||||
return []string{}, &platform.Error{
|
||||
Code: platform.ENotFound,
|
||||
Msg: "organization has no secret keys",
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
},
|
||||
args: args{
|
||||
orgID: 1,
|
||||
},
|
||||
wants: wants{
|
||||
statusCode: http.StatusOK,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
body: `
|
||||
{
|
||||
"links": {
|
||||
"org": "/api/v2/orgs/0000000000000001",
|
||||
"self": "/api/v2/orgs/0000000000000001/secrets"
|
||||
},
|
||||
"secrets": []
|
||||
}
|
||||
`,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/influxdata/influxdb"
|
||||
)
|
||||
|
@ -120,7 +119,10 @@ func (s *Service) getSecretKeys(ctx context.Context, tx Tx, orgID influxdb.ID) (
|
|||
}
|
||||
|
||||
if id != orgID {
|
||||
return nil, fmt.Errorf("organization has no secret keys")
|
||||
return []string{}, &influxdb.Error{
|
||||
Code: influxdb.ENotFound,
|
||||
Msg: "organization has no secret keys",
|
||||
}
|
||||
}
|
||||
|
||||
keys := []string{key}
|
||||
|
|
Loading…
Reference in New Issue