Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/envd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ generate:
echo "buf is not installed. Do you want to install it? (Y/n): "; \
read choice; \
if [ "$$choice" = "Y" ]; then \
go install github.com/bufbuild/buf/cmd/buf@latest && \
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@latest; \
go install github.com/bufbuild/buf/cmd/buf@v1.50.1 && \
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1 && \
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@v1.18.1; \
else \
exit 1; \
fi; \
Expand Down
33 changes: 32 additions & 1 deletion packages/envd/internal/services/filesystem/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"strings"

"github.com/e2b-dev/infra/packages/envd/internal/permissions"
rpc "github.com/e2b-dev/infra/packages/envd/internal/services/spec/filesystem"
Expand All @@ -13,6 +15,11 @@ import (
)

func (Service) ListDir(ctx context.Context, req *connect.Request[rpc.ListDirRequest]) (*connect.Response[rpc.ListDirResponse], error) {
depth := req.Msg.GetDepth()
if depth == 0 {
depth = 1 // default depth to current directory
}

u, err := permissions.GetAuthUser(ctx)
if err != nil {
return nil, err
Expand All @@ -36,7 +43,31 @@ func (Service) ListDir(ctx context.Context, req *connect.Request[rpc.ListDirRequ
return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("path is not a directory: %s", dirPath))
}

entries, err := os.ReadDir(dirPath)
var entries []os.DirEntry
err = filepath.WalkDir(dirPath, func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}

// Skip the root directory itself
if path == dirPath {
return nil
}

// Calculate current depth
relPath, err := filepath.Rel(dirPath, path)
if err != nil {
return err
}
currentDepth := len(strings.Split(relPath, string(os.PathSeparator)))

if currentDepth > int(depth) {
return filepath.SkipDir
}

entries = append(entries, d)
return nil
})
if err != nil {
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("error reading directory: %w", err))
}
Expand Down
251 changes: 130 additions & 121 deletions packages/envd/internal/services/spec/filesystem/filesystem.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/envd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (

var (
// These vars are automatically set by goreleaser.
Version = "0.1.5"
Version = "0.1.6"

commitSHA string

Expand Down
1 change: 1 addition & 0 deletions packages/envd/spec/filesystem/filesystem.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum FileType {

message ListDirRequest {
string path = 1;
uint32 depth = 2;
Comment thread
0div marked this conversation as resolved.
}

message ListDirResponse {
Expand Down
19 changes: 16 additions & 3 deletions tests/integration/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# Integration Tests

Package for defining integration tests. Currently, there is a setup for API and Orchestrator testing.

## Run locally
1) Setup env variables in the .env file
2) If necessary, run `make connect-orchestrator` to create a tunnel to one orchestrator client VM in GCP
3) Run `make test`

1. Setup env variables in the root folder `infra/.env` file
2. If you made changes to the `api` or `envd` protobuf spec, run `make generate` from this folder (and don't forget to generate it in `envd` if changes apply there too).
Comment thread
0div marked this conversation as resolved.
3. If necessary, run `make connect-orchestrator` to create a tunnel to one orchestrator client VM in GCP (you may need to run `make setup-ssh` the first time)
4. Run `make test` in this folder or `make test-integration` from the root `infra/` folder.

## Usage of clients (api, orchestrator, envd)

All tests are in the folder internal/tests. You can see the usage of different clients in the tests. Here are just basics.

### API

HTTP client. In order to pass the API key, use the `setup.WithAPIKey()` option.

```go
client := setup.GetAPIClient()

Expand All @@ -21,19 +27,24 @@ resp, err := client.PostSandboxesWithResponse(ctx, api.NewSandbox{
```

### Orchestrator

GRPC client. There is no authentication needed as it runs behind API in production.

```go
client := setup.GetOrchestratorClient(t, ctx)
resp, err := client.List(ctx, &emptypb.Empty{})
```

### Envd

Envd client is used for interacting with the sandbox.
There are two API types—HTTP and GRPC.
Each of them provides different methods for interacting with the sandbox; you need to check which ones you need.

#### HTTP

In order to access correct sandbox URL, you need to pass `setup.WithSandbox(...)` with the required arguments.

```go
client := setup.GetEnvdClient(t, ctx)
resp, err := client.HTTPClient.PostFilesWithBodyWithResponse(
Expand All @@ -44,10 +55,12 @@ resp, err := client.HTTPClient.PostFilesWithBodyWithResponse(
```

#### GRPC

In order to access correct sandbox URL, you need to call `setup.SetSandboxHeader(...)` with the required arguments.

All methods also expect a user (`user`/`root`) to be set in the header.
You can achieve it using `setup.SetUserHeader(...)`.

```go
client := setup.GetEnvdClient(t, ctx)
req := connect.NewRequest(&filesystem.ListDirRequest{
Expand Down
Loading
Loading