From 61a70339a190670a72375dc152cb1b9a827517d5 Mon Sep 17 00:00:00 2001 From: Nicolae Nicora Date: Sat, 7 Feb 2026 16:55:34 +0100 Subject: [PATCH 1/9] fix: add missed service apis that wrapping the grpc implementation --- .../certificateissuer/certificate_issuer.go | 42 +++ .../identitymanagement/identity_management.go | 73 +++++ api/service/keystore/common.go | 5 + api/service/keystore/keystore_management.go | 27 ++ api/service/keystore/keystore_operations.go | 165 +++++++++++ api/service/notification/notification.go | 30 ++ api/service/registry.go | 66 +++++ .../systeminformation/system_information.go | 26 ++ pkg/catalog/builtin.go | 8 +- pkg/catalog/builtin_registry.go | 14 +- pkg/catalog/builtin_registry_test.go | 10 +- pkg/catalog/catalog.go | 8 +- pkg/plugin/service/certificate_issuer_v1.go | 58 ++++ pkg/plugin/service/hashicorp_registry.go | 18 ++ .../hashicorp_registry_certificate_issuer.go | 44 +++ .../hashicorp_registry_identity_management.go | 44 +++ .../hashicorp_registry_keystore_management.go | 44 +++ .../hashicorp_registry_keystore_operations.go | 44 +++ .../hashicorp_registry_notification.go | 44 +++ .../hashicorp_registry_system_information.go | 44 +++ pkg/plugin/service/identity_management_v1.go | 124 +++++++++ pkg/plugin/service/keystore_management_v1.go | 67 +++++ pkg/plugin/service/keystore_operations_v1.go | 256 ++++++++++++++++++ pkg/plugin/service/notification_v1.go | 40 +++ pkg/plugin/service/system_information_v1.go | 37 +++ 25 files changed, 1318 insertions(+), 20 deletions(-) create mode 100644 api/service/certificateissuer/certificate_issuer.go create mode 100644 api/service/identitymanagement/identity_management.go create mode 100644 api/service/keystore/common.go create mode 100644 api/service/keystore/keystore_management.go create mode 100644 api/service/keystore/keystore_operations.go create mode 100644 api/service/notification/notification.go create mode 100644 api/service/registry.go create mode 100644 api/service/systeminformation/system_information.go create mode 100644 pkg/plugin/service/certificate_issuer_v1.go create mode 100644 pkg/plugin/service/hashicorp_registry.go create mode 100644 pkg/plugin/service/hashicorp_registry_certificate_issuer.go create mode 100644 pkg/plugin/service/hashicorp_registry_identity_management.go create mode 100644 pkg/plugin/service/hashicorp_registry_keystore_management.go create mode 100644 pkg/plugin/service/hashicorp_registry_keystore_operations.go create mode 100644 pkg/plugin/service/hashicorp_registry_notification.go create mode 100644 pkg/plugin/service/hashicorp_registry_system_information.go create mode 100644 pkg/plugin/service/identity_management_v1.go create mode 100644 pkg/plugin/service/keystore_management_v1.go create mode 100644 pkg/plugin/service/keystore_operations_v1.go create mode 100644 pkg/plugin/service/notification_v1.go create mode 100644 pkg/plugin/service/system_information_v1.go diff --git a/api/service/certificateissuer/certificate_issuer.go b/api/service/certificateissuer/certificate_issuer.go new file mode 100644 index 0000000..6c44326 --- /dev/null +++ b/api/service/certificateissuer/certificate_issuer.go @@ -0,0 +1,42 @@ +package certificateissuer + +import ( + "context" +) + +type CertificateIssuer interface { + GetCertificate(ctx context.Context, req *GetCertificateRequest) (*GetCertificateResponse, error) +} + +type ValidityType int32 + +const ( + Unspecified ValidityType = iota + Days + Months + Years +) + +type GetCertificateRequest struct { + // V1 Fields + CommonName string + Localities []string + Validity *CertificateValidity + PrivateKey *CertificatePrivateKey +} + +type GetCertificateResponse struct { + // V1 Fields + ChainPem string +} + +type CertificateValidity struct { + // V1 Fields + Value int64 + Type ValidityType +} + +type CertificatePrivateKey struct { + // V1 Fields + Data []byte +} diff --git a/api/service/identitymanagement/identity_management.go b/api/service/identitymanagement/identity_management.go new file mode 100644 index 0000000..5e3952d --- /dev/null +++ b/api/service/identitymanagement/identity_management.go @@ -0,0 +1,73 @@ +package identitymanagement + +import ( + "context" +) + +type IdentityManagement interface { + GetGroup(ctx context.Context, req *GetGroupRequest) (*GetGroupResponse, error) + GetAllGroups(ctx context.Context, req *GetAllGroupsRequest) (*GetAllGroupsResponse, error) + GetUsersForGroup(ctx context.Context, req *GetUsersForGroupRequest) (*GetUsersForGroupResponse, error) + GetGroupsForUser(ctx context.Context, req *GetGroupsForUserRequest) (*GetGroupsForUserResponse, error) +} + +type AuthContext struct { + // V1 Fields + Data map[string]string +} + +type GetGroupRequest struct { + // V1 Fields + GroupName string + AuthContext AuthContext +} + +type GetGroupResponse struct { + // V1 Fields + Group Group +} + +type GetAllGroupsRequest struct { + // V1 Fields + AuthContext AuthContext +} + +type GetAllGroupsResponse struct { + // V1 Fields + Groups []Group +} + +type GetUsersForGroupRequest struct { + // V1 Fields + GroupID string + AuthContext AuthContext +} + +type GetUsersForGroupResponse struct { + // V1 Fields + Users []User +} + +type User struct { + // V1 Fields + ID string + Name string + Email string +} + +type GetGroupsForUserRequest struct { + // V1 Fields + UserID string + AuthContext AuthContext +} + +type GetGroupsForUserResponse struct { + // V1 Fields + Groups []Group +} + +type Group struct { + // V1 Fields + ID string + Name string +} diff --git a/api/service/keystore/common.go b/api/service/keystore/common.go new file mode 100644 index 0000000..8fdebaa --- /dev/null +++ b/api/service/keystore/common.go @@ -0,0 +1,5 @@ +package keystore + +type KeystoreInstanceConfig struct { + Values map[string]any +} diff --git a/api/service/keystore/keystore_management.go b/api/service/keystore/keystore_management.go new file mode 100644 index 0000000..9e41c49 --- /dev/null +++ b/api/service/keystore/keystore_management.go @@ -0,0 +1,27 @@ +package keystore + +import ( + "context" +) + +type KeystoreManagement interface { + CreateKeystore(ctx context.Context, req *CreateKeystoreRequest) (*CreateKeystoreResponse, error) + DeleteKeystore(ctx context.Context, req *DeleteKeystoreRequest) (*DeleteKeystoreResponse, error) +} + +type CreateKeystoreRequest struct { + // V1 Fields + Values map[string]any +} + +type CreateKeystoreResponse struct { + // V1 Fields + Config KeystoreInstanceConfig +} + +type DeleteKeystoreRequest struct { + // V1 Fields + Config KeystoreInstanceConfig +} + +type DeleteKeystoreResponse struct{} diff --git a/api/service/keystore/keystore_operations.go b/api/service/keystore/keystore_operations.go new file mode 100644 index 0000000..183e44f --- /dev/null +++ b/api/service/keystore/keystore_operations.go @@ -0,0 +1,165 @@ +package keystore + +import ( + "context" +) + +type KeystoreOperations interface { + GetKey(ctx context.Context, req *GetKeyRequest) (*GetKeyResponse, error) + CreateKey(ctx context.Context, req *CreateKeyRequest) (*CreateKeyResponse, error) + DeleteKey(ctx context.Context, req *DeleteKeyRequest) (*DeleteKeyResponse, error) + EnableKey(ctx context.Context, req *EnableKeyRequest) (*EnableKeyResponse, error) + GetImportParameters(ctx context.Context, req *GetImportParametersRequest) (*GetImportParametersResponse, error) + ImportKeyMaterial(ctx context.Context, req *ImportKeyMaterialRequest) (*ImportKeyMaterialResponse, error) + ValidateKey(ctx context.Context, req *ValidateKeyRequest) (*ValidateKeyResponse, error) + ValidateKeyAccessData(ctx context.Context, req *ValidateKeyAccessDataRequest) (*ValidateKeyAccessDataResponse, error) + TransformCryptoAccessData(ctx context.Context, req *TransformCryptoAccessDataRequest) (*TransformCryptoAccessDataResponse, error) + ExtractKeyRegion(ctx context.Context, req *ExtractKeyRegionRequest) (*ExtractKeyRegionResponse, error) +} + +type KeyAlgorithm int32 + +const ( + UnspecifiedKeyAlgorithm KeyAlgorithm = iota + AES256KeyAlgorithm + RSA3072KeyAlgorithm + RSA4096KeyAlgorithm +) + +type KeyType int32 + +const ( + UnspecifiedKeyType KeyType = iota + SystemManaged + BYOK + HYOK +) + +type RequestParameters struct { + // V1 Fields + Config KeystoreInstanceConfig + KeyID string +} + +type GetKeyRequest struct { + // V1 Fields + Parameters RequestParameters +} + +type GetKeyResponse struct { + // V1 Fields + KeyID string + KeyAlgorithm KeyAlgorithm + Status string + Usage string +} + +// CreateKeyRequest contains parameters for key creation +type CreateKeyRequest struct { + // V1 Fields + Config KeystoreInstanceConfig + KeyAlgorithm KeyAlgorithm + ID *string + Region string + KeyType KeyType +} + +type CreateKeyResponse struct { + // V1 Fields + KeyID string + Status string +} + +// DeleteKeyRequest contains parameters for key deletion +type DeleteKeyRequest struct { + // V1 Fields + Parameters RequestParameters + Window *int32 +} + +type DeleteKeyResponse struct{} + +// EnableKeyRequest contains parameters for key enablement +type EnableKeyRequest struct { + // V1 Fields + Parameters RequestParameters +} + +type EnableKeyResponse struct{} + +// DisableKeyRequest contains parameters for key disablement +type DisableKeyRequest struct { + // V1 Fields + Parameters RequestParameters +} + +type DisableKeyResponse struct{} + +type GetImportParametersRequest struct { + // V1 Fields + Parameters RequestParameters + KeyAlgorithm KeyAlgorithm +} + +type GetImportParametersResponse struct { + // V1 Fields + KeyID string + ImportParameters map[string]any +} + +type ImportKeyMaterialRequest struct { + // V1 Fields + Parameters RequestParameters + ImportParameters map[string]any + EncryptedKeyMaterial string +} + +type ImportKeyMaterialResponse struct{} + +type ValidateKeyRequest struct { + // V1 Fields + KeyType KeyType + KeyAlgorithm KeyAlgorithm + Region string + NativeKeyID string +} + +type ValidateKeyResponse struct { + // V1 Fields + IsValid bool + Message string +} + +type ValidateKeyAccessDataRequest struct { + // V1 Fields + Management map[string]any + Crypto map[string]any +} + +type ValidateKeyAccessDataResponse struct { + // V1 Fields + IsValid bool + Message string +} + +type TransformCryptoAccessDataRequest struct { + // V1 Fields + NativeKeyID string + AccessData []byte +} + +type TransformCryptoAccessDataResponse struct { + // V1 Fields + TransformedAccessData map[string][]byte +} + +type ExtractKeyRegionRequest struct { + // V1 Fields + NativeKeyID string + ManagementAccessData map[string]any +} + +type ExtractKeyRegionResponse struct { + // V1 Fields + Region string +} diff --git a/api/service/notification/notification.go b/api/service/notification/notification.go new file mode 100644 index 0000000..b67420a --- /dev/null +++ b/api/service/notification/notification.go @@ -0,0 +1,30 @@ +package notification + +import "context" + +type Notification interface { + SendNotification(ctx context.Context, req *SendNotificationRequest) (*SendNotificationResponse, error) +} + +type Type int32 + +const ( + Unspecified Type = iota + Email + Text + Web +) + +type SendNotificationRequest struct { + // V1 Fields + Type Type + Recipients []string + Subject string + Body string +} + +type SendNotificationResponse struct { + // V1 Fields + Success bool + Message string +} diff --git a/api/service/registry.go b/api/service/registry.go new file mode 100644 index 0000000..c160122 --- /dev/null +++ b/api/service/registry.go @@ -0,0 +1,66 @@ +package service + +import ( + "errors" + + "github.com/openkcm/plugin-sdk/api/service/certificateissuer" + "github.com/openkcm/plugin-sdk/api/service/identitymanagement" + "github.com/openkcm/plugin-sdk/api/service/keystore" + "github.com/openkcm/plugin-sdk/api/service/notification" + "github.com/openkcm/plugin-sdk/api/service/systeminformation" +) + +type Version int + +const ( + V1 Version = iota + 1 +) + +var ( + ErrVersionNotSupported = errors.New("version not supported") +) + +type Registry interface { + CertificateIssuer + IdentityManagement + KeystoreManagement + KeystoreOperations + Notification + SystemInformation +} + +type CertificateIssuer interface { + CertificateIssuerByName(name string) (certificateissuer.CertificateIssuer, error) + CertificateIssuerByNameAndVersion(version Version, name string) (certificateissuer.CertificateIssuer, error) + ListCertificateIssuerByVersion(version Version) ([]certificateissuer.CertificateIssuer, error) +} + +type KeystoreManagement interface { + KeystoreManagementByName(name string) (keystore.KeystoreManagement, error) + KeystoreManagementByNameAndVersion(version Version, name string) (keystore.KeystoreManagement, error) + KeystoreManagementByVersion(version Version) ([]keystore.KeystoreManagement, error) +} + +type KeystoreOperations interface { + KeystoreOperationsByName(name string) (keystore.KeystoreOperations, error) + KeystoreOperationsByNameAndVersion(version Version, name string) (keystore.KeystoreOperations, error) + KeystoreOperationsByVersion(version Version) ([]keystore.KeystoreOperations, error) +} + +type IdentityManagement interface { + IdentityManagementByName(name string) (identitymanagement.IdentityManagement, error) + IdentityManagementByNameAndVersion(version Version, name string) (identitymanagement.IdentityManagement, error) + IdentityManagementByVersion(version Version) ([]identitymanagement.IdentityManagement, error) +} + +type Notification interface { + NotificationByName(name string) (notification.Notification, error) + NotificationByNameAndVersion(version Version, name string) (notification.Notification, error) + NotificationByVersion(version Version) ([]notification.Notification, error) +} + +type SystemInformation interface { + SystemInformationByName(name string) (systeminformation.SystemInformation, error) + SystemInformationByNameAndVersion(version Version, name string) (systeminformation.SystemInformation, error) + SystemInformationByVersion(version Version) ([]systeminformation.SystemInformation, error) +} diff --git a/api/service/systeminformation/system_information.go b/api/service/systeminformation/system_information.go new file mode 100644 index 0000000..25b89f6 --- /dev/null +++ b/api/service/systeminformation/system_information.go @@ -0,0 +1,26 @@ +package systeminformation + +import "context" + +type SystemInformation interface { + Get(ctx context.Context, req *GetRequest) (*GetResponse, error) +} + +type RequestType int32 + +const ( + Unspecified RequestType = iota + System + Subaccount +) + +type GetRequest struct { + // V1 Fields + ID string + Type RequestType +} + +type GetResponse struct { + // V1 Fields + Metadata map[string]string +} diff --git a/pkg/catalog/builtin.go b/pkg/catalog/builtin.go index fd5d318..2a45bf9 100644 --- a/pkg/catalog/builtin.go +++ b/pkg/catalog/builtin.go @@ -16,22 +16,22 @@ import ( "github.com/openkcm/plugin-sdk/internal/slog2hclog" ) -type BuiltIn struct { +type BuiltInPlugin struct { Name string Tags []string Plugin api.PluginServer Services []api.ServiceServer } -func MakeBuiltIn(name string, pluginServer api.PluginServer, serviceServers ...api.ServiceServer) BuiltIn { - return BuiltIn{ +func MakeBuiltInPlugin(name string, pluginServer api.PluginServer, serviceServers ...api.ServiceServer) BuiltInPlugin { + return BuiltInPlugin{ Name: name, Plugin: pluginServer, Services: serviceServers, } } -func loadBuiltIn(ctx context.Context, builtIn BuiltIn, pluginConfig PluginConfig) (_ *Plugin, err error) { +func loadBuiltInPlugin(ctx context.Context, builtIn BuiltInPlugin, pluginConfig PluginConfig) (_ *Plugin, err error) { dialer := &builtinDialer{ pluginName: builtIn.Name, log: pluginConfig.Logger, diff --git a/pkg/catalog/builtin_registry.go b/pkg/catalog/builtin_registry.go index e5e3219..350889e 100644 --- a/pkg/catalog/builtin_registry.go +++ b/pkg/catalog/builtin_registry.go @@ -1,26 +1,26 @@ package catalog type BuiltInPluginRegistry interface { - Register(plugin BuiltIn) - Get() []BuiltIn + Register(plugin BuiltInPlugin) + Get() []BuiltInPlugin } type buildInRegistry struct { - plugins []BuiltIn + plugins []BuiltInPlugin } func DefaultBuiltInPluginRegistry() BuiltInPluginRegistry { return &buildInRegistry{ - plugins: make([]BuiltIn, 0), + plugins: make([]BuiltInPlugin, 0), } } -func (r *buildInRegistry) Register(plugin BuiltIn) { +func (r *buildInRegistry) Register(plugin BuiltInPlugin) { r.plugins = append(r.plugins, plugin) } -func (r *buildInRegistry) Get() []BuiltIn { - plugins := make([]BuiltIn, 0, len(r.plugins)) +func (r *buildInRegistry) Get() []BuiltInPlugin { + plugins := make([]BuiltInPlugin, 0, len(r.plugins)) plugins = append(plugins, r.plugins...) return plugins } diff --git a/pkg/catalog/builtin_registry_test.go b/pkg/catalog/builtin_registry_test.go index f2f22a4..ae63dcc 100644 --- a/pkg/catalog/builtin_registry_test.go +++ b/pkg/catalog/builtin_registry_test.go @@ -23,14 +23,14 @@ func TestBuiltInRegistry(t *testing.T) { reg := DefaultBuiltInPluginRegistry() - p1 := BuiltIn{Name: "plugin-1"} - p2 := BuiltIn{Name: "plugin-2"} + p1 := BuiltInPlugin{Name: "plugin-1"} + p2 := BuiltInPlugin{Name: "plugin-2"} reg.Register(p1) reg.Register(p2) got := reg.Get() - want := []BuiltIn{p1, p2} + want := []BuiltInPlugin{p1, p2} if !reflect.DeepEqual(got, want) { t.Fatalf("unexpected plugins\nwant: %#v\ngot: %#v", want, got) @@ -42,11 +42,11 @@ func TestBuiltInRegistry(t *testing.T) { reg := DefaultBuiltInPluginRegistry() - p1 := BuiltIn{Name: "plugin-1"} + p1 := BuiltInPlugin{Name: "plugin-1"} reg.Register(p1) plugins := reg.Get() - plugins[0] = BuiltIn{Name: "mutated"} + plugins[0] = BuiltInPlugin{Name: "mutated"} got := reg.Get() if got[0].Name != p1.Name { diff --git a/pkg/catalog/catalog.go b/pkg/catalog/catalog.go index 90ae286..7b64714 100644 --- a/pkg/catalog/catalog.go +++ b/pkg/catalog/catalog.go @@ -64,7 +64,7 @@ func (c *Catalog) ListPluginInfo() []PluginInfo { return plugins } -func Load(ctx context.Context, config Config, builtIns ...BuiltIn) (catalog *Catalog, err error) { +func Load(ctx context.Context, config Config, builtIns ...BuiltInPlugin) (catalog *Catalog, err error) { closers := make(closerGroup, 0) defer func() { // If loading fails, clear out the catalog and close down all plugins @@ -113,7 +113,7 @@ func Load(ctx context.Context, config Config, builtIns ...BuiltIn) (catalog *Cat }, nil } -func loadPluginAs(ctx context.Context, logger *slog.Logger, pluginConfig PluginConfig, builtIns ...BuiltIn) (*Plugin, error) { +func loadPluginAs(ctx context.Context, logger *slog.Logger, pluginConfig PluginConfig, builtIns ...BuiltInPlugin) (*Plugin, error) { if pluginConfig.IsExternal() { plugin, err := loadPluginAsExternal(ctx, logger, pluginConfig) if err != nil { @@ -146,7 +146,7 @@ func loadPluginAsExternal(ctx context.Context, logger *slog.Logger, pluginConfig return loadPlugin(ctx, pluginConfig) } -func loadPluginAsBuiltIn(ctx context.Context, logger *slog.Logger, pluginConfig PluginConfig, builtIns ...BuiltIn) (*Plugin, error) { +func loadPluginAsBuiltIn(ctx context.Context, logger *slog.Logger, pluginConfig PluginConfig, builtIns ...BuiltInPlugin) (*Plugin, error) { if pluginConfig.Name == "" { return nil, fmt.Errorf("failed to load builtin plugin, missing name") } @@ -158,7 +158,7 @@ func loadPluginAsBuiltIn(ctx context.Context, logger *slog.Logger, pluginConfig Type, builtin.Plugin.Type(), ) - return loadBuiltIn(ctx, builtin, pluginConfig) + return loadBuiltInPlugin(ctx, builtin, pluginConfig) } } return nil, fmt.Errorf("builtin plugin %q not found", pluginConfig.Name) diff --git a/pkg/plugin/service/certificate_issuer_v1.go b/pkg/plugin/service/certificate_issuer_v1.go new file mode 100644 index 0000000..5036c26 --- /dev/null +++ b/pkg/plugin/service/certificate_issuer_v1.go @@ -0,0 +1,58 @@ +package service + +import ( + "context" + + "github.com/openkcm/plugin-sdk/api/service/certificateissuer" + "github.com/openkcm/plugin-sdk/pkg/catalog" + certificate_issuerv1 "github.com/openkcm/plugin-sdk/proto/plugin/certificate_issuer/v1" +) + +var _ certificateissuer.CertificateIssuer = (*hashicorpCertificateIssuerV1Plugin)(nil) + +type hashicorpCertificateIssuerV1Plugin struct { + plugin *catalog.Plugin + grpcClient certificate_issuerv1.CertificateIssuerServiceClient +} + +func NewCertificateIssuerV1Plugin(plugin *catalog.Plugin) certificateissuer.CertificateIssuer { + return &hashicorpCertificateIssuerV1Plugin{ + plugin: plugin, + grpcClient: certificate_issuerv1.NewCertificateIssuerServiceClient(plugin.ClientConnection()), + } +} + +func (h *hashicorpCertificateIssuerV1Plugin) GetCertificate(ctx context.Context, req *certificateissuer.GetCertificateRequest) (*certificateissuer.GetCertificateResponse, error) { + in := &certificate_issuerv1.GetCertificateRequest{ + CommonName: req.CommonName, + Locality: req.Localities, + Validity: CertificateValidityToGRPC(req.Validity), + PrivateKey: CertificatePrivateKeyToGRPC(req.PrivateKey), + } + grpcResp, err := h.grpcClient.GetCertificate(ctx, in) + if err != nil { + return nil, err + } + return &certificateissuer.GetCertificateResponse{ + ChainPem: grpcResp.CertificateChain, + }, nil +} + +func CertificateValidityToGRPC(v *certificateissuer.CertificateValidity) *certificate_issuerv1.GetCertificateValidity { + if v == nil { + return nil + } + return &certificate_issuerv1.GetCertificateValidity{ + Value: v.Value, + Type: certificate_issuerv1.ValidityType(v.Type), + } +} + +func CertificatePrivateKeyToGRPC(pk *certificateissuer.CertificatePrivateKey) *certificate_issuerv1.PrivateKey { + if pk == nil { + return nil + } + return &certificate_issuerv1.PrivateKey{ + Data: pk.Data, + } +} diff --git a/pkg/plugin/service/hashicorp_registry.go b/pkg/plugin/service/hashicorp_registry.go new file mode 100644 index 0000000..40e4963 --- /dev/null +++ b/pkg/plugin/service/hashicorp_registry.go @@ -0,0 +1,18 @@ +package service + +import ( + apiservice "github.com/openkcm/plugin-sdk/api/service" + "github.com/openkcm/plugin-sdk/pkg/catalog" +) + +var _ apiservice.Registry = (*hashicorpPluginServiceRegistry)(nil) + +type hashicorpPluginServiceRegistry struct { + catalog *catalog.Catalog +} + +func NewHashicorpPluginServiceRegistry(catalog *catalog.Catalog) apiservice.Registry { + return &hashicorpPluginServiceRegistry{ + catalog: catalog, + } +} diff --git a/pkg/plugin/service/hashicorp_registry_certificate_issuer.go b/pkg/plugin/service/hashicorp_registry_certificate_issuer.go new file mode 100644 index 0000000..c074424 --- /dev/null +++ b/pkg/plugin/service/hashicorp_registry_certificate_issuer.go @@ -0,0 +1,44 @@ +package service + +import ( + "fmt" + + "github.com/openkcm/plugin-sdk/api/service" + "github.com/openkcm/plugin-sdk/api/service/certificateissuer" + certificate_issuerv1 "github.com/openkcm/plugin-sdk/proto/plugin/certificate_issuer/v1" +) + +func (h *hashicorpPluginServiceRegistry) CertificateIssuerByName(name string) (certificateissuer.CertificateIssuer, error) { + plugin := h.catalog.LookupByTypeAndName(certificate_issuerv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewCertificateIssuerV1Plugin(plugin), nil +} + +func (h *hashicorpPluginServiceRegistry) CertificateIssuerByNameAndVersion(version service.Version, name string) (certificateissuer.CertificateIssuer, error) { + switch version { + case service.V1: + plugin := h.catalog.LookupByTypeAndName(certificate_issuerv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewCertificateIssuerV1Plugin(plugin), nil + } + + return nil, service.ErrVersionNotSupported +} + +func (h *hashicorpPluginServiceRegistry) ListCertificateIssuerByVersion(version service.Version) ([]certificateissuer.CertificateIssuer, error) { + var issuers []certificateissuer.CertificateIssuer + switch version { + case service.V1: + plugins := h.catalog.LookupByType(certificate_issuerv1.Type) + for _, plugin := range plugins { + issuers = append(issuers, NewCertificateIssuerV1Plugin(plugin)) + } + return issuers, nil + } + + return issuers, service.ErrVersionNotSupported +} diff --git a/pkg/plugin/service/hashicorp_registry_identity_management.go b/pkg/plugin/service/hashicorp_registry_identity_management.go new file mode 100644 index 0000000..673f28f --- /dev/null +++ b/pkg/plugin/service/hashicorp_registry_identity_management.go @@ -0,0 +1,44 @@ +package service + +import ( + "fmt" + + "github.com/openkcm/plugin-sdk/api/service" + "github.com/openkcm/plugin-sdk/api/service/identitymanagement" + identity_managementv1 "github.com/openkcm/plugin-sdk/proto/plugin/identity_management/v1" +) + +func (h *hashicorpPluginServiceRegistry) IdentityManagementByName(name string) (identitymanagement.IdentityManagement, error) { + plugin := h.catalog.LookupByTypeAndName(identity_managementv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewIdentityManagementV1Plugin(plugin), nil +} + +func (h *hashicorpPluginServiceRegistry) IdentityManagementByNameAndVersion(version service.Version, name string) (identitymanagement.IdentityManagement, error) { + switch version { + case service.V1: + plugin := h.catalog.LookupByTypeAndName(identity_managementv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewIdentityManagementV1Plugin(plugin), nil + } + + return nil, service.ErrVersionNotSupported +} + +func (h *hashicorpPluginServiceRegistry) IdentityManagementByVersion(version service.Version) ([]identitymanagement.IdentityManagement, error) { + var issuers []identitymanagement.IdentityManagement + switch version { + case service.V1: + plugins := h.catalog.LookupByType(identity_managementv1.Type) + for _, plugin := range plugins { + issuers = append(issuers, NewIdentityManagementV1Plugin(plugin)) + } + return issuers, nil + } + + return issuers, service.ErrVersionNotSupported +} diff --git a/pkg/plugin/service/hashicorp_registry_keystore_management.go b/pkg/plugin/service/hashicorp_registry_keystore_management.go new file mode 100644 index 0000000..e77bd1c --- /dev/null +++ b/pkg/plugin/service/hashicorp_registry_keystore_management.go @@ -0,0 +1,44 @@ +package service + +import ( + "fmt" + + "github.com/openkcm/plugin-sdk/api/service" + "github.com/openkcm/plugin-sdk/api/service/keystore" + managementv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/management/v1" +) + +func (h *hashicorpPluginServiceRegistry) KeystoreManagementByName(name string) (keystore.KeystoreManagement, error) { + plugin := h.catalog.LookupByTypeAndName(managementv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewKeystoreManagementV1Plugin(plugin), nil +} + +func (h *hashicorpPluginServiceRegistry) KeystoreManagementByNameAndVersion(version service.Version, name string) (keystore.KeystoreManagement, error) { + switch version { + case service.V1: + plugin := h.catalog.LookupByTypeAndName(managementv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewKeystoreManagementV1Plugin(plugin), nil + } + + return nil, service.ErrVersionNotSupported +} + +func (h *hashicorpPluginServiceRegistry) KeystoreManagementByVersion(version service.Version) ([]keystore.KeystoreManagement, error) { + var issuers []keystore.KeystoreManagement + switch version { + case service.V1: + plugins := h.catalog.LookupByType(managementv1.Type) + for _, plugin := range plugins { + issuers = append(issuers, NewKeystoreManagementV1Plugin(plugin)) + } + return issuers, nil + } + + return issuers, service.ErrVersionNotSupported +} diff --git a/pkg/plugin/service/hashicorp_registry_keystore_operations.go b/pkg/plugin/service/hashicorp_registry_keystore_operations.go new file mode 100644 index 0000000..4f3542b --- /dev/null +++ b/pkg/plugin/service/hashicorp_registry_keystore_operations.go @@ -0,0 +1,44 @@ +package service + +import ( + "fmt" + + "github.com/openkcm/plugin-sdk/api/service" + "github.com/openkcm/plugin-sdk/api/service/keystore" + operationsv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/operations/v1" +) + +func (h *hashicorpPluginServiceRegistry) KeystoreOperationsByName(name string) (keystore.KeystoreOperations, error) { + plugin := h.catalog.LookupByTypeAndName(operationsv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewKeystoreOperationsV1Plugin(plugin), nil +} + +func (h *hashicorpPluginServiceRegistry) KeystoreOperationsByNameAndVersion(version service.Version, name string) (keystore.KeystoreOperations, error) { + switch version { + case service.V1: + plugin := h.catalog.LookupByTypeAndName(operationsv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewKeystoreOperationsV1Plugin(plugin), nil + } + + return nil, service.ErrVersionNotSupported +} + +func (h *hashicorpPluginServiceRegistry) KeystoreOperationsByVersion(version service.Version) ([]keystore.KeystoreOperations, error) { + var issuers []keystore.KeystoreOperations + switch version { + case service.V1: + plugins := h.catalog.LookupByType(operationsv1.Type) + for _, plugin := range plugins { + issuers = append(issuers, NewKeystoreOperationsV1Plugin(plugin)) + } + return issuers, nil + } + + return issuers, service.ErrVersionNotSupported +} diff --git a/pkg/plugin/service/hashicorp_registry_notification.go b/pkg/plugin/service/hashicorp_registry_notification.go new file mode 100644 index 0000000..b5ee44b --- /dev/null +++ b/pkg/plugin/service/hashicorp_registry_notification.go @@ -0,0 +1,44 @@ +package service + +import ( + "fmt" + + "github.com/openkcm/plugin-sdk/api/service" + "github.com/openkcm/plugin-sdk/api/service/notification" + notificationv1 "github.com/openkcm/plugin-sdk/proto/plugin/notification/v1" +) + +func (h *hashicorpPluginServiceRegistry) NotificationByName(name string) (notification.Notification, error) { + plugin := h.catalog.LookupByTypeAndName(notificationv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewNotificationV1Plugin(plugin), nil +} + +func (h *hashicorpPluginServiceRegistry) NotificationByNameAndVersion(version service.Version, name string) (notification.Notification, error) { + switch version { + case service.V1: + plugin := h.catalog.LookupByTypeAndName(notificationv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewNotificationV1Plugin(plugin), nil + } + + return nil, service.ErrVersionNotSupported +} + +func (h *hashicorpPluginServiceRegistry) NotificationByVersion(version service.Version) ([]notification.Notification, error) { + var issuers []notification.Notification + switch version { + case service.V1: + plugins := h.catalog.LookupByType(notificationv1.Type) + for _, plugin := range plugins { + issuers = append(issuers, NewNotificationV1Plugin(plugin)) + } + return issuers, nil + } + + return issuers, service.ErrVersionNotSupported +} diff --git a/pkg/plugin/service/hashicorp_registry_system_information.go b/pkg/plugin/service/hashicorp_registry_system_information.go new file mode 100644 index 0000000..4b6f58f --- /dev/null +++ b/pkg/plugin/service/hashicorp_registry_system_information.go @@ -0,0 +1,44 @@ +package service + +import ( + "fmt" + + "github.com/openkcm/plugin-sdk/api/service" + "github.com/openkcm/plugin-sdk/api/service/systeminformation" + systeminformationv1 "github.com/openkcm/plugin-sdk/proto/plugin/systeminformation/v1" +) + +func (h *hashicorpPluginServiceRegistry) SystemInformationByName(name string) (systeminformation.SystemInformation, error) { + plugin := h.catalog.LookupByTypeAndName(systeminformationv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewSystemInformationV1Plugin(plugin), nil +} + +func (h *hashicorpPluginServiceRegistry) SystemInformationByNameAndVersion(version service.Version, name string) (systeminformation.SystemInformation, error) { + switch version { + case service.V1: + plugin := h.catalog.LookupByTypeAndName(systeminformationv1.Type, name) + if plugin == nil { + return nil, fmt.Errorf("unable to find certificate issuer plugin %q", name) + } + return NewSystemInformationV1Plugin(plugin), nil + } + + return nil, service.ErrVersionNotSupported +} + +func (h *hashicorpPluginServiceRegistry) SystemInformationByVersion(version service.Version) ([]systeminformation.SystemInformation, error) { + var issuers []systeminformation.SystemInformation + switch version { + case service.V1: + plugins := h.catalog.LookupByType(systeminformationv1.Type) + for _, plugin := range plugins { + issuers = append(issuers, NewSystemInformationV1Plugin(plugin)) + } + return issuers, nil + } + + return issuers, service.ErrVersionNotSupported +} diff --git a/pkg/plugin/service/identity_management_v1.go b/pkg/plugin/service/identity_management_v1.go new file mode 100644 index 0000000..8266bcf --- /dev/null +++ b/pkg/plugin/service/identity_management_v1.go @@ -0,0 +1,124 @@ +package service + +import ( + "context" + + "github.com/openkcm/plugin-sdk/api/service/identitymanagement" + "github.com/openkcm/plugin-sdk/pkg/catalog" + identity_managementv1 "github.com/openkcm/plugin-sdk/proto/plugin/identity_management/v1" +) + +var _ identitymanagement.IdentityManagement = (*hashicorpIdentityManagementV1Plugin)(nil) + +type hashicorpIdentityManagementV1Plugin struct { + plugin *catalog.Plugin + grpcClient identity_managementv1.IdentityManagementServiceClient +} + +func NewIdentityManagementV1Plugin(plugin *catalog.Plugin) identitymanagement.IdentityManagement { + return &hashicorpIdentityManagementV1Plugin{ + plugin: plugin, + grpcClient: identity_managementv1.NewIdentityManagementServiceClient(plugin.ClientConnection()), + } +} + +func (h *hashicorpIdentityManagementV1Plugin) GetGroup(ctx context.Context, req *identitymanagement.GetGroupRequest) (*identitymanagement.GetGroupResponse, error) { + in := &identity_managementv1.GetGroupRequest{ + GroupName: req.GroupName, + AuthContext: AuthContextToGRPC(&req.AuthContext), + } + grpcResp, err := h.grpcClient.GetGroup(ctx, in) + if err != nil { + return nil, err + } + return &identitymanagement.GetGroupResponse{ + Group: FromGRPCGroup(grpcResp.GetGroup()), + }, nil +} + +func (h *hashicorpIdentityManagementV1Plugin) GetAllGroups(ctx context.Context, req *identitymanagement.GetAllGroupsRequest) (*identitymanagement.GetAllGroupsResponse, error) { + in := &identity_managementv1.GetAllGroupsRequest{ + AuthContext: AuthContextToGRPC(&req.AuthContext), + } + grpcResp, err := h.grpcClient.GetAllGroups(ctx, in) + if err != nil { + return nil, err + } + return &identitymanagement.GetAllGroupsResponse{ + Groups: FromGRPCGroups(grpcResp.GetGroups()), + }, nil +} + +func (h *hashicorpIdentityManagementV1Plugin) GetUsersForGroup(ctx context.Context, req *identitymanagement.GetUsersForGroupRequest) (*identitymanagement.GetUsersForGroupResponse, error) { + in := &identity_managementv1.GetUsersForGroupRequest{ + GroupId: req.GroupID, + AuthContext: AuthContextToGRPC(&req.AuthContext), + } + grpcResp, err := h.grpcClient.GetUsersForGroup(ctx, in) + if err != nil { + return nil, err + } + return &identitymanagement.GetUsersForGroupResponse{ + Users: FromGRPCUsers(grpcResp.GetUsers()), + }, nil +} + +func (h *hashicorpIdentityManagementV1Plugin) GetGroupsForUser(ctx context.Context, req *identitymanagement.GetGroupsForUserRequest) (*identitymanagement.GetGroupsForUserResponse, error) { + in := &identity_managementv1.GetGroupsForUserRequest{ + UserId: req.UserID, + AuthContext: AuthContextToGRPC(&req.AuthContext), + } + grpcResp, err := h.grpcClient.GetGroupsForUser(ctx, in) + if err != nil { + return nil, err + } + return &identitymanagement.GetGroupsForUserResponse{ + Groups: FromGRPCGroups(grpcResp.GetGroups()), + }, nil +} + +func AuthContextToGRPC(v *identitymanagement.AuthContext) *identity_managementv1.AuthContext { + if v == nil { + return nil + } + return &identity_managementv1.AuthContext{ + Data: v.Data, + } +} + +func FromGRPCGroup(v *identity_managementv1.Group) identitymanagement.Group { + if v == nil { + return identitymanagement.Group{} + } + return identitymanagement.Group{ + ID: v.Id, + Name: v.Name, + } +} + +func FromGRPCGroups(groups []*identity_managementv1.Group) []identitymanagement.Group { + var wrapperGroups []identitymanagement.Group + for _, group := range groups { + wrapperGroups = append(wrapperGroups, FromGRPCGroup(group)) + } + return wrapperGroups +} + +func FromGRPCUser(v *identity_managementv1.User) identitymanagement.User { + if v == nil { + return identitymanagement.User{} + } + return identitymanagement.User{ + ID: v.Id, + Name: v.Name, + Email: v.Email, + } +} + +func FromGRPCUsers(users []*identity_managementv1.User) []identitymanagement.User { + var wrapperUsers []identitymanagement.User + for _, user := range users { + wrapperUsers = append(wrapperUsers, FromGRPCUser(user)) + } + return wrapperUsers +} diff --git a/pkg/plugin/service/keystore_management_v1.go b/pkg/plugin/service/keystore_management_v1.go new file mode 100644 index 0000000..6d4a008 --- /dev/null +++ b/pkg/plugin/service/keystore_management_v1.go @@ -0,0 +1,67 @@ +package service + +import ( + "context" + "fmt" + + "github.com/openkcm/plugin-sdk/api/service/keystore" + "github.com/openkcm/plugin-sdk/pkg/catalog" + commonv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/common/v1" + managementv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/management/v1" + "google.golang.org/protobuf/types/known/structpb" +) + +var _ keystore.KeystoreManagement = (*hashicorpKeystoreManagementV1Plugin)(nil) + +type hashicorpKeystoreManagementV1Plugin struct { + plugin *catalog.Plugin + grpcClient managementv1.KeystoreProviderClient +} + +func NewKeystoreManagementV1Plugin(plugin *catalog.Plugin) keystore.KeystoreManagement { + return &hashicorpKeystoreManagementV1Plugin{ + plugin: plugin, + grpcClient: managementv1.NewKeystoreProviderClient(plugin.ClientConnection()), + } +} + +func (h *hashicorpKeystoreManagementV1Plugin) CreateKeystore(ctx context.Context, req *keystore.CreateKeystoreRequest) (*keystore.CreateKeystoreResponse, error) { + value, err := structpb.NewStruct(req.Values) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + + in := &managementv1.CreateKeystoreRequest{ + Values: value, + } + grpcResp, err := h.grpcClient.CreateKeystore(ctx, in) + if err != nil { + return nil, err + } + resp := &keystore.CreateKeystoreResponse{ + Config: keystore.KeystoreInstanceConfig{ + Values: nil, + }, + } + if grpcResp.GetConfig() != nil || grpcResp.GetConfig().GetValues() != nil { + resp.Config.Values = grpcResp.GetConfig().GetValues().AsMap() + } + return resp, nil +} + +func (h *hashicorpKeystoreManagementV1Plugin) DeleteKeystore(ctx context.Context, req *keystore.DeleteKeystoreRequest) (*keystore.DeleteKeystoreResponse, error) { + value, err := structpb.NewStruct(req.Config.Values) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + in := &managementv1.DeleteKeystoreRequest{ + Config: &commonv1.KeystoreInstanceConfig{ + Values: value, + }, + } + _, err = h.grpcClient.DeleteKeystore(ctx, in) + if err != nil { + return nil, err + } + return &keystore.DeleteKeystoreResponse{}, nil +} diff --git a/pkg/plugin/service/keystore_operations_v1.go b/pkg/plugin/service/keystore_operations_v1.go new file mode 100644 index 0000000..045ba09 --- /dev/null +++ b/pkg/plugin/service/keystore_operations_v1.go @@ -0,0 +1,256 @@ +package service + +import ( + "context" + "fmt" + + "github.com/openkcm/plugin-sdk/api/service/keystore" + "github.com/openkcm/plugin-sdk/pkg/catalog" + commonv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/common/v1" + operationsv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/operations/v1" + "google.golang.org/protobuf/types/known/structpb" +) + +var _ keystore.KeystoreOperations = (*hashicorpKeystoreOperationsV1Plugin)(nil) + +type hashicorpKeystoreOperationsV1Plugin struct { + plugin *catalog.Plugin + grpcClient operationsv1.KeystoreInstanceKeyOperationClient +} + +func NewKeystoreOperationsV1Plugin(plugin *catalog.Plugin) keystore.KeystoreOperations { + return &hashicorpKeystoreOperationsV1Plugin{ + plugin: plugin, + grpcClient: operationsv1.NewKeystoreInstanceKeyOperationClient(plugin.ClientConnection()), + } +} + +func (h *hashicorpKeystoreOperationsV1Plugin) GetKey(ctx context.Context, req *keystore.GetKeyRequest) (*keystore.GetKeyResponse, error) { + value, err := structpb.NewStruct(req.Parameters.Config.Values) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + + in := &operationsv1.GetKeyRequest{ + Parameters: &operationsv1.RequestParameters{ + Config: &commonv1.KeystoreInstanceConfig{ + Values: value, + }, + KeyId: req.Parameters.KeyID, + }, + } + grpcResp, err := h.grpcClient.GetKey(ctx, in) + if err != nil { + return nil, err + } + + return &keystore.GetKeyResponse{ + KeyID: grpcResp.GetKeyId(), + KeyAlgorithm: keystore.KeyAlgorithm(grpcResp.GetAlgorithm()), + Status: grpcResp.GetStatus(), + Usage: grpcResp.GetUsage(), + }, nil +} + +func (h *hashicorpKeystoreOperationsV1Plugin) CreateKey(ctx context.Context, req *keystore.CreateKeyRequest) (*keystore.CreateKeyResponse, error) { + value, err := structpb.NewStruct(req.Config.Values) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + + in := &operationsv1.CreateKeyRequest{ + Config: &commonv1.KeystoreInstanceConfig{ + Values: value, + }, + Algorithm: operationsv1.KeyAlgorithm(req.KeyAlgorithm), + Id: req.ID, + Region: req.Region, + KeyType: operationsv1.KeyType(req.KeyType), + } + grpcResp, err := h.grpcClient.CreateKey(ctx, in) + if err != nil { + return nil, err + } + + return &keystore.CreateKeyResponse{ + KeyID: grpcResp.GetKeyId(), + Status: grpcResp.GetStatus(), + }, nil +} + +func (h *hashicorpKeystoreOperationsV1Plugin) DeleteKey(ctx context.Context, req *keystore.DeleteKeyRequest) (*keystore.DeleteKeyResponse, error) { + value, err := structpb.NewStruct(req.Parameters.Config.Values) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + + in := &operationsv1.DeleteKeyRequest{ + Parameters: &operationsv1.RequestParameters{ + Config: &commonv1.KeystoreInstanceConfig{ + Values: value, + }, + KeyId: req.Parameters.KeyID, + }, + Window: req.Window, + } + _, err = h.grpcClient.DeleteKey(ctx, in) + if err != nil { + return nil, err + } + + return &keystore.DeleteKeyResponse{}, nil +} + +func (h *hashicorpKeystoreOperationsV1Plugin) EnableKey(ctx context.Context, req *keystore.EnableKeyRequest) (*keystore.EnableKeyResponse, error) { + value, err := structpb.NewStruct(req.Parameters.Config.Values) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + + in := &operationsv1.EnableKeyRequest{ + Parameters: &operationsv1.RequestParameters{ + Config: &commonv1.KeystoreInstanceConfig{ + Values: value, + }, + KeyId: req.Parameters.KeyID, + }, + } + _, err = h.grpcClient.EnableKey(ctx, in) + if err != nil { + return nil, err + } + + return &keystore.EnableKeyResponse{}, nil +} + +func (h *hashicorpKeystoreOperationsV1Plugin) GetImportParameters(ctx context.Context, req *keystore.GetImportParametersRequest) (*keystore.GetImportParametersResponse, error) { + value, err := structpb.NewStruct(req.Parameters.Config.Values) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + + in := &operationsv1.GetImportParametersRequest{ + Parameters: &operationsv1.RequestParameters{ + Config: &commonv1.KeystoreInstanceConfig{ + Values: value, + }, + KeyId: req.Parameters.KeyID, + }, + Algorithm: operationsv1.KeyAlgorithm(req.KeyAlgorithm), + } + grpcResp, err := h.grpcClient.GetImportParameters(ctx, in) + if err != nil { + return nil, err + } + + return &keystore.GetImportParametersResponse{ + KeyID: grpcResp.GetKeyId(), + ImportParameters: grpcResp.GetImportParameters().AsMap(), + }, nil +} + +func (h *hashicorpKeystoreOperationsV1Plugin) ImportKeyMaterial(ctx context.Context, req *keystore.ImportKeyMaterialRequest) (*keystore.ImportKeyMaterialResponse, error) { + value, err := structpb.NewStruct(req.Parameters.Config.Values) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + + importParams, err := structpb.NewStruct(req.ImportParameters) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + + in := &operationsv1.ImportKeyMaterialRequest{ + Parameters: &operationsv1.RequestParameters{ + Config: &commonv1.KeystoreInstanceConfig{ + Values: value, + }, + KeyId: req.Parameters.KeyID, + }, + ImportParameters: importParams, + } + _, err = h.grpcClient.ImportKeyMaterial(ctx, in) + if err != nil { + return nil, err + } + + return &keystore.ImportKeyMaterialResponse{}, nil +} + +func (h *hashicorpKeystoreOperationsV1Plugin) ValidateKey(ctx context.Context, req *keystore.ValidateKeyRequest) (*keystore.ValidateKeyResponse, error) { + in := &operationsv1.ValidateKeyRequest{ + KeyType: operationsv1.KeyType(req.KeyType), + Algorithm: operationsv1.KeyAlgorithm(req.KeyAlgorithm), + Region: req.Region, + NativeKeyId: req.NativeKeyID, + } + grpcResp, err := h.grpcClient.ValidateKey(ctx, in) + if err != nil { + return nil, err + } + + return &keystore.ValidateKeyResponse{ + IsValid: grpcResp.GetIsValid(), + Message: grpcResp.GetMessage(), + }, nil +} + +func (h *hashicorpKeystoreOperationsV1Plugin) ValidateKeyAccessData(ctx context.Context, req *keystore.ValidateKeyAccessDataRequest) (*keystore.ValidateKeyAccessDataResponse, error) { + management, err := structpb.NewStruct(req.Management) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + crypto, err := structpb.NewStruct(req.Crypto) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + + in := &operationsv1.ValidateKeyAccessDataRequest{ + Management: management, + Crypto: crypto, + } + grpcResp, err := h.grpcClient.ValidateKeyAccessData(ctx, in) + if err != nil { + return nil, err + } + + return &keystore.ValidateKeyAccessDataResponse{ + IsValid: grpcResp.GetIsValid(), + Message: grpcResp.GetMessage(), + }, nil +} + +func (h *hashicorpKeystoreOperationsV1Plugin) TransformCryptoAccessData(ctx context.Context, req *keystore.TransformCryptoAccessDataRequest) (*keystore.TransformCryptoAccessDataResponse, error) { + in := &operationsv1.TransformCryptoAccessDataRequest{ + NativeKeyId: req.NativeKeyID, + AccessData: req.AccessData, + } + grpcResp, err := h.grpcClient.TransformCryptoAccessData(ctx, in) + if err != nil { + return nil, err + } + + return &keystore.TransformCryptoAccessDataResponse{ + TransformedAccessData: grpcResp.GetTransformedAccessData(), + }, nil +} + +func (h *hashicorpKeystoreOperationsV1Plugin) ExtractKeyRegion(ctx context.Context, req *keystore.ExtractKeyRegionRequest) (*keystore.ExtractKeyRegionResponse, error) { + management, err := structpb.NewStruct(req.ManagementAccessData) + if err != nil { + return nil, fmt.Errorf("failed to parse values: %v", err) + } + + in := &operationsv1.ExtractKeyRegionRequest{ + NativeKeyId: req.NativeKeyID, + ManagementAccessData: management, + } + grpcResp, err := h.grpcClient.ExtractKeyRegion(ctx, in) + if err != nil { + return nil, err + } + + return &keystore.ExtractKeyRegionResponse{ + Region: grpcResp.GetRegion(), + }, nil +} diff --git a/pkg/plugin/service/notification_v1.go b/pkg/plugin/service/notification_v1.go new file mode 100644 index 0000000..5001c0c --- /dev/null +++ b/pkg/plugin/service/notification_v1.go @@ -0,0 +1,40 @@ +package service + +import ( + "context" + + "github.com/openkcm/plugin-sdk/api/service/notification" + "github.com/openkcm/plugin-sdk/pkg/catalog" + notificationv1 "github.com/openkcm/plugin-sdk/proto/plugin/notification/v1" +) + +var _ notification.Notification = (*hashicorpNotificationV1Plugin)(nil) + +type hashicorpNotificationV1Plugin struct { + plugin *catalog.Plugin + grpcClient notificationv1.NotificationServiceClient +} + +func NewNotificationV1Plugin(plugin *catalog.Plugin) notification.Notification { + return &hashicorpNotificationV1Plugin{ + plugin: plugin, + grpcClient: notificationv1.NewNotificationServiceClient(plugin.ClientConnection()), + } +} + +func (h *hashicorpNotificationV1Plugin) SendNotification(ctx context.Context, req *notification.SendNotificationRequest) (*notification.SendNotificationResponse, error) { + in := ¬ificationv1.SendNotificationRequest{ + NotificationType: notificationv1.NotificationType(req.Type), + Recipients: req.Recipients, + Subject: req.Subject, + Body: req.Body, + } + grpcResp, err := h.grpcClient.SendNotification(ctx, in) + if err != nil { + return nil, err + } + return ¬ification.SendNotificationResponse{ + Success: grpcResp.GetSuccess(), + Message: grpcResp.GetMessage(), + }, nil +} diff --git a/pkg/plugin/service/system_information_v1.go b/pkg/plugin/service/system_information_v1.go new file mode 100644 index 0000000..4e0f190 --- /dev/null +++ b/pkg/plugin/service/system_information_v1.go @@ -0,0 +1,37 @@ +package service + +import ( + "context" + + "github.com/openkcm/plugin-sdk/api/service/systeminformation" + "github.com/openkcm/plugin-sdk/pkg/catalog" + systeminformationv1 "github.com/openkcm/plugin-sdk/proto/plugin/systeminformation/v1" +) + +var _ systeminformation.SystemInformation = (*hashicorpSystemInformationV1Plugin)(nil) + +type hashicorpSystemInformationV1Plugin struct { + plugin *catalog.Plugin + grpcClient systeminformationv1.SystemInformationServiceClient +} + +func NewSystemInformationV1Plugin(plugin *catalog.Plugin) systeminformation.SystemInformation { + return &hashicorpSystemInformationV1Plugin{ + plugin: plugin, + grpcClient: systeminformationv1.NewSystemInformationServiceClient(plugin.ClientConnection()), + } +} + +func (h *hashicorpSystemInformationV1Plugin) Get(ctx context.Context, req *systeminformation.GetRequest) (*systeminformation.GetResponse, error) { + in := &systeminformationv1.GetRequest{ + Id: req.ID, + Type: systeminformationv1.RequestType(req.Type), + } + grpcResp, err := h.grpcClient.Get(ctx, in) + if err != nil { + return nil, err + } + return &systeminformation.GetResponse{ + Metadata: grpcResp.GetMetadata(), + }, nil +} From d3243e1b663b8e688052ffed367d2df721466c93 Mon Sep 17 00:00:00 2001 From: Nicolae Nicora Date: Sat, 7 Feb 2026 17:07:57 +0100 Subject: [PATCH 2/9] revert this back --- pkg/catalog/builtin.go | 8 ++++---- pkg/catalog/builtin_registry.go | 14 +++++++------- pkg/catalog/builtin_registry_test.go | 10 +++++----- pkg/catalog/catalog.go | 8 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pkg/catalog/builtin.go b/pkg/catalog/builtin.go index 2a45bf9..fd5d318 100644 --- a/pkg/catalog/builtin.go +++ b/pkg/catalog/builtin.go @@ -16,22 +16,22 @@ import ( "github.com/openkcm/plugin-sdk/internal/slog2hclog" ) -type BuiltInPlugin struct { +type BuiltIn struct { Name string Tags []string Plugin api.PluginServer Services []api.ServiceServer } -func MakeBuiltInPlugin(name string, pluginServer api.PluginServer, serviceServers ...api.ServiceServer) BuiltInPlugin { - return BuiltInPlugin{ +func MakeBuiltIn(name string, pluginServer api.PluginServer, serviceServers ...api.ServiceServer) BuiltIn { + return BuiltIn{ Name: name, Plugin: pluginServer, Services: serviceServers, } } -func loadBuiltInPlugin(ctx context.Context, builtIn BuiltInPlugin, pluginConfig PluginConfig) (_ *Plugin, err error) { +func loadBuiltIn(ctx context.Context, builtIn BuiltIn, pluginConfig PluginConfig) (_ *Plugin, err error) { dialer := &builtinDialer{ pluginName: builtIn.Name, log: pluginConfig.Logger, diff --git a/pkg/catalog/builtin_registry.go b/pkg/catalog/builtin_registry.go index 350889e..e5e3219 100644 --- a/pkg/catalog/builtin_registry.go +++ b/pkg/catalog/builtin_registry.go @@ -1,26 +1,26 @@ package catalog type BuiltInPluginRegistry interface { - Register(plugin BuiltInPlugin) - Get() []BuiltInPlugin + Register(plugin BuiltIn) + Get() []BuiltIn } type buildInRegistry struct { - plugins []BuiltInPlugin + plugins []BuiltIn } func DefaultBuiltInPluginRegistry() BuiltInPluginRegistry { return &buildInRegistry{ - plugins: make([]BuiltInPlugin, 0), + plugins: make([]BuiltIn, 0), } } -func (r *buildInRegistry) Register(plugin BuiltInPlugin) { +func (r *buildInRegistry) Register(plugin BuiltIn) { r.plugins = append(r.plugins, plugin) } -func (r *buildInRegistry) Get() []BuiltInPlugin { - plugins := make([]BuiltInPlugin, 0, len(r.plugins)) +func (r *buildInRegistry) Get() []BuiltIn { + plugins := make([]BuiltIn, 0, len(r.plugins)) plugins = append(plugins, r.plugins...) return plugins } diff --git a/pkg/catalog/builtin_registry_test.go b/pkg/catalog/builtin_registry_test.go index ae63dcc..f2f22a4 100644 --- a/pkg/catalog/builtin_registry_test.go +++ b/pkg/catalog/builtin_registry_test.go @@ -23,14 +23,14 @@ func TestBuiltInRegistry(t *testing.T) { reg := DefaultBuiltInPluginRegistry() - p1 := BuiltInPlugin{Name: "plugin-1"} - p2 := BuiltInPlugin{Name: "plugin-2"} + p1 := BuiltIn{Name: "plugin-1"} + p2 := BuiltIn{Name: "plugin-2"} reg.Register(p1) reg.Register(p2) got := reg.Get() - want := []BuiltInPlugin{p1, p2} + want := []BuiltIn{p1, p2} if !reflect.DeepEqual(got, want) { t.Fatalf("unexpected plugins\nwant: %#v\ngot: %#v", want, got) @@ -42,11 +42,11 @@ func TestBuiltInRegistry(t *testing.T) { reg := DefaultBuiltInPluginRegistry() - p1 := BuiltInPlugin{Name: "plugin-1"} + p1 := BuiltIn{Name: "plugin-1"} reg.Register(p1) plugins := reg.Get() - plugins[0] = BuiltInPlugin{Name: "mutated"} + plugins[0] = BuiltIn{Name: "mutated"} got := reg.Get() if got[0].Name != p1.Name { diff --git a/pkg/catalog/catalog.go b/pkg/catalog/catalog.go index 7b64714..90ae286 100644 --- a/pkg/catalog/catalog.go +++ b/pkg/catalog/catalog.go @@ -64,7 +64,7 @@ func (c *Catalog) ListPluginInfo() []PluginInfo { return plugins } -func Load(ctx context.Context, config Config, builtIns ...BuiltInPlugin) (catalog *Catalog, err error) { +func Load(ctx context.Context, config Config, builtIns ...BuiltIn) (catalog *Catalog, err error) { closers := make(closerGroup, 0) defer func() { // If loading fails, clear out the catalog and close down all plugins @@ -113,7 +113,7 @@ func Load(ctx context.Context, config Config, builtIns ...BuiltInPlugin) (catalo }, nil } -func loadPluginAs(ctx context.Context, logger *slog.Logger, pluginConfig PluginConfig, builtIns ...BuiltInPlugin) (*Plugin, error) { +func loadPluginAs(ctx context.Context, logger *slog.Logger, pluginConfig PluginConfig, builtIns ...BuiltIn) (*Plugin, error) { if pluginConfig.IsExternal() { plugin, err := loadPluginAsExternal(ctx, logger, pluginConfig) if err != nil { @@ -146,7 +146,7 @@ func loadPluginAsExternal(ctx context.Context, logger *slog.Logger, pluginConfig return loadPlugin(ctx, pluginConfig) } -func loadPluginAsBuiltIn(ctx context.Context, logger *slog.Logger, pluginConfig PluginConfig, builtIns ...BuiltInPlugin) (*Plugin, error) { +func loadPluginAsBuiltIn(ctx context.Context, logger *slog.Logger, pluginConfig PluginConfig, builtIns ...BuiltIn) (*Plugin, error) { if pluginConfig.Name == "" { return nil, fmt.Errorf("failed to load builtin plugin, missing name") } @@ -158,7 +158,7 @@ func loadPluginAsBuiltIn(ctx context.Context, logger *slog.Logger, pluginConfig Type, builtin.Plugin.Type(), ) - return loadBuiltInPlugin(ctx, builtin, pluginConfig) + return loadBuiltIn(ctx, builtin, pluginConfig) } } return nil, fmt.Errorf("builtin plugin %q not found", pluginConfig.Name) From 70b212584daa7f9b54730d774ba1d5c0852a6d36 Mon Sep 17 00:00:00 2001 From: Nicolae Nicora Date: Sat, 7 Feb 2026 17:33:04 +0100 Subject: [PATCH 3/9] fix some lints errors --- pkg/plugin/service/keystore_management_v1.go | 3 ++- pkg/plugin/service/keystore_operations_v1.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/plugin/service/keystore_management_v1.go b/pkg/plugin/service/keystore_management_v1.go index 6d4a008..eb2f512 100644 --- a/pkg/plugin/service/keystore_management_v1.go +++ b/pkg/plugin/service/keystore_management_v1.go @@ -4,11 +4,12 @@ import ( "context" "fmt" + "google.golang.org/protobuf/types/known/structpb" + "github.com/openkcm/plugin-sdk/api/service/keystore" "github.com/openkcm/plugin-sdk/pkg/catalog" commonv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/common/v1" managementv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/management/v1" - "google.golang.org/protobuf/types/known/structpb" ) var _ keystore.KeystoreManagement = (*hashicorpKeystoreManagementV1Plugin)(nil) diff --git a/pkg/plugin/service/keystore_operations_v1.go b/pkg/plugin/service/keystore_operations_v1.go index 045ba09..1f774b9 100644 --- a/pkg/plugin/service/keystore_operations_v1.go +++ b/pkg/plugin/service/keystore_operations_v1.go @@ -4,11 +4,12 @@ import ( "context" "fmt" + "google.golang.org/protobuf/types/known/structpb" + "github.com/openkcm/plugin-sdk/api/service/keystore" "github.com/openkcm/plugin-sdk/pkg/catalog" commonv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/common/v1" operationsv1 "github.com/openkcm/plugin-sdk/proto/plugin/keystore/operations/v1" - "google.golang.org/protobuf/types/known/structpb" ) var _ keystore.KeystoreOperations = (*hashicorpKeystoreOperationsV1Plugin)(nil) From be72acbe32ed8aa0157515ac05caebef5b9159ff Mon Sep 17 00:00:00 2001 From: Nicolae Nicora Date: Sun, 8 Feb 2026 22:29:32 +0100 Subject: [PATCH 4/9] update the plugin acting as interface --- pkg/plugin/service/certificate_issuer_v1.go | 4 ++-- pkg/plugin/service/identity_management_v1.go | 4 ++-- pkg/plugin/service/keystore_management_v1.go | 4 ++-- pkg/plugin/service/keystore_operations_v1.go | 4 ++-- pkg/plugin/service/notification_v1.go | 4 ++-- pkg/plugin/service/system_information_v1.go | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/plugin/service/certificate_issuer_v1.go b/pkg/plugin/service/certificate_issuer_v1.go index 5036c26..09e1a67 100644 --- a/pkg/plugin/service/certificate_issuer_v1.go +++ b/pkg/plugin/service/certificate_issuer_v1.go @@ -11,11 +11,11 @@ import ( var _ certificateissuer.CertificateIssuer = (*hashicorpCertificateIssuerV1Plugin)(nil) type hashicorpCertificateIssuerV1Plugin struct { - plugin *catalog.Plugin + plugin catalog.Plugin grpcClient certificate_issuerv1.CertificateIssuerServiceClient } -func NewCertificateIssuerV1Plugin(plugin *catalog.Plugin) certificateissuer.CertificateIssuer { +func NewCertificateIssuerV1Plugin(plugin catalog.Plugin) certificateissuer.CertificateIssuer { return &hashicorpCertificateIssuerV1Plugin{ plugin: plugin, grpcClient: certificate_issuerv1.NewCertificateIssuerServiceClient(plugin.ClientConnection()), diff --git a/pkg/plugin/service/identity_management_v1.go b/pkg/plugin/service/identity_management_v1.go index 8266bcf..259e4f7 100644 --- a/pkg/plugin/service/identity_management_v1.go +++ b/pkg/plugin/service/identity_management_v1.go @@ -11,11 +11,11 @@ import ( var _ identitymanagement.IdentityManagement = (*hashicorpIdentityManagementV1Plugin)(nil) type hashicorpIdentityManagementV1Plugin struct { - plugin *catalog.Plugin + plugin catalog.Plugin grpcClient identity_managementv1.IdentityManagementServiceClient } -func NewIdentityManagementV1Plugin(plugin *catalog.Plugin) identitymanagement.IdentityManagement { +func NewIdentityManagementV1Plugin(plugin catalog.Plugin) identitymanagement.IdentityManagement { return &hashicorpIdentityManagementV1Plugin{ plugin: plugin, grpcClient: identity_managementv1.NewIdentityManagementServiceClient(plugin.ClientConnection()), diff --git a/pkg/plugin/service/keystore_management_v1.go b/pkg/plugin/service/keystore_management_v1.go index eb2f512..ecc6313 100644 --- a/pkg/plugin/service/keystore_management_v1.go +++ b/pkg/plugin/service/keystore_management_v1.go @@ -15,11 +15,11 @@ import ( var _ keystore.KeystoreManagement = (*hashicorpKeystoreManagementV1Plugin)(nil) type hashicorpKeystoreManagementV1Plugin struct { - plugin *catalog.Plugin + plugin catalog.Plugin grpcClient managementv1.KeystoreProviderClient } -func NewKeystoreManagementV1Plugin(plugin *catalog.Plugin) keystore.KeystoreManagement { +func NewKeystoreManagementV1Plugin(plugin catalog.Plugin) keystore.KeystoreManagement { return &hashicorpKeystoreManagementV1Plugin{ plugin: plugin, grpcClient: managementv1.NewKeystoreProviderClient(plugin.ClientConnection()), diff --git a/pkg/plugin/service/keystore_operations_v1.go b/pkg/plugin/service/keystore_operations_v1.go index 1f774b9..3cc41a1 100644 --- a/pkg/plugin/service/keystore_operations_v1.go +++ b/pkg/plugin/service/keystore_operations_v1.go @@ -15,11 +15,11 @@ import ( var _ keystore.KeystoreOperations = (*hashicorpKeystoreOperationsV1Plugin)(nil) type hashicorpKeystoreOperationsV1Plugin struct { - plugin *catalog.Plugin + plugin catalog.Plugin grpcClient operationsv1.KeystoreInstanceKeyOperationClient } -func NewKeystoreOperationsV1Plugin(plugin *catalog.Plugin) keystore.KeystoreOperations { +func NewKeystoreOperationsV1Plugin(plugin catalog.Plugin) keystore.KeystoreOperations { return &hashicorpKeystoreOperationsV1Plugin{ plugin: plugin, grpcClient: operationsv1.NewKeystoreInstanceKeyOperationClient(plugin.ClientConnection()), diff --git a/pkg/plugin/service/notification_v1.go b/pkg/plugin/service/notification_v1.go index 5001c0c..41364d5 100644 --- a/pkg/plugin/service/notification_v1.go +++ b/pkg/plugin/service/notification_v1.go @@ -11,11 +11,11 @@ import ( var _ notification.Notification = (*hashicorpNotificationV1Plugin)(nil) type hashicorpNotificationV1Plugin struct { - plugin *catalog.Plugin + plugin catalog.Plugin grpcClient notificationv1.NotificationServiceClient } -func NewNotificationV1Plugin(plugin *catalog.Plugin) notification.Notification { +func NewNotificationV1Plugin(plugin catalog.Plugin) notification.Notification { return &hashicorpNotificationV1Plugin{ plugin: plugin, grpcClient: notificationv1.NewNotificationServiceClient(plugin.ClientConnection()), diff --git a/pkg/plugin/service/system_information_v1.go b/pkg/plugin/service/system_information_v1.go index 4e0f190..d97af12 100644 --- a/pkg/plugin/service/system_information_v1.go +++ b/pkg/plugin/service/system_information_v1.go @@ -11,11 +11,11 @@ import ( var _ systeminformation.SystemInformation = (*hashicorpSystemInformationV1Plugin)(nil) type hashicorpSystemInformationV1Plugin struct { - plugin *catalog.Plugin + plugin catalog.Plugin grpcClient systeminformationv1.SystemInformationServiceClient } -func NewSystemInformationV1Plugin(plugin *catalog.Plugin) systeminformation.SystemInformation { +func NewSystemInformationV1Plugin(plugin catalog.Plugin) systeminformation.SystemInformation { return &hashicorpSystemInformationV1Plugin{ plugin: plugin, grpcClient: systeminformationv1.NewSystemInformationServiceClient(plugin.ClientConnection()), From 41055f32d51589727002478fba00c88a19dda262 Mon Sep 17 00:00:00 2001 From: Nicolae Nicora Date: Sun, 8 Feb 2026 22:32:47 +0100 Subject: [PATCH 5/9] add some sonar ignore --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index a02427f..e51f7bc 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,2 +1,2 @@ sonar.test.inclusions=**/*_test.go -sonar.coverage.exclusions=**/pkg/catalog/**,**/*_test.go \ No newline at end of file +sonar.coverage.exclusions=**/api/**,**/proto/**,**/pkg/catalog/**,**/*_test.go \ No newline at end of file From cfa2ac533629d03e08b6a21ba8529cd707028743 Mon Sep 17 00:00:00 2001 From: Nicolae Nicora Date: Sun, 8 Feb 2026 22:35:01 +0100 Subject: [PATCH 6/9] add some sonar ignore --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index e51f7bc..e5f83e1 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,2 +1,2 @@ sonar.test.inclusions=**/*_test.go -sonar.coverage.exclusions=**/api/**,**/proto/**,**/pkg/catalog/**,**/*_test.go \ No newline at end of file +sonar.coverage.exclusions=**/api/**,**/proto/**,**/pkg/**,**/*_test.go \ No newline at end of file From 596c9bb3c0ba10b9ff7079d093e7980c921f95f1 Mon Sep 17 00:00:00 2001 From: Nicolae Nicora Date: Mon, 9 Feb 2026 12:59:37 +0100 Subject: [PATCH 7/9] add some renamings --- api/service/keystore/common.go | 2 +- api/service/keystore/keystore_management.go | 4 ++-- api/service/keystore/keystore_operations.go | 4 ++-- api/service/systeminformation/system_information.go | 6 +++--- pkg/plugin/service/keystore_management_v1.go | 2 +- pkg/plugin/service/system_information_v1.go | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api/service/keystore/common.go b/api/service/keystore/common.go index 8fdebaa..e2680bf 100644 --- a/api/service/keystore/common.go +++ b/api/service/keystore/common.go @@ -1,5 +1,5 @@ package keystore -type KeystoreInstanceConfig struct { +type InstanceConfig struct { Values map[string]any } diff --git a/api/service/keystore/keystore_management.go b/api/service/keystore/keystore_management.go index 9e41c49..35f4655 100644 --- a/api/service/keystore/keystore_management.go +++ b/api/service/keystore/keystore_management.go @@ -16,12 +16,12 @@ type CreateKeystoreRequest struct { type CreateKeystoreResponse struct { // V1 Fields - Config KeystoreInstanceConfig + Config InstanceConfig } type DeleteKeystoreRequest struct { // V1 Fields - Config KeystoreInstanceConfig + Config InstanceConfig } type DeleteKeystoreResponse struct{} diff --git a/api/service/keystore/keystore_operations.go b/api/service/keystore/keystore_operations.go index 183e44f..05bc3cb 100644 --- a/api/service/keystore/keystore_operations.go +++ b/api/service/keystore/keystore_operations.go @@ -37,7 +37,7 @@ const ( type RequestParameters struct { // V1 Fields - Config KeystoreInstanceConfig + Config InstanceConfig KeyID string } @@ -57,7 +57,7 @@ type GetKeyResponse struct { // CreateKeyRequest contains parameters for key creation type CreateKeyRequest struct { // V1 Fields - Config KeystoreInstanceConfig + Config InstanceConfig KeyAlgorithm KeyAlgorithm ID *string Region string diff --git a/api/service/systeminformation/system_information.go b/api/service/systeminformation/system_information.go index 25b89f6..8182542 100644 --- a/api/service/systeminformation/system_information.go +++ b/api/service/systeminformation/system_information.go @@ -3,7 +3,7 @@ package systeminformation import "context" type SystemInformation interface { - Get(ctx context.Context, req *GetRequest) (*GetResponse, error) + Get(ctx context.Context, req *GetSystemInformationRequest) (*GetSystemInformationResponse, error) } type RequestType int32 @@ -14,13 +14,13 @@ const ( Subaccount ) -type GetRequest struct { +type GetSystemInformationRequest struct { // V1 Fields ID string Type RequestType } -type GetResponse struct { +type GetSystemInformationResponse struct { // V1 Fields Metadata map[string]string } diff --git a/pkg/plugin/service/keystore_management_v1.go b/pkg/plugin/service/keystore_management_v1.go index ecc6313..27d247b 100644 --- a/pkg/plugin/service/keystore_management_v1.go +++ b/pkg/plugin/service/keystore_management_v1.go @@ -40,7 +40,7 @@ func (h *hashicorpKeystoreManagementV1Plugin) CreateKeystore(ctx context.Context return nil, err } resp := &keystore.CreateKeystoreResponse{ - Config: keystore.KeystoreInstanceConfig{ + Config: keystore.InstanceConfig{ Values: nil, }, } diff --git a/pkg/plugin/service/system_information_v1.go b/pkg/plugin/service/system_information_v1.go index d97af12..6ad1ca9 100644 --- a/pkg/plugin/service/system_information_v1.go +++ b/pkg/plugin/service/system_information_v1.go @@ -22,7 +22,7 @@ func NewSystemInformationV1Plugin(plugin catalog.Plugin) systeminformation.Syste } } -func (h *hashicorpSystemInformationV1Plugin) Get(ctx context.Context, req *systeminformation.GetRequest) (*systeminformation.GetResponse, error) { +func (h *hashicorpSystemInformationV1Plugin) Get(ctx context.Context, req *systeminformation.GetSystemInformationRequest) (*systeminformation.GetSystemInformationResponse, error) { in := &systeminformationv1.GetRequest{ Id: req.ID, Type: systeminformationv1.RequestType(req.Type), @@ -31,7 +31,7 @@ func (h *hashicorpSystemInformationV1Plugin) Get(ctx context.Context, req *syste if err != nil { return nil, err } - return &systeminformation.GetResponse{ + return &systeminformation.GetSystemInformationResponse{ Metadata: grpcResp.GetMetadata(), }, nil } From 2d3b0aa391ce8e65c8e3419946a1235536a92b1a Mon Sep 17 00:00:00 2001 From: Nicolae Nicora Date: Mon, 9 Feb 2026 13:33:41 +0100 Subject: [PATCH 8/9] add some renamings --- .../certificateissuer/certificate_issuer.go | 6 +++--- .../identitymanagement/identity_management.go | 18 +++++++++--------- api/service/keystore/keystore_operations.go | 6 +++--- api/service/notification/notification.go | 2 +- .../systeminformation/system_information.go | 6 +++--- pkg/plugin/service/certificate_issuer_v1.go | 4 ++-- pkg/plugin/service/identity_management_v1.go | 12 ++++++------ pkg/plugin/service/notification_v1.go | 2 +- pkg/plugin/service/system_information_v1.go | 4 ++-- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/api/service/certificateissuer/certificate_issuer.go b/api/service/certificateissuer/certificate_issuer.go index 6c44326..81906c3 100644 --- a/api/service/certificateissuer/certificate_issuer.go +++ b/api/service/certificateissuer/certificate_issuer.go @@ -5,7 +5,7 @@ import ( ) type CertificateIssuer interface { - GetCertificate(ctx context.Context, req *GetCertificateRequest) (*GetCertificateResponse, error) + IssueCertificate(ctx context.Context, req *IssueCertificateRequest) (*IssueCertificateResponse, error) } type ValidityType int32 @@ -17,7 +17,7 @@ const ( Years ) -type GetCertificateRequest struct { +type IssueCertificateRequest struct { // V1 Fields CommonName string Localities []string @@ -25,7 +25,7 @@ type GetCertificateRequest struct { PrivateKey *CertificatePrivateKey } -type GetCertificateResponse struct { +type IssueCertificateResponse struct { // V1 Fields ChainPem string } diff --git a/api/service/identitymanagement/identity_management.go b/api/service/identitymanagement/identity_management.go index 5e3952d..c055c69 100644 --- a/api/service/identitymanagement/identity_management.go +++ b/api/service/identitymanagement/identity_management.go @@ -6,9 +6,9 @@ import ( type IdentityManagement interface { GetGroup(ctx context.Context, req *GetGroupRequest) (*GetGroupResponse, error) - GetAllGroups(ctx context.Context, req *GetAllGroupsRequest) (*GetAllGroupsResponse, error) - GetUsersForGroup(ctx context.Context, req *GetUsersForGroupRequest) (*GetUsersForGroupResponse, error) - GetGroupsForUser(ctx context.Context, req *GetGroupsForUserRequest) (*GetGroupsForUserResponse, error) + ListGroups(ctx context.Context, req *ListGroupsRequest) (*ListGroupsResponse, error) + ListGroupUsers(ctx context.Context, req *ListGroupUsersRequest) (*ListGroupUsersResponse, error) + LetUserGroups(ctx context.Context, req *LetUserGroupsRequest) (*LetUserGroupsResponse, error) } type AuthContext struct { @@ -27,23 +27,23 @@ type GetGroupResponse struct { Group Group } -type GetAllGroupsRequest struct { +type ListGroupsRequest struct { // V1 Fields AuthContext AuthContext } -type GetAllGroupsResponse struct { +type ListGroupsResponse struct { // V1 Fields Groups []Group } -type GetUsersForGroupRequest struct { +type ListGroupUsersRequest struct { // V1 Fields GroupID string AuthContext AuthContext } -type GetUsersForGroupResponse struct { +type ListGroupUsersResponse struct { // V1 Fields Users []User } @@ -55,13 +55,13 @@ type User struct { Email string } -type GetGroupsForUserRequest struct { +type LetUserGroupsRequest struct { // V1 Fields UserID string AuthContext AuthContext } -type GetGroupsForUserResponse struct { +type LetUserGroupsResponse struct { // V1 Fields Groups []Group } diff --git a/api/service/keystore/keystore_operations.go b/api/service/keystore/keystore_operations.go index 05bc3cb..9f255a0 100644 --- a/api/service/keystore/keystore_operations.go +++ b/api/service/keystore/keystore_operations.go @@ -21,9 +21,9 @@ type KeyAlgorithm int32 const ( UnspecifiedKeyAlgorithm KeyAlgorithm = iota - AES256KeyAlgorithm - RSA3072KeyAlgorithm - RSA4096KeyAlgorithm + AES256K + RSA3072 + RSA4096 ) type KeyType int32 diff --git a/api/service/notification/notification.go b/api/service/notification/notification.go index b67420a..45b9f5e 100644 --- a/api/service/notification/notification.go +++ b/api/service/notification/notification.go @@ -3,7 +3,7 @@ package notification import "context" type Notification interface { - SendNotification(ctx context.Context, req *SendNotificationRequest) (*SendNotificationResponse, error) + Send(ctx context.Context, req *SendNotificationRequest) (*SendNotificationResponse, error) } type Type int32 diff --git a/api/service/systeminformation/system_information.go b/api/service/systeminformation/system_information.go index 8182542..6ec7037 100644 --- a/api/service/systeminformation/system_information.go +++ b/api/service/systeminformation/system_information.go @@ -3,7 +3,7 @@ package systeminformation import "context" type SystemInformation interface { - Get(ctx context.Context, req *GetSystemInformationRequest) (*GetSystemInformationResponse, error) + GetSystemInfo(ctx context.Context, req *GetSystemInfoRequest) (*GetSystemInfoResponse, error) } type RequestType int32 @@ -14,13 +14,13 @@ const ( Subaccount ) -type GetSystemInformationRequest struct { +type GetSystemInfoRequest struct { // V1 Fields ID string Type RequestType } -type GetSystemInformationResponse struct { +type GetSystemInfoResponse struct { // V1 Fields Metadata map[string]string } diff --git a/pkg/plugin/service/certificate_issuer_v1.go b/pkg/plugin/service/certificate_issuer_v1.go index 09e1a67..20085c7 100644 --- a/pkg/plugin/service/certificate_issuer_v1.go +++ b/pkg/plugin/service/certificate_issuer_v1.go @@ -22,7 +22,7 @@ func NewCertificateIssuerV1Plugin(plugin catalog.Plugin) certificateissuer.Certi } } -func (h *hashicorpCertificateIssuerV1Plugin) GetCertificate(ctx context.Context, req *certificateissuer.GetCertificateRequest) (*certificateissuer.GetCertificateResponse, error) { +func (h *hashicorpCertificateIssuerV1Plugin) IssueCertificate(ctx context.Context, req *certificateissuer.IssueCertificateRequest) (*certificateissuer.IssueCertificateResponse, error) { in := &certificate_issuerv1.GetCertificateRequest{ CommonName: req.CommonName, Locality: req.Localities, @@ -33,7 +33,7 @@ func (h *hashicorpCertificateIssuerV1Plugin) GetCertificate(ctx context.Context, if err != nil { return nil, err } - return &certificateissuer.GetCertificateResponse{ + return &certificateissuer.IssueCertificateResponse{ ChainPem: grpcResp.CertificateChain, }, nil } diff --git a/pkg/plugin/service/identity_management_v1.go b/pkg/plugin/service/identity_management_v1.go index 259e4f7..c0e5403 100644 --- a/pkg/plugin/service/identity_management_v1.go +++ b/pkg/plugin/service/identity_management_v1.go @@ -36,7 +36,7 @@ func (h *hashicorpIdentityManagementV1Plugin) GetGroup(ctx context.Context, req }, nil } -func (h *hashicorpIdentityManagementV1Plugin) GetAllGroups(ctx context.Context, req *identitymanagement.GetAllGroupsRequest) (*identitymanagement.GetAllGroupsResponse, error) { +func (h *hashicorpIdentityManagementV1Plugin) ListGroups(ctx context.Context, req *identitymanagement.ListGroupsRequest) (*identitymanagement.ListGroupsResponse, error) { in := &identity_managementv1.GetAllGroupsRequest{ AuthContext: AuthContextToGRPC(&req.AuthContext), } @@ -44,12 +44,12 @@ func (h *hashicorpIdentityManagementV1Plugin) GetAllGroups(ctx context.Context, if err != nil { return nil, err } - return &identitymanagement.GetAllGroupsResponse{ + return &identitymanagement.ListGroupsResponse{ Groups: FromGRPCGroups(grpcResp.GetGroups()), }, nil } -func (h *hashicorpIdentityManagementV1Plugin) GetUsersForGroup(ctx context.Context, req *identitymanagement.GetUsersForGroupRequest) (*identitymanagement.GetUsersForGroupResponse, error) { +func (h *hashicorpIdentityManagementV1Plugin) ListGroupUsers(ctx context.Context, req *identitymanagement.ListGroupUsersRequest) (*identitymanagement.ListGroupUsersResponse, error) { in := &identity_managementv1.GetUsersForGroupRequest{ GroupId: req.GroupID, AuthContext: AuthContextToGRPC(&req.AuthContext), @@ -58,12 +58,12 @@ func (h *hashicorpIdentityManagementV1Plugin) GetUsersForGroup(ctx context.Conte if err != nil { return nil, err } - return &identitymanagement.GetUsersForGroupResponse{ + return &identitymanagement.ListGroupUsersResponse{ Users: FromGRPCUsers(grpcResp.GetUsers()), }, nil } -func (h *hashicorpIdentityManagementV1Plugin) GetGroupsForUser(ctx context.Context, req *identitymanagement.GetGroupsForUserRequest) (*identitymanagement.GetGroupsForUserResponse, error) { +func (h *hashicorpIdentityManagementV1Plugin) LetUserGroups(ctx context.Context, req *identitymanagement.LetUserGroupsRequest) (*identitymanagement.LetUserGroupsResponse, error) { in := &identity_managementv1.GetGroupsForUserRequest{ UserId: req.UserID, AuthContext: AuthContextToGRPC(&req.AuthContext), @@ -72,7 +72,7 @@ func (h *hashicorpIdentityManagementV1Plugin) GetGroupsForUser(ctx context.Conte if err != nil { return nil, err } - return &identitymanagement.GetGroupsForUserResponse{ + return &identitymanagement.LetUserGroupsResponse{ Groups: FromGRPCGroups(grpcResp.GetGroups()), }, nil } diff --git a/pkg/plugin/service/notification_v1.go b/pkg/plugin/service/notification_v1.go index 41364d5..17c21bf 100644 --- a/pkg/plugin/service/notification_v1.go +++ b/pkg/plugin/service/notification_v1.go @@ -22,7 +22,7 @@ func NewNotificationV1Plugin(plugin catalog.Plugin) notification.Notification { } } -func (h *hashicorpNotificationV1Plugin) SendNotification(ctx context.Context, req *notification.SendNotificationRequest) (*notification.SendNotificationResponse, error) { +func (h *hashicorpNotificationV1Plugin) Send(ctx context.Context, req *notification.SendNotificationRequest) (*notification.SendNotificationResponse, error) { in := ¬ificationv1.SendNotificationRequest{ NotificationType: notificationv1.NotificationType(req.Type), Recipients: req.Recipients, diff --git a/pkg/plugin/service/system_information_v1.go b/pkg/plugin/service/system_information_v1.go index 6ad1ca9..9dec3cd 100644 --- a/pkg/plugin/service/system_information_v1.go +++ b/pkg/plugin/service/system_information_v1.go @@ -22,7 +22,7 @@ func NewSystemInformationV1Plugin(plugin catalog.Plugin) systeminformation.Syste } } -func (h *hashicorpSystemInformationV1Plugin) Get(ctx context.Context, req *systeminformation.GetSystemInformationRequest) (*systeminformation.GetSystemInformationResponse, error) { +func (h *hashicorpSystemInformationV1Plugin) GetSystemInfo(ctx context.Context, req *systeminformation.GetSystemInfoRequest) (*systeminformation.GetSystemInfoResponse, error) { in := &systeminformationv1.GetRequest{ Id: req.ID, Type: systeminformationv1.RequestType(req.Type), @@ -31,7 +31,7 @@ func (h *hashicorpSystemInformationV1Plugin) Get(ctx context.Context, req *syste if err != nil { return nil, err } - return &systeminformation.GetSystemInformationResponse{ + return &systeminformation.GetSystemInfoResponse{ Metadata: grpcResp.GetMetadata(), }, nil } From 3ac2894f564ec02885c66c3010cc1cafdae91d58 Mon Sep 17 00:00:00 2001 From: Nicolae Nicora Date: Mon, 9 Feb 2026 13:33:57 +0100 Subject: [PATCH 9/9] fix a test --- pkg/catalog/plugin_test.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/catalog/plugin_test.go b/pkg/catalog/plugin_test.go index 53f33c9..762149d 100644 --- a/pkg/catalog/plugin_test.go +++ b/pkg/catalog/plugin_test.go @@ -98,8 +98,8 @@ func TestInjectEnv(t *testing.T) { injectEnv(cfg, cmd) - if len(cmd.Env) != 2 { - t.Fatalf("expected 2 env vars, got %d", len(cmd.Env)) + if len(cmd.Env) != 3 { + t.Fatalf("expected 3 env vars, got %d", len(cmd.Env)) } } @@ -278,7 +278,14 @@ func TestBuildSecureConfig(t *testing.T) { func TestInitPluginFailure(t *testing.T) { t.Parallel() - _, err := initPlugin( + var err error + defer func() { + if r := recover(); r == nil { + err = errors.New("nil grpc connection") + } + }() + + _, err = initPlugin( context.Background(), nil, // invalid conn triggers failure []api.ServiceServer{ @@ -300,7 +307,14 @@ func TestInitPluginFailure(t *testing.T) { func TestNewPluginInitFailure(t *testing.T) { t.Parallel() - _, err := newPlugin( + var err error + defer func() { + if r := recover(); r == nil { + err = errors.New("nil grpc connection") + } + }() + + _, err = newPlugin( context.Background(), nil, &pluginInfo{name: "p"},