diff --git a/src/cluster/k8sClientHandler.go b/src/cluster/k8sClientHandler.go index aba4bcb1..0e05f6ad 100644 --- a/src/cluster/k8sClientHandler.go +++ b/src/cluster/k8sClientHandler.go @@ -541,6 +541,7 @@ func CreateLicenseSecret(k8sClient *kubernetes.Clientset, key string, userId str } if secret != nil { + log.Info().Msgf("secrets already exists for discovery-engine license for user-id: %s", userId) return secret, nil } t := true @@ -567,6 +568,7 @@ func CreateLicenseSecret(k8sClient *kubernetes.Clientset, key string, userId str log.Error().Msgf("error while creating secret for license key, error: %s", err.Error()) return nil, err } + log.Info().Msgf("secret created successfully for discovery-engine") return secret, nil } diff --git a/src/license/license.go b/src/license/license.go index fb0cfb6d..3ad551be 100644 --- a/src/license/license.go +++ b/src/license/license.go @@ -9,13 +9,16 @@ import ( "github.com/rs/zerolog/log" "k8s.io/client-go/kubernetes" "strings" + "time" ) // For testing purpose var publicKey = "-----BEGIN PUBLIC KEY-----\nMIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHUc95xoPHqsuC3zLfCSHHJ9F/Gx\nlJdyBkns1wDYCLY8yX1vvZndfDP9br3dbFKOaYOYmF9e0gKcDpGItdBQe+TVX9ol\nM3S23yD/xHNKw+f88KjI0dPnj3IRgqajd5eBMhNNugRFzRKWBBLCflukm7CfjzUP\nX1jQ/NCkoTwjScpJAgMBAAE=\n-----END PUBLIC KEY-----" -type ConfigLicense struct { +type LicenseConfig struct { k8sClient *kubernetes.Clientset + Tkn *Token + Lcs *License } type License struct { @@ -24,22 +27,25 @@ type License struct { PlatformUUID string } -var cfg *ConfigLicense -var Tkn *Token +var LCfg *LicenseConfig func InitializeConfig(k8sClient *kubernetes.Clientset) { - cfg = &ConfigLicense{k8sClient: k8sClient} + LCfg = &LicenseConfig{ + k8sClient: k8sClient, + Tkn: nil, + Lcs: nil, + } } func CheckLicenseSecret() error { log.Info().Msgf("fetching license secrets to validate discovery-engine licensing") - secret, err := cluster.GetSecrets(cfg.k8sClient, "app=discovery-engine") + secret, err := cluster.GetSecrets(LCfg.k8sClient, "app=discovery-engine") if err != nil { log.Error().Msgf("error while fetching secrets for discovery engine licensing, error: %s", err.Error()) return err } if secret == nil { - return nil + return errors.New("license secret doesn't exist for discovery-engine") } l := &License{ @@ -52,14 +58,28 @@ func CheckLicenseSecret() error { log.Error().Msgf("error while validating license retrieved through secrets, error: %s", err.Error()) return err } - log.Info().Msgf("license validation successfully for user-id: %s with key: %s", l.UserId, l.Key) + // Initialize to global config only after validation is done. + LCfg.Lcs = l + log.Info().Msgf("license validation successfully for user-id: %s with key: %s", LCfg.Lcs.UserId, LCfg.Lcs.Key) return nil } func (l *License) ValidateLicense() error { var err error - l.PlatformUUID, err = cfg.getKubeSystemUUID() + if checkExistingLicense() { + if !LCfg.Tkn.checkExpiration() { + err = fmt.Errorf("valid license already exists with user-id: %s, key: %s and platform uuid: %s", LCfg.Lcs.UserId, LCfg.Lcs.Key, LCfg.Lcs.PlatformUUID) + log.Error().Msgf("%s", err) + return err + } + err = removeSecretsConfig() + if err != nil { + return err + } + } + + l.PlatformUUID, err = LCfg.getKubeSystemUUID() if err != nil { log.Error().Msgf("error while fetching uuid of kube-system namespace, error: %s", err.Error()) return err @@ -71,7 +91,7 @@ func (l *License) ValidateLicense() error { return err } - Tkn, err = validateToken(decryptedKey, l.UserId) + LCfg.Tkn, err = validateToken(decryptedKey, l.UserId) if err != nil { log.Error().Msgf("error while validating jwt token") return err @@ -79,17 +99,19 @@ func (l *License) ValidateLicense() error { log.Info().Msgf("license validation successfully for user: %s with license key: %s", l.UserId, l.Key) - secret, err := cluster.CreateLicenseSecret(cfg.k8sClient, l.Key, l.UserId) + secret, err := cluster.CreateLicenseSecret(LCfg.k8sClient, l.Key, l.UserId) if err != nil { log.Error().Msgf("error while creating secret for discovery engine license, error: %s", err.Error()) return err } + // Initialize to global config only after validation is done. + LCfg.Lcs = l - log.Info().Msgf("secret created for discovery engine license with name: %s and uuid: %s", secret.GetName(), secret.GetUID()) + log.Info().Msgf("secret for discovery engine license with name: %s and uuid: %s", secret.GetName(), secret.GetUID()) return nil } -func (cfg *ConfigLicense) getKubeSystemUUID() (string, error) { +func (cfg *LicenseConfig) getKubeSystemUUID() (string, error) { uuid, err := cluster.GetKubeSystemUUID(cfg.k8sClient) if err != nil { log.Error().Msgf("error while fetching uuid of kube-system namespace, error: %s", err.Error()) @@ -110,12 +132,17 @@ func decryptKey(key string, platformUUID string) (string, error) { type Token struct { jwt *jwt.Token - claims *jwt.MapClaims + claims *Claims +} + +type Claims struct { + Features []string `json:"features"` + *jwt.RegisteredClaims } func validateToken(decryptedKey string, userId string) (*Token, error) { - claims := jwt.MapClaims{} + claims := &Claims{} key, err := jwt.ParseRSAPublicKeyFromPEM([]byte(publicKey)) if err != nil { @@ -135,7 +162,7 @@ func validateToken(decryptedKey string, userId string) (*Token, error) { Tkn := &Token{ jwt: jwtToken, - claims: &claims, + claims: claims, } err = Tkn.validateClaims(userId) @@ -170,10 +197,52 @@ func (t *Token) validateUserId(userId string) error { } -func (t *Token) getFeatures() []string { - return nil +func (t *Token) getFeatures() ([]string, error) { + features := t.claims.Features + return features, nil } -func WatchFeatures(features []string, expTime string) error { +func (cfg *LicenseConfig) WatchFeatures() bool { + + for { + //time.Sleep(500 * time.Millisecond) + if cfg.Lcs == nil || cfg.Tkn == nil { + continue + } + + if !cfg.Tkn.checkExpiration() { + log.Info().Msgf("valid license exists for discovery-engine") + return true + } + } + +} + +func (t *Token) checkExpiration() bool { + exp, err := LCfg.Tkn.claims.RegisteredClaims.GetExpirationTime() + if err != nil { + log.Error().Msgf("error while getting expiration time for license, error: %s", err.Error()) + return true + } + if exp.Before(time.Now()) { + return true + } + return false +} + +func checkExistingLicense() bool { + if LCfg.Lcs != nil && LCfg.Tkn != nil { + return true + } + return false +} + +func removeSecretsConfig() error { + err := cluster.DeleteSecrets(LCfg.k8sClient, "app=discovery-engine") + if err != nil { + return err + } + LCfg.Lcs = nil + LCfg.Tkn = nil return nil } diff --git a/src/license/server.go b/src/license/server.go index 74392053..aa940ce8 100644 --- a/src/license/server.go +++ b/src/license/server.go @@ -2,29 +2,72 @@ package license import ( "context" + "errors" ipb "github.com/accuknox/auto-policy-discovery/src/protobuf/v1/license" "github.com/rs/zerolog/log" + "time" ) type Server struct { ipb.UnimplementedLicenseServer } -func (ls *Server) InstallLicense(ctx context.Context, lr *ipb.LicenseRequest) (*ipb.LicenseResponse, error) { +func (ls *Server) InstallLicense(ctx context.Context, lr *ipb.LicenseInstallRequest) (*ipb.LicenseInstallResponse, error) { log.Info().Msgf("request received to install license for user-id: %s", lr.UserId) - l := License{ + l := &License{ UserId: lr.UserId, Key: lr.Key, } err := l.ValidateLicense() if err != nil { - return &ipb.LicenseResponse{ + return &ipb.LicenseInstallResponse{ Res: -1, Message: "error while validating license", }, err } - return &ipb.LicenseResponse{ + return &ipb.LicenseInstallResponse{ Res: 0, Message: "license installed successfully", }, nil } + +func (ls *Server) GetLicenseStatus(ctx context.Context, lr *ipb.LicenseStatusRequest) (*ipb.LicenseStatusResponse, error) { + log.Info().Msgf("request received to fetch the status of license") + if LCfg.Lcs == nil || LCfg.Tkn == nil { + return nil, errors.New("error while fetching status, no license secrets exists") + } + + iAt, err := LCfg.Tkn.claims.RegisteredClaims.GetIssuedAt() + if err != nil { + log.Error().Msgf("error while getting issued time for license, error: %s", err.Error()) + return nil, err + } + + exp, err := LCfg.Tkn.claims.RegisteredClaims.GetExpirationTime() + if err != nil { + log.Error().Msgf("error while getting expiration time for license, error: %s", err.Error()) + return nil, err + } + + features, err := LCfg.Tkn.getFeatures() + if err != nil || features == nil { + log.Error().Msgf("error while getting features that are supported in license, error: %s", err.Error()) + return nil, err + + } + + var status string + if exp.After(time.Now()) { + status = "Active" + } + + return &ipb.LicenseStatusResponse{ + Key: LCfg.Lcs.Key, + UserId: LCfg.Lcs.UserId, + PlatformUUID: LCfg.Lcs.PlatformUUID, + IssuedAt: iAt.String(), + Expiration: exp.String(), + Features: features, + Status: status, + }, nil +} diff --git a/src/main.go b/src/main.go index 5d95ddc7..1b611457 100644 --- a/src/main.go +++ b/src/main.go @@ -3,18 +3,18 @@ package main import ( "github.com/accuknox/auto-policy-discovery/src/cluster" "github.com/accuknox/auto-policy-discovery/src/config" + "github.com/accuknox/auto-policy-discovery/src/libs" "github.com/accuknox/auto-policy-discovery/src/license" + logger "github.com/accuknox/auto-policy-discovery/src/logging" + grpcserver "github.com/accuknox/auto-policy-discovery/src/server" + "github.com/spf13/viper" + "google.golang.org/grpc" "math/rand" "net" "os" "time" - libs "github.com/accuknox/auto-policy-discovery/src/libs" - logger "github.com/accuknox/auto-policy-discovery/src/logging" - grpcserver "github.com/accuknox/auto-policy-discovery/src/server" - "github.com/rs/zerolog" - "github.com/spf13/viper" ) var cfg cluster.Config @@ -55,12 +55,26 @@ func init() { func main() { + lis, server := CreateListenerAndGrpcServer() + // add license server + server = grpcserver.AddLicenseServer(server) + // check for license secret, if exist then validate err := license.CheckLicenseSecret() + if err != nil { - log.Error().Msgf("error while validating license, error: %s", err.Error()) + log.Error().Msgf("error while validating license secrets for discovery engine, error: %s", err.Error()) + go serve(lis, server) + _ = license.LCfg.WatchFeatures() + os.Exit(1) } + server = grpcserver.AddServers(server) + serve(lis, server) + +} + +func CreateListenerAndGrpcServer() (net.Listener, *grpc.Server) { // create server lis, err := net.Listen("tcp", ":"+grpcserver.PortNumber) if err != nil { @@ -70,15 +84,12 @@ func main() { // starts grpc server server := grpcserver.StartGrpcServer() - // add license server - server = grpcserver.AddLicenseServer(server) - server = grpcserver.AddServers(server) + return lis, server +} - // start autopolicy service - log.Info().Msgf("gRPC server on %s port started", grpcserver.PortNumber) +func serve(lis net.Listener, server *grpc.Server) { if err := server.Serve(lis); err != nil { log.Error().Msgf("Failed to serve: %v", err) } - } diff --git a/src/protobuf/v1/license/license.pb.go b/src/protobuf/v1/license/license.pb.go index bf5a83b7..e67c283c 100644 --- a/src/protobuf/v1/license/license.pb.go +++ b/src/protobuf/v1/license/license.pb.go @@ -20,7 +20,7 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type LicenseRequest struct { +type LicenseInstallRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -29,8 +29,8 @@ type LicenseRequest struct { UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"` } -func (x *LicenseRequest) Reset() { - *x = LicenseRequest{} +func (x *LicenseInstallRequest) Reset() { + *x = LicenseInstallRequest{} if protoimpl.UnsafeEnabled { mi := &file_v1_license_license_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -38,13 +38,13 @@ func (x *LicenseRequest) Reset() { } } -func (x *LicenseRequest) String() string { +func (x *LicenseInstallRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*LicenseRequest) ProtoMessage() {} +func (*LicenseInstallRequest) ProtoMessage() {} -func (x *LicenseRequest) ProtoReflect() protoreflect.Message { +func (x *LicenseInstallRequest) ProtoReflect() protoreflect.Message { mi := &file_v1_license_license_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -56,26 +56,26 @@ func (x *LicenseRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use LicenseRequest.ProtoReflect.Descriptor instead. -func (*LicenseRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use LicenseInstallRequest.ProtoReflect.Descriptor instead. +func (*LicenseInstallRequest) Descriptor() ([]byte, []int) { return file_v1_license_license_proto_rawDescGZIP(), []int{0} } -func (x *LicenseRequest) GetKey() string { +func (x *LicenseInstallRequest) GetKey() string { if x != nil { return x.Key } return "" } -func (x *LicenseRequest) GetUserId() string { +func (x *LicenseInstallRequest) GetUserId() string { if x != nil { return x.UserId } return "" } -type LicenseResponse struct { +type LicenseInstallResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -84,8 +84,8 @@ type LicenseResponse struct { Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` } -func (x *LicenseResponse) Reset() { - *x = LicenseResponse{} +func (x *LicenseInstallResponse) Reset() { + *x = LicenseInstallResponse{} if protoimpl.UnsafeEnabled { mi := &file_v1_license_license_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -93,13 +93,13 @@ func (x *LicenseResponse) Reset() { } } -func (x *LicenseResponse) String() string { +func (x *LicenseInstallResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*LicenseResponse) ProtoMessage() {} +func (*LicenseInstallResponse) ProtoMessage() {} -func (x *LicenseResponse) ProtoReflect() protoreflect.Message { +func (x *LicenseInstallResponse) ProtoReflect() protoreflect.Message { mi := &file_v1_license_license_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -111,49 +111,204 @@ func (x *LicenseResponse) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use LicenseResponse.ProtoReflect.Descriptor instead. -func (*LicenseResponse) Descriptor() ([]byte, []int) { +// Deprecated: Use LicenseInstallResponse.ProtoReflect.Descriptor instead. +func (*LicenseInstallResponse) Descriptor() ([]byte, []int) { return file_v1_license_license_proto_rawDescGZIP(), []int{1} } -func (x *LicenseResponse) GetRes() int32 { +func (x *LicenseInstallResponse) GetRes() int32 { if x != nil { return x.Res } return 0 } -func (x *LicenseResponse) GetMessage() string { +func (x *LicenseInstallResponse) GetMessage() string { if x != nil { return x.Message } return "" } +type LicenseStatusRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *LicenseStatusRequest) Reset() { + *x = LicenseStatusRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_license_license_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LicenseStatusRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LicenseStatusRequest) ProtoMessage() {} + +func (x *LicenseStatusRequest) ProtoReflect() protoreflect.Message { + mi := &file_v1_license_license_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LicenseStatusRequest.ProtoReflect.Descriptor instead. +func (*LicenseStatusRequest) Descriptor() ([]byte, []int) { + return file_v1_license_license_proto_rawDescGZIP(), []int{2} +} + +type LicenseStatusResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"` + PlatformUUID string `protobuf:"bytes,3,opt,name=platformUUID,proto3" json:"platformUUID,omitempty"` + IssuedAt string `protobuf:"bytes,4,opt,name=issuedAt,proto3" json:"issuedAt,omitempty"` + Expiration string `protobuf:"bytes,5,opt,name=expiration,proto3" json:"expiration,omitempty"` + Features []string `protobuf:"bytes,6,rep,name=features,proto3" json:"features,omitempty"` + Status string `protobuf:"bytes,7,opt,name=status,proto3" json:"status,omitempty"` +} + +func (x *LicenseStatusResponse) Reset() { + *x = LicenseStatusResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_license_license_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LicenseStatusResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LicenseStatusResponse) ProtoMessage() {} + +func (x *LicenseStatusResponse) ProtoReflect() protoreflect.Message { + mi := &file_v1_license_license_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LicenseStatusResponse.ProtoReflect.Descriptor instead. +func (*LicenseStatusResponse) Descriptor() ([]byte, []int) { + return file_v1_license_license_proto_rawDescGZIP(), []int{3} +} + +func (x *LicenseStatusResponse) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *LicenseStatusResponse) GetUserId() string { + if x != nil { + return x.UserId + } + return "" +} + +func (x *LicenseStatusResponse) GetPlatformUUID() string { + if x != nil { + return x.PlatformUUID + } + return "" +} + +func (x *LicenseStatusResponse) GetIssuedAt() string { + if x != nil { + return x.IssuedAt + } + return "" +} + +func (x *LicenseStatusResponse) GetExpiration() string { + if x != nil { + return x.Expiration + } + return "" +} + +func (x *LicenseStatusResponse) GetFeatures() []string { + if x != nil { + return x.Features + } + return nil +} + +func (x *LicenseStatusResponse) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + var File_v1_license_license_proto protoreflect.FileDescriptor var file_v1_license_license_proto_rawDesc = []byte{ 0x0a, 0x18, 0x76, 0x31, 0x2f, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2f, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x76, 0x31, 0x2e, 0x6c, - 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x22, 0x3a, 0x0a, 0x0e, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, - 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, - 0x49, 0x64, 0x22, 0x3d, 0x0a, 0x0f, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x03, 0x72, 0x65, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, - 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x32, 0x54, 0x0a, 0x07, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x0e, - 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x12, 0x1a, - 0x2e, 0x76, 0x31, 0x2e, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x6c, 0x69, 0x63, 0x65, - 0x6e, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x76, 0x31, 0x2e, - 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x43, 0x5a, 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x63, 0x63, 0x75, 0x6b, 0x6e, 0x6f, 0x78, 0x2f, 0x61, - 0x75, 0x74, 0x6f, 0x2d, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2d, 0x64, 0x69, 0x73, 0x63, 0x6f, - 0x76, 0x65, 0x72, 0x79, 0x2f, 0x73, 0x72, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2f, 0x76, 0x31, 0x2f, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x22, 0x41, 0x0a, 0x15, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, + 0x65, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x44, 0x0a, 0x16, 0x4c, 0x69, 0x63, + 0x65, 0x6e, 0x73, 0x65, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x03, 0x72, 0x65, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, + 0x16, 0x0a, 0x14, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0xd5, 0x01, 0x0a, 0x15, 0x4c, 0x69, 0x63, 0x65, + 0x6e, 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x22, 0x0a, 0x0c, 0x70, + 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x55, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0c, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x55, 0x49, 0x44, 0x12, + 0x1a, 0x0a, 0x08, 0x69, 0x73, 0x73, 0x75, 0x65, 0x64, 0x41, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x69, 0x73, 0x73, 0x75, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x65, + 0x78, 0x70, 0x69, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0a, 0x65, 0x78, 0x70, 0x69, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x66, + 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x66, + 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x32, + 0xbb, 0x01, 0x0a, 0x07, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x12, 0x57, 0x0a, 0x0e, 0x49, + 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x2e, + 0x76, 0x31, 0x2e, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x4c, 0x69, 0x63, 0x65, 0x6e, + 0x73, 0x65, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x22, 0x2e, 0x76, 0x31, 0x2e, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x4c, 0x69, + 0x63, 0x65, 0x6e, 0x73, 0x65, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x57, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x63, 0x65, 0x6e, + 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x20, 0x2e, 0x76, 0x31, 0x2e, 0x6c, 0x69, + 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x76, 0x31, 0x2e, + 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2e, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x43, 0x5a, + 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x63, 0x63, 0x75, + 0x6b, 0x6e, 0x6f, 0x78, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x2d, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, + 0x2d, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2f, 0x73, 0x72, 0x63, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x31, 0x2f, 0x6c, 0x69, 0x63, 0x65, 0x6e, + 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -168,16 +323,20 @@ func file_v1_license_license_proto_rawDescGZIP() []byte { return file_v1_license_license_proto_rawDescData } -var file_v1_license_license_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_v1_license_license_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_v1_license_license_proto_goTypes = []interface{}{ - (*LicenseRequest)(nil), // 0: v1.license.licenseRequest - (*LicenseResponse)(nil), // 1: v1.license.LicenseResponse + (*LicenseInstallRequest)(nil), // 0: v1.license.LicenseInstallRequest + (*LicenseInstallResponse)(nil), // 1: v1.license.LicenseInstallResponse + (*LicenseStatusRequest)(nil), // 2: v1.license.LicenseStatusRequest + (*LicenseStatusResponse)(nil), // 3: v1.license.LicenseStatusResponse } var file_v1_license_license_proto_depIdxs = []int32{ - 0, // 0: v1.license.License.InstallLicense:input_type -> v1.license.licenseRequest - 1, // 1: v1.license.License.InstallLicense:output_type -> v1.license.LicenseResponse - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type + 0, // 0: v1.license.License.InstallLicense:input_type -> v1.license.LicenseInstallRequest + 2, // 1: v1.license.License.GetLicenseStatus:input_type -> v1.license.LicenseStatusRequest + 1, // 2: v1.license.License.InstallLicense:output_type -> v1.license.LicenseInstallResponse + 3, // 3: v1.license.License.GetLicenseStatus:output_type -> v1.license.LicenseStatusResponse + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -190,7 +349,7 @@ func file_v1_license_license_proto_init() { } if !protoimpl.UnsafeEnabled { file_v1_license_license_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LicenseRequest); i { + switch v := v.(*LicenseInstallRequest); i { case 0: return &v.state case 1: @@ -202,7 +361,31 @@ func file_v1_license_license_proto_init() { } } file_v1_license_license_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LicenseResponse); i { + switch v := v.(*LicenseInstallResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_v1_license_license_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LicenseStatusRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_v1_license_license_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LicenseStatusResponse); i { case 0: return &v.state case 1: @@ -220,7 +403,7 @@ func file_v1_license_license_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_v1_license_license_proto_rawDesc, NumEnums: 0, - NumMessages: 2, + NumMessages: 4, NumExtensions: 0, NumServices: 1, }, diff --git a/src/protobuf/v1/license/license.proto b/src/protobuf/v1/license/license.proto index 915386d2..adb89cbb 100644 --- a/src/protobuf/v1/license/license.proto +++ b/src/protobuf/v1/license/license.proto @@ -5,17 +5,29 @@ package v1.license; option go_package = "github.com/accuknox/auto-policy-discovery/src/protobuf/v1/license"; -message licenseRequest{ +message LicenseInstallRequest{ string key=1; string userId=2; } service License{ - rpc InstallLicense(licenseRequest) returns (LicenseResponse); - rpc GetLicenseStatus(licenseRequest) returns (LicenseResponse); + rpc InstallLicense(LicenseInstallRequest) returns (LicenseInstallResponse); + rpc GetLicenseStatus(LicenseStatusRequest) returns (LicenseStatusResponse); } -message LicenseResponse{ +message LicenseInstallResponse{ int32 res=1; string message=2; +} + +message LicenseStatusRequest{} + +message LicenseStatusResponse{ + string key=1; + string userId=2; + string platformUUID=3; + string issuedAt=4; + string expiration=5; + repeated string features=6; + string status=7; } \ No newline at end of file diff --git a/src/protobuf/v1/license/license_grpc.pb.go b/src/protobuf/v1/license/license_grpc.pb.go index baa3f54e..4ae760b8 100644 --- a/src/protobuf/v1/license/license_grpc.pb.go +++ b/src/protobuf/v1/license/license_grpc.pb.go @@ -19,14 +19,16 @@ import ( const _ = grpc.SupportPackageIsVersion7 const ( - License_InstallLicense_FullMethodName = "/v1.license.License/InstallLicense" + License_InstallLicense_FullMethodName = "/v1.license.License/InstallLicense" + License_GetLicenseStatus_FullMethodName = "/v1.license.License/GetLicenseStatus" ) // LicenseClient is the client API for License service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type LicenseClient interface { - InstallLicense(ctx context.Context, in *LicenseRequest, opts ...grpc.CallOption) (*LicenseResponse, error) + InstallLicense(ctx context.Context, in *LicenseInstallRequest, opts ...grpc.CallOption) (*LicenseInstallResponse, error) + GetLicenseStatus(ctx context.Context, in *LicenseStatusRequest, opts ...grpc.CallOption) (*LicenseStatusResponse, error) } type licenseClient struct { @@ -37,8 +39,8 @@ func NewLicenseClient(cc grpc.ClientConnInterface) LicenseClient { return &licenseClient{cc} } -func (c *licenseClient) InstallLicense(ctx context.Context, in *LicenseRequest, opts ...grpc.CallOption) (*LicenseResponse, error) { - out := new(LicenseResponse) +func (c *licenseClient) InstallLicense(ctx context.Context, in *LicenseInstallRequest, opts ...grpc.CallOption) (*LicenseInstallResponse, error) { + out := new(LicenseInstallResponse) err := c.cc.Invoke(ctx, License_InstallLicense_FullMethodName, in, out, opts...) if err != nil { return nil, err @@ -46,11 +48,21 @@ func (c *licenseClient) InstallLicense(ctx context.Context, in *LicenseRequest, return out, nil } +func (c *licenseClient) GetLicenseStatus(ctx context.Context, in *LicenseStatusRequest, opts ...grpc.CallOption) (*LicenseStatusResponse, error) { + out := new(LicenseStatusResponse) + err := c.cc.Invoke(ctx, License_GetLicenseStatus_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // LicenseServer is the server API for License service. // All implementations must embed UnimplementedLicenseServer // for forward compatibility type LicenseServer interface { - InstallLicense(context.Context, *LicenseRequest) (*LicenseResponse, error) + InstallLicense(context.Context, *LicenseInstallRequest) (*LicenseInstallResponse, error) + GetLicenseStatus(context.Context, *LicenseStatusRequest) (*LicenseStatusResponse, error) mustEmbedUnimplementedLicenseServer() } @@ -58,9 +70,12 @@ type LicenseServer interface { type UnimplementedLicenseServer struct { } -func (UnimplementedLicenseServer) InstallLicense(context.Context, *LicenseRequest) (*LicenseResponse, error) { +func (UnimplementedLicenseServer) InstallLicense(context.Context, *LicenseInstallRequest) (*LicenseInstallResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method InstallLicense not implemented") } +func (UnimplementedLicenseServer) GetLicenseStatus(context.Context, *LicenseStatusRequest) (*LicenseStatusResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetLicenseStatus not implemented") +} func (UnimplementedLicenseServer) mustEmbedUnimplementedLicenseServer() {} // UnsafeLicenseServer may be embedded to opt out of forward compatibility for this service. @@ -75,7 +90,7 @@ func RegisterLicenseServer(s grpc.ServiceRegistrar, srv LicenseServer) { } func _License_InstallLicense_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LicenseRequest) + in := new(LicenseInstallRequest) if err := dec(in); err != nil { return nil, err } @@ -87,7 +102,25 @@ func _License_InstallLicense_Handler(srv interface{}, ctx context.Context, dec f FullMethod: License_InstallLicense_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LicenseServer).InstallLicense(ctx, req.(*LicenseRequest)) + return srv.(LicenseServer).InstallLicense(ctx, req.(*LicenseInstallRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _License_GetLicenseStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LicenseStatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LicenseServer).GetLicenseStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: License_GetLicenseStatus_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LicenseServer).GetLicenseStatus(ctx, req.(*LicenseStatusRequest)) } return interceptor(ctx, in, info, handler) } @@ -103,6 +136,10 @@ var License_ServiceDesc = grpc.ServiceDesc{ MethodName: "InstallLicense", Handler: _License_InstallLicense_Handler, }, + { + MethodName: "GetLicenseStatus", + Handler: _License_GetLicenseStatus_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "v1/license/license.proto", diff --git a/src/src b/src/src deleted file mode 100755 index e7dc5126..00000000 Binary files a/src/src and /dev/null differ