Skip to content

Commit eb1d7b7

Browse files
committed
refactor.
1 parent d1eedf3 commit eb1d7b7

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

service/policy/keymanagement/platform_key_indexer.go renamed to service/kas/key_indexer.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package keymanagement
1+
package kas
22

33
import (
44
"context"
@@ -21,7 +21,7 @@ import (
2121
var ErrNoActiveKeyForAlgorithm = errors.New("no active key found for specified algorithm")
2222

2323
// Used for reaching out to platform to get keys
24-
type PlatformKeyIndexer struct {
24+
type KeyIndexer struct {
2525
// SDK is the SDK instance used to interact with the platform
2626
sdk *sdk.SDK
2727
// KasURI
@@ -31,13 +31,13 @@ type PlatformKeyIndexer struct {
3131
}
3232

3333
// platformKeyAdapter is an adapter for KeyDetails, where keys come from the platform
34-
type KasKeyAdapter struct {
34+
type KeyAdapter struct {
3535
key *policy.KasKey
3636
log *logger.Logger
3737
}
3838

39-
func NewPlatformKeyIndexer(sdk *sdk.SDK, kasURI string, l *logger.Logger) *PlatformKeyIndexer {
40-
return &PlatformKeyIndexer{
39+
func NewPlatformKeyIndexer(sdk *sdk.SDK, kasURI string, l *logger.Logger) *KeyIndexer {
40+
return &KeyIndexer{
4141
sdk: sdk,
4242
kasURI: kasURI,
4343
log: l,
@@ -61,7 +61,7 @@ func convertAlgToEnum(alg string) (policy.Algorithm, error) {
6161
}
6262
}
6363

64-
func (p *PlatformKeyIndexer) FindKeyByAlgorithm(ctx context.Context, algorithm string, _ bool) (trust.KeyDetails, error) {
64+
func (p *KeyIndexer) FindKeyByAlgorithm(ctx context.Context, algorithm string, _ bool) (trust.KeyDetails, error) {
6565
alg, err := convertAlgToEnum(algorithm)
6666
if err != nil {
6767
return nil, err
@@ -90,13 +90,13 @@ func (p *PlatformKeyIndexer) FindKeyByAlgorithm(ctx context.Context, algorithm s
9090
return nil, ErrNoActiveKeyForAlgorithm
9191
}
9292

93-
return &KasKeyAdapter{
93+
return &KeyAdapter{
9494
key: activeKey,
9595
log: p.log,
9696
}, nil
9797
}
9898

99-
func (p *PlatformKeyIndexer) FindKeyByID(ctx context.Context, id trust.KeyIdentifier) (trust.KeyDetails, error) {
99+
func (p *KeyIndexer) FindKeyByID(ctx context.Context, id trust.KeyIdentifier) (trust.KeyDetails, error) {
100100
req := &kasregistry.GetKeyRequest{
101101
Identifier: &kasregistry.GetKeyRequest_Key{
102102
Key: &kasregistry.KasKeyIdentifier{
@@ -113,13 +113,13 @@ func (p *PlatformKeyIndexer) FindKeyByID(ctx context.Context, id trust.KeyIdenti
113113
return nil, err
114114
}
115115

116-
return &KasKeyAdapter{
116+
return &KeyAdapter{
117117
key: resp.GetKasKey(),
118118
log: p.log,
119119
}, nil
120120
}
121121

122-
func (p *PlatformKeyIndexer) ListKeys(ctx context.Context) ([]trust.KeyDetails, error) {
122+
func (p *KeyIndexer) ListKeys(ctx context.Context) ([]trust.KeyDetails, error) {
123123
req := &kasregistry.ListKeysRequest{
124124
KasFilter: &kasregistry.ListKeysRequest_KasUri{
125125
KasUri: p.kasURI,
@@ -132,7 +132,7 @@ func (p *PlatformKeyIndexer) ListKeys(ctx context.Context) ([]trust.KeyDetails,
132132

133133
keys := make([]trust.KeyDetails, len(resp.GetKasKeys()))
134134
for i, key := range resp.GetKasKeys() {
135-
keys[i] = &KasKeyAdapter{
135+
keys[i] = &KeyAdapter{
136136
key: key,
137137
log: p.log,
138138
}
@@ -141,21 +141,21 @@ func (p *PlatformKeyIndexer) ListKeys(ctx context.Context) ([]trust.KeyDetails,
141141
return keys, nil
142142
}
143143

144-
func (p *KasKeyAdapter) ID() trust.KeyIdentifier {
144+
func (p *KeyAdapter) ID() trust.KeyIdentifier {
145145
return trust.KeyIdentifier(p.key.GetKey().GetKeyId())
146146
}
147147

148148
// Might need to convert this to a standard format
149-
func (p *KasKeyAdapter) Algorithm() string {
149+
func (p *KeyAdapter) Algorithm() string {
150150
return p.key.GetKey().GetKeyAlgorithm().String()
151151
}
152152

153-
func (p *KasKeyAdapter) IsLegacy() bool {
153+
func (p *KeyAdapter) IsLegacy() bool {
154154
return false
155155
}
156156

157157
// This will point to the correct "manager"
158-
func (p *KasKeyAdapter) System() string {
158+
func (p *KeyAdapter) System() string {
159159
var mode string
160160
if p.key.GetKey().GetProviderConfig() != nil {
161161
mode = p.key.GetKey().GetProviderConfig().GetName()
@@ -211,7 +211,7 @@ func convertPEMToJWK(_ string) (string, error) {
211211
return "", errors.New("convertPEMToJWK function is not implemented")
212212
}
213213

214-
func (p *KasKeyAdapter) ExportPublicKey(ctx context.Context, format trust.KeyType) (string, error) {
214+
func (p *KeyAdapter) ExportPublicKey(ctx context.Context, format trust.KeyType) (string, error) {
215215
publicKeyCtx := p.key.GetKey().GetPublicKeyCtx()
216216

217217
// Decode the base64-encoded public key
@@ -241,6 +241,6 @@ func (p *KasKeyAdapter) ExportPublicKey(ctx context.Context, format trust.KeyTyp
241241
}
242242
}
243243

244-
func (p *KasKeyAdapter) ExportCertificate(_ context.Context) (string, error) {
244+
func (p *KeyAdapter) ExportCertificate(_ context.Context) (string, error) {
245245
return "", errors.New("not implemented")
246246
}

service/policy/keymanagement/platform_key_indexer_test.go renamed to service/kas/key_indexer_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package keymanagement
1+
package kas
22

33
import (
44
"context"
@@ -11,21 +11,21 @@ import (
1111
"github.com/stretchr/testify/suite"
1212
)
1313

14-
type PlatformKeyIndexTestSuite struct {
14+
type KeyIndexTestSuite struct {
1515
suite.Suite
1616
rsaKey trust.KeyDetails
1717
}
1818

19-
func (s *PlatformKeyIndexTestSuite) SetupTest() {
20-
s.rsaKey = &KasKeyAdapter{
19+
func (s *KeyIndexTestSuite) SetupTest() {
20+
s.rsaKey = &KeyAdapter{
2121
key: &policy.KasKey{
2222
KasId: "test-kas-id",
2323
Key: &policy.AsymmetricKey{
2424
Id: "test-id",
2525
KeyId: "test-key-id",
2626
KeyAlgorithm: policy.Algorithm_ALGORITHM_RSA_2048,
2727
KeyStatus: policy.KeyStatus_KEY_STATUS_ACTIVE,
28-
KeyMode: policy.KeyMode_KEY_MODE_LOCAL,
28+
KeyMode: policy.KeyMode_KEY_MODE_CONFIG_ROOT_KEY,
2929
PublicKeyCtx: &policy.KasPublicKeyCtx{
3030
Pem: "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUF3SEw0TkVrOFpDa0JzNjZXQVpWagpIS3NseDRseWdmaXN3aW42RUx5OU9OczZLVDRYa1crRGxsdExtck14bHZkbzVRaDg1UmFZS01mWUdDTWtPM0dGCkFsK0JOeWFOM1kwa0N1QjNPU2ErTzdyMURhNVZteVVuaEJNbFBrYnVPY1Y0cjlLMUhOSGd3eDl2UFp3RjRpQW8KQStEY1VBcWFEeHlvYjV6enNGZ0hUNjJHLzdLdEtiZ2hYT1dCanRUYUl1ZHpsK2FaSjFPemY0U1RkOXhST2QrMQordVo2VG1ocmFEUm9zdDUrTTZUN0toL2lGWk40TTFUY2hwWXU1TDhKR2tVaG9YaEdZcHUrMGczSzlqYlh6RVh5CnpJU3VXN2d6SGRWYUxvcnBkQlNkRHpOWkNvTFVoL0U1T3d5TFZFQkNKaDZJVUtvdWJ5WHVucnIxQnJmK2tLbEsKeHdJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==",
3131
},
@@ -37,16 +37,16 @@ func (s *PlatformKeyIndexTestSuite) SetupTest() {
3737
},
3838
}
3939
}
40-
func (s *PlatformKeyIndexTestSuite) TearDownTest() {}
40+
func (s *KeyIndexTestSuite) TearDownTest() {}
4141

42-
func (s *PlatformKeyIndexTestSuite) TestKeyDetails() {
42+
func (s *KeyIndexTestSuite) TestKeyDetails() {
4343
s.Equal("test-key-id", string(s.rsaKey.ID()))
4444
s.Equal("ALGORITHM_RSA_2048", s.rsaKey.Algorithm())
4545
s.False(s.rsaKey.IsLegacy())
4646
s.Equal("openbao", s.rsaKey.System())
4747
}
4848

49-
func (s *PlatformKeyIndexTestSuite) TestKeyExportPublicKey_JWKFormat() {
49+
func (s *KeyIndexTestSuite) TestKeyExportPublicKey_JWKFormat() {
5050
// Export JWK format
5151
jwkString, err := s.rsaKey.ExportPublicKey(context.Background(), trust.KeyTypeJWK)
5252
s.Require().NoError(err)
@@ -57,13 +57,13 @@ func (s *PlatformKeyIndexTestSuite) TestKeyExportPublicKey_JWKFormat() {
5757
s.Require().NotNil(rsaKey)
5858
}
5959

60-
func (s *PlatformKeyIndexTestSuite) TestKeyExportPublicKey_PKCSFormat() {
60+
func (s *KeyIndexTestSuite) TestKeyExportPublicKey_PKCSFormat() {
6161
// Export JWK format
6262
pem, err := s.rsaKey.ExportPublicKey(context.Background(), trust.KeyTypePKCS8)
6363
s.Require().NoError(err)
6464
s.Require().NotEmpty(pem)
6565

66-
keyAdapter, ok := s.rsaKey.(*KasKeyAdapter)
66+
keyAdapter, ok := s.rsaKey.(*KeyAdapter)
6767
s.Require().True(ok)
6868
pubCtx := keyAdapter.key.GetKey().GetPublicKeyCtx()
6969
s.Require().NotEmpty(pubCtx)
@@ -72,5 +72,5 @@ func (s *PlatformKeyIndexTestSuite) TestKeyExportPublicKey_PKCSFormat() {
7272
}
7373

7474
func TestNewPlatformKeyIndexTestSuite(t *testing.T) {
75-
suite.Run(t, new(PlatformKeyIndexTestSuite))
75+
suite.Run(t, new(KeyIndexTestSuite))
7676
}

0 commit comments

Comments
 (0)