-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Disk Manager] sync test/mocks/compute, test/mocks/kms
- Loading branch information
1 parent
2137d52
commit 974ff48
Showing
5 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
GO_PROGRAM(compute-mock) | ||
|
||
SRCS( | ||
main.go | ||
) | ||
|
||
END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
GO_PROGRAM(kms-mock) | ||
|
||
SRCS( | ||
main.go | ||
) | ||
|
||
END() |