Skip to content

Commit

Permalink
[Disk Manager] sync test/mocks/compute, test/mocks/kms
Browse files Browse the repository at this point in the history
  • Loading branch information
SvartMetal committed Dec 19, 2023
1 parent 2137d52 commit 974ff48
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 0 deletions.
17 changes: 17 additions & 0 deletions build/platform/test_tool/host_os.ya.make.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
IF (HOST_OS_DARWIN AND HOST_ARCH_X86_64)
DECLARE_EXTERNAL_RESOURCE(TEST_TOOL_HOST sbr:5545693048)
DECLARE_EXTERNAL_RESOURCE(TEST_TOOL3_HOST sbr:5545693048)
ELSEIF (HOST_OS_DARWIN AND HOST_ARCH_ARM64)
DECLARE_EXTERNAL_RESOURCE(TEST_TOOL_HOST sbr:5545692674)
DECLARE_EXTERNAL_RESOURCE(TEST_TOOL3_HOST sbr:5545692674)
ELSEIF (HOST_OS_LINUX AND HOST_ARCH_X86_64)
DECLARE_EXTERNAL_RESOURCE(TEST_TOOL_HOST sbr:5545693767)
DECLARE_EXTERNAL_RESOURCE(TEST_TOOL3_HOST sbr:5545693767)
ELSEIF (HOST_OS_LINUX AND HOST_ARCH_AARCH64)
DECLARE_EXTERNAL_RESOURCE(TEST_TOOL_HOST sbr:5545692313)
DECLARE_EXTERNAL_RESOURCE(TEST_TOOL3_HOST sbr:5545692313)
ELSEIF (HOST_OS_WINDOWS AND HOST_ARCH_X86_64)
DECLARE_EXTERNAL_RESOURCE(TEST_TOOL_HOST sbr:5545693355)
DECLARE_EXTERNAL_RESOURCE(TEST_TOOL3_HOST sbr:5545693355)

ENDIF()
67 changes: 67 additions & 0 deletions cloud/disk_manager/test/mocks/compute/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"context"
"fmt"
"log"
"net"

"github.com/spf13/cobra"
"github.com/ydb-platform/nbs/contrib/ydb/public/api/client/yc_private/compute/inner"
"google.golang.org/grpc"
)

////////////////////////////////////////////////////////////////////////////////

type computeService struct {
}

func (s *computeService) CreateToken(
ctx context.Context,
req *compute.CreateTokenRequest,
) (*compute.CreateTokenResponse, error) {

log.Printf("get CreateToken request: %v", req)
return &compute.CreateTokenResponse{
Token: "token-from-compute-mock",
}, nil
}

////////////////////////////////////////////////////////////////////////////////

func run(port uint32) error {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
return fmt.Errorf("failed to listen on %v: %w", port, err)
}

log.Printf("listening on %v", lis.Addr().String())

srv := grpc.NewServer()
compute.RegisterDiskServiceServer(srv, &computeService{})

return srv.Serve(lis)
}

////////////////////////////////////////////////////////////////////////////////

func main() {
log.Println("launching compute-mock")

var port uint32
var rootCmd = &cobra.Command{
Use: "compute-mock",
Short: "Mock for Compute",
Run: func(cmd *cobra.Command, args []string) {
err := run(port)
if err != nil {
log.Fatalf("Error: %v", err)
}
},
}
rootCmd.Flags().Uint32Var(&port, "port", 4201, "server port")

if err := rootCmd.Execute(); err != nil {
log.Fatalf("Error: %v", err)
}
}
7 changes: 7 additions & 0 deletions cloud/disk_manager/test/mocks/compute/ya.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GO_PROGRAM(compute-mock)

SRCS(
main.go
)

END()
148 changes: 148 additions & 0 deletions cloud/disk_manager/test/mocks/kms/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package main

import (
"context"
"fmt"
"log"
"net"

"github.com/spf13/cobra"
"github.com/ydb-platform/nbs/contrib/ydb/public/api/client/yc_private/kms"
"google.golang.org/grpc"
grpc_codes "google.golang.org/grpc/codes"
grpc_status "google.golang.org/grpc/status"
)

////////////////////////////////////////////////////////////////////////////////

type kmsService struct {
}

func (s *kmsService) Encrypt(
ctx context.Context,
req *kms.SymmetricEncryptRequest,
) (*kms.SymmetricEncryptResponse, error) {

return nil, grpc_status.Error(
grpc_codes.Unimplemented,
"Encrypt not implemented",
)
}

func (s *kmsService) Decrypt(
ctx context.Context,
req *kms.SymmetricDecryptRequest,
) (*kms.SymmetricDecryptResponse, error) {

log.Printf("get Decrypt request: %v", req)
return &kms.SymmetricDecryptResponse{
KeyId: req.KeyId,
VersionId: req.KeyId + "-version-id",
Plaintext: []byte("12345678901234567890123456789012"),
}, nil
}

func (s *kmsService) BatchEncrypt(
ctx context.Context,
req *kms.SymmetricBatchEncryptRequest,
) (*kms.SymmetricBatchEncryptResponse, error) {

return nil, grpc_status.Error(
grpc_codes.Unimplemented,
"BatchEncrypt not implemented",
)
}

func (s *kmsService) BatchDecrypt(
ctx context.Context,
req *kms.SymmetricBatchDecryptRequest,
) (*kms.SymmetricBatchDecryptResponse, error) {

return nil, grpc_status.Error(
grpc_codes.Unimplemented,
"BatchDecrypt not implemented",
)
}

func (s *kmsService) ReEncrypt(
ctx context.Context,
req *kms.SymmetricReEncryptRequest,
) (*kms.SymmetricReEncryptResponse, error) {

return nil, grpc_status.Error(
grpc_codes.Unimplemented,
"ReEncrypt not implemented",
)
}

func (s *kmsService) GenerateDataKey(
ctx context.Context,
req *kms.GenerateDataKeyRequest,
) (*kms.GenerateDataKeyResponse, error) {

return nil, grpc_status.Error(
grpc_codes.Unimplemented,
"GenerateDataKey not implemented",
)
}

func (s *kmsService) GenerateRandom(
ctx context.Context,
req *kms.GenerateRandomRequest,
) (*kms.GenerateRandomResponse, error) {

return nil, grpc_status.Error(
grpc_codes.Unimplemented,
"GenerateRandom not implemented",
)
}

func (s *kmsService) GenerateAsymmetricDataKey(
ctx context.Context,
req *kms.GenerateAsymmetricDataKeyRequest,
) (*kms.GenerateAsymmetricDataKeyResponse, error) {

return nil, grpc_status.Error(
grpc_codes.Unimplemented,
"GenerateAsymmetricDataKey not implemented",
)
}

////////////////////////////////////////////////////////////////////////////////

func run(port uint32) error {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
return fmt.Errorf("failed to listen on %v: %w", port, err)
}

log.Printf("listening on %v", lis.Addr().String())

srv := grpc.NewServer()
kms.RegisterSymmetricCryptoServiceServer(srv, &kmsService{})

return srv.Serve(lis)
}

////////////////////////////////////////////////////////////////////////////////

func main() {
log.Println("launching kms-mock")

var port uint32
var rootCmd = &cobra.Command{
Use: "kms-mock",
Short: "Mock for KMS",
Run: func(cmd *cobra.Command, args []string) {
err := run(port)
if err != nil {
log.Fatalf("Error: %v", err)
}
},
}
rootCmd.Flags().Uint32Var(&port, "port", 4202, "server port")

if err := rootCmd.Execute(); err != nil {
log.Fatalf("Error: %v", err)
}
}
7 changes: 7 additions & 0 deletions cloud/disk_manager/test/mocks/kms/ya.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GO_PROGRAM(kms-mock)

SRCS(
main.go
)

END()

0 comments on commit 974ff48

Please sign in to comment.