Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor keploy v2 codebase #1571

Merged
merged 190 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
190 commits
Select commit Hold shift + click to select a range
590b58a
chore: wip refactoring v2 codebase
slayerjain Feb 9, 2024
1786447
chore: refactor v2 cmds by removing duplicate code
slayerjain Feb 15, 2024
f32f9aa
chore: refactor the project structure and some interfaces
slayerjain Feb 16, 2024
95fb61c
chore: add arg names in intrumentation interface
slayerjain Feb 16, 2024
08c6a68
chore: add ctx to intrumentation.run method
slayerjain Feb 16, 2024
1f1dc21
chore: update pending subcommand with new structs
slayerjain Feb 16, 2024
2db7142
chore: add Hook interface to start hooks, proxy
gouravkrosx Feb 17, 2024
9db2554
chore: add register for mock and config comds
slayerjain Feb 17, 2024
bafcdf8
chore: rename module to server/v2 and add more interfaces
slayerjain Feb 17, 2024
fdfb852
chore: add record service impl
charankamarapu Feb 18, 2024
59b222e
chore: add mock-record service
charankamarapu Feb 18, 2024
dbb330f
chore: modularize proxy package
gouravkrosx Feb 18, 2024
4a9e255
chore: add testSetIds
charankamarapu Feb 19, 2024
c737b93
chore: implement app module to manage running apps
slayerjain Feb 19, 2024
43fb4ad
chore: update record
charankamarapu Feb 19, 2024
4a18412
chore: implement hooks module in core
slayerjain Feb 19, 2024
d5f6413
chore: implement run service
charankamarapu Feb 20, 2024
2516430
fix: add imports and test impl
charankamarapu Feb 20, 2024
d8da3db
chore: update record service
charankamarapu Feb 20, 2024
6af7299
chore: update record service
charankamarapu Feb 20, 2024
e257714
chore: add test service
charankamarapu Feb 20, 2024
3d1bdb8
chore: add mocktest and tools service
charankamarapu Feb 20, 2024
3d3531b
chore: refactor proxy and http parser
gouravkrosx Feb 20, 2024
8de02d4
chore: add err chan in test service
charankamarapu Feb 21, 2024
416a6db
chore: add treeDb to proxy
gouravkrosx Feb 21, 2024
de73280
chore: update integration interface
gouravkrosx Feb 21, 2024
4ef44d7
chore: update http parser
gouravkrosx Feb 22, 2024
bd22af1
chore: update generic parser
gouravkrosx Feb 22, 2024
c63e9a0
chore: add enum for integration type
gouravkrosx Feb 22, 2024
3f5bc90
style: refactored serve package
PranshuSrivastava Feb 22, 2024
86e3de6
Merge branch 'keploy-v2-refactor' of https://github.com/keploy/keploy…
PranshuSrivastava Feb 22, 2024
d44902b
chore: update postgres parser
gouravkrosx Feb 22, 2024
de61fd8
chore: initial refactoring of mysql parser
gouravkrosx Feb 22, 2024
7fed848
chore: initial refactoring of mongo parser
gouravkrosx Feb 22, 2024
aab80db
chore: update grpc parser
gouravkrosx Feb 23, 2024
3b1bbea
chore: update mongo parser
gouravkrosx Feb 23, 2024
e45371c
chore: update mysql parser
gouravkrosx Feb 23, 2024
6a787fb
reafactor:platform related changes (#1600)
shivamsouravjha Feb 24, 2024
9afe690
refactor: mock initaliser and filtering (#1615)
shivamsouravjha Feb 26, 2024
aeb1f58
chore: update panic recovery function across codebase
gouravkrosx Feb 26, 2024
1d7b565
chore: cli integration
charankamarapu Feb 26, 2024
1bf6912
chore: passed context in some functions
gouravkrosx Feb 26, 2024
cebb51f
chore: correct functions
charankamarapu Feb 26, 2024
20fdc32
chore: correct functions
charankamarapu Feb 26, 2024
f101f40
chore: integrate CLI
charankamarapu Feb 26, 2024
58ee935
chore: correct functions
charankamarapu Feb 27, 2024
ce8cc7e
chroe: remove unwanted files
charankamarapu Feb 27, 2024
25af8a7
chore: remove deployment folder
charankamarapu Feb 27, 2024
f327393
chore: update functions
charankamarapu Feb 27, 2024
800a4ca
chore: changed fucntion name
charankamarapu Feb 27, 2024
15b57be
chore: remove cycle dep
charankamarapu Feb 27, 2024
2d54785
fix: correct imports
charankamarapu Feb 27, 2024
ca25201
chore: add start to replay
charankamarapu Feb 27, 2024
7b51dee
chore: clean tele
charankamarapu Feb 27, 2024
f1f15d3
chore: go routine to DBs
charankamarapu Feb 27, 2024
c8da4ba
refactor:context cancell is create yaml (#1618)
shivamsouravjha Feb 27, 2024
3ea3db8
chore: go routine to DBs
charankamarapu Feb 27, 2024
c7727c1
chore: correct fucntion names
charankamarapu Feb 27, 2024
88881c3
chore: correct testDB fucntions
charankamarapu Feb 27, 2024
0548649
chore: remove extra fields in report
charankamarapu Feb 27, 2024
d62f0e0
refactor:using yaml defind write functions in report (#1627)
shivamsouravjha Feb 28, 2024
b8c2086
chore: refactor hooks, app, proxy
gouravkrosx Feb 28, 2024
bafb9ab
fix: mockdb functions
charankamarapu Feb 28, 2024
8e4439b
fix: db functions
charankamarapu Feb 28, 2024
5261c23
chore: add ctx in yaml
charankamarapu Feb 29, 2024
511d06b
chore: refactor apps,core
gouravkrosx Mar 1, 2024
c3e3cdb
chore: fix proxy port
gouravkrosx Mar 1, 2024
2c955ea
chore: refactor apps,core for userIP
gouravkrosx Mar 1, 2024
e212bc7
chore: add installationId
charankamarapu Mar 1, 2024
6e4f191
chore: remove compilation issues
gouravkrosx Mar 1, 2024
1747af8
chore: correct cli
charankamarapu Mar 2, 2024
c1f8941
chore: fix record command
charankamarapu Mar 2, 2024
63c3ce8
chore: fix bind bug
charankamarapu Mar 2, 2024
9770192
chore: update graphql server
gouravkrosx Mar 2, 2024
b5a98e5
chore: record working
gouravkrosx Mar 2, 2024
bb477a3
chore: releasing eBPF resources
gouravkrosx Mar 2, 2024
034c6a5
chore: releasing eBPF resources-2
gouravkrosx Mar 2, 2024
6823f18
chore: remove extra keploy path
charankamarapu Mar 3, 2024
6b9bbd2
chore: remove err log as parent is already doing it.
charankamarapu Mar 3, 2024
04c9ad9
chore: correct mocking
charankamarapu Mar 3, 2024
cb5d92b
chore: add todo
charankamarapu Mar 3, 2024
85f7f80
chore: fix reports
charankamarapu Mar 3, 2024
e02ca43
chore: remove unnecessary go for saving mocks
gouravkrosx Mar 4, 2024
3856fb1
chore: fix app errors
charankamarapu Mar 4, 2024
50ff9b6
chore: service update
charankamarapu Mar 4, 2024
2aa43bb
chore: correct record service
charankamarapu Mar 4, 2024
ef5572b
chore: correct record service
charankamarapu Mar 4, 2024
76c784c
chore: correct replay
charankamarapu Mar 4, 2024
c59468b
chore: add err grps
charankamarapu Mar 4, 2024
dcec2d0
chore: remove todos
charankamarapu Mar 4, 2024
6b43eb1
chore: create provider package
charankamarapu Mar 4, 2024
941b1d6
chore: remove errs
charankamarapu Mar 4, 2024
2262949
chore: correct error handling
charankamarapu Mar 5, 2024
6eb920e
chore: correct error handling
charankamarapu Mar 5, 2024
f76e34e
chore: correct error handling
charankamarapu Mar 5, 2024
a8990ba
fix: correct debug flag
charankamarapu Mar 5, 2024
77ab91d
chore: correct test service
charankamarapu Mar 5, 2024
853f6bd
chore: add delay
charankamarapu Mar 5, 2024
db9a023
chore: correct report version
charankamarapu Mar 5, 2024
0cb0368
chore: remove unused file
charankamarapu Mar 5, 2024
518980c
modify context cancellation function in exec.Cmd
gouravkrosx Mar 5, 2024
70f1be8
chore: passed error channel to proxy
gouravkrosx Mar 5, 2024
7efb23a
chore: add context.Canceled
charankamarapu Mar 6, 2024
23f2362
chore: correct one-click install
charankamarapu Mar 6, 2024
4d361fb
chore: add extra fields in report
charankamarapu Mar 6, 2024
2ece941
modified error logs for context cancelled errors
gouravkrosx Mar 6, 2024
e535f6c
chore: refactor logger.error()
charankamarapu Mar 6, 2024
b96c552
chore: remove ioutil
charankamarapu Mar 6, 2024
12e9ba6
chore: add linter
charankamarapu Mar 6, 2024
e77cda0
chore: fix custom naming
charankamarapu Mar 6, 2024
93e8b1d
chore: update readMe
charankamarapu Mar 6, 2024
5779577
chore: update error logs
gouravkrosx Mar 6, 2024
655f31a
chore: fix import cycle
gouravkrosx Mar 6, 2024
b6c5da0
chore: update error logs
gouravkrosx Mar 6, 2024
8f8d3ca
chore: synced some commits with main
gouravkrosx Mar 6, 2024
0bb2dc3
chore: add record timer
charankamarapu Mar 6, 2024
290347a
chore: return ctx error where needed
gouravkrosx Mar 6, 2024
2c62b02
chore: correct replay service
charankamarapu Mar 7, 2024
dd7b5bc
chore: refactor folder names
charankamarapu Mar 7, 2024
cc7c6cb
chore: remove closing of error channel again:
gouravkrosx Mar 7, 2024
b5060f5
chore: correct time
charankamarapu Mar 7, 2024
66c75a3
chore: closing outgoing channel after context done
gouravkrosx Mar 7, 2024
32e569c
chore: lint cli, config, util
charankamarapu Mar 7, 2024
856e691
chore: lint services
charankamarapu Mar 7, 2024
ee04175
chore: lint platform
charankamarapu Mar 7, 2024
aeeaffc
chore: lint models
charankamarapu Mar 7, 2024
5a9bb24
chore: lint graph
charankamarapu Mar 7, 2024
5215003
chore: add error group in socket listeners of ebpf
gouravkrosx Mar 7, 2024
2d9ef0b
chore: lint intergrations
charankamarapu Mar 7, 2024
efe18c6
chore: lint proxy
charankamarapu Mar 7, 2024
e4fcc97
chore: resolve lint
charankamarapu Mar 7, 2024
9ca2b64
chore: lint
charankamarapu Mar 7, 2024
3c9ccab
chore: add errorgroups in app, core
gouravkrosx Mar 7, 2024
f42253a
chore: refactor test
charankamarapu Mar 7, 2024
3887e3f
chore: add delay
charankamarapu Mar 7, 2024
be0eb4d
chore: add errorgroupin proxy
gouravkrosx Mar 7, 2024
f8d454f
chore: add error group in generic parser
gouravkrosx Mar 7, 2024
81bc5fa
chore: add error group in grpc parser
gouravkrosx Mar 7, 2024
60b2fd4
chore: add error group in postgres parser
gouravkrosx Mar 7, 2024
665ee72
chore: refactor replay
charankamarapu Mar 8, 2024
6f72ec9
chore: add break
charankamarapu Mar 8, 2024
dee6c2b
chore: refactor unload
charankamarapu Mar 8, 2024
2391c5a
chore: refactor errors
charankamarapu Mar 8, 2024
a9417da
chore: refactor errors
charankamarapu Mar 8, 2024
d6a5d88
chore: linters
charankamarapu Mar 8, 2024
9456982
chore: handle ctx done in socket listeners
gouravkrosx Mar 8, 2024
623cd26
chore: fix ctx cancel in dns servers
gouravkrosx Mar 8, 2024
5c2da14
chore: fix ctx cancel in proxy and readconn util functions
gouravkrosx Mar 8, 2024
4e6303c
chore: fix ctx cancel in generic parser
gouravkrosx Mar 8, 2024
757dd45
chore: remove rand
charankamarapu Mar 8, 2024
9fcf059
chore: fix ctx cancel in http parser
gouravkrosx Mar 8, 2024
924a84c
chore: fix ctx cancel in mongo parser
gouravkrosx Mar 8, 2024
564c50b
chore: fix ctx cancel in postgres parser
gouravkrosx Mar 8, 2024
42ef17b
chore: add nil check for error group typecast & handle ctx cancel in …
gouravkrosx Mar 10, 2024
cca8083
chore: fix ctx cancel in mongo & mysql parser
gouravkrosx Mar 10, 2024
c558506
chore:pass right context in parser
gouravkrosx Mar 10, 2024
6765fa4
chore:lint
gouravkrosx Mar 10, 2024
ddc39aa
chore: add ctx impl in create yaml
charankamarapu Mar 11, 2024
a033a19
chore: correct platform
charankamarapu Mar 11, 2024
155fc5c
chore: add ctx in delay
charankamarapu Mar 11, 2024
91cf44a
chore: fix closing of mock channel
gouravkrosx Mar 11, 2024
d0e9175
chore: add go routine in tele
charankamarapu Mar 11, 2024
98e6d18
chore: add tele in record
charankamarapu Mar 11, 2024
35f7d2e
chore: add nil check in channel in proxy
gouravkrosx Mar 11, 2024
5170788
chore: add errgrps
charankamarapu Mar 11, 2024
719cfea
chore: remove delays
charankamarapu Mar 11, 2024
924e3b7
chore: add telemetry
charankamarapu Mar 11, 2024
92a8ae6
chore: lint
charankamarapu Mar 11, 2024
7f6a74b
chore: remove print
charankamarapu Mar 11, 2024
6ee1365
chore: fix ebpf resources unloading errors
gouravkrosx Mar 11, 2024
0d7e885
chore: remove print
charankamarapu Mar 11, 2024
5df4317
chore: remove print
charankamarapu Mar 11, 2024
01b7dd7
chore: fix log
charankamarapu Mar 11, 2024
871e4d8
chore: add info log
charankamarapu Mar 11, 2024
2746b6c
chore: change file permissions and remove errCh in outgoing
gouravkrosx Mar 12, 2024
d9efa9a
chore: uncomment java setupCA
gouravkrosx Mar 12, 2024
82574a0
chore: add buffered channels
charankamarapu Mar 12, 2024
0a31137
chore: add new err grps
charankamarapu Mar 12, 2024
83ab006
chore: add new err grps
charankamarapu Mar 12, 2024
53d7567
chore: add diff ctx cancel for hooks and proxy
gouravkrosx Mar 12, 2024
6d11ff5
chore: ctx lint
gouravkrosx Mar 12, 2024
54d0e9e
chore: remove print
gouravkrosx Mar 12, 2024
5a05646
chore: fix ctx
charankamarapu Mar 12, 2024
4e5a06c
filter mocks
gouravkrosx Mar 12, 2024
93585fb
after setting mocks
gouravkrosx Mar 12, 2024
7ce1c3c
fix: sorting mocks
charankamarapu Mar 12, 2024
c591176
fix: inital config mocks issue
gouravkrosx Mar 12, 2024
b4d36dc
fix: return in case of match error in mongo, postgres
gouravkrosx Mar 12, 2024
0f01cf4
fix: linter
charankamarapu Mar 13, 2024
42ce92c
chore: merge main and resolve conflicts
slayerjain Mar 13, 2024
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/--documentation-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ labels: [Documentation]
body:
- type: markdown
attributes:
value: Thank you for taking the time to file a Documentation update.
value: Thank you for taking the time to file a Documentation tools.
- type: textarea
attributes:
label: What do you want to add to the docs? (please state reasons if any)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
template-path: .github/ISSUE_TEMPLATE/--documentation-update.yaml
template-path: .github/ISSUE_TEMPLATE/--documentation-tools.yaml

- name: Set labels based on repository field
uses: redhat-plumbers-in-action/advanced-issue-labeler@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_workflow_scripts/golang-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ docker network create keploy-network
docker run --name mongoDb --rm --net keploy-network -p 27017:27017 -d mongo

# Generate the keploy-config file.
docker run --name keploy-v2 -p 16789:16789 --privileged --pid=host -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm keployv2 generate-config
docker run --name keploy-v2 -p 16789:16789 --privileged --pid=host -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm keployv2 config --generate

# Update the global noise to ts.
config_file="./keploy-config.yaml"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_workflow_scripts/golang-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [ -f "./keploy-config.yaml" ]; then
fi

# Generate the keploy-config file.
./../../keployv2 generate-config
./../../keployv2 config --generate

# Update the global noise to ts.
config_file="./keploy-config.yaml"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_workflow_scripts/node-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ docker run --name mongoDb --rm -p 27017:27017 -d mongo
# Install the required node dependencies.
npm install

# Edit the connection.js file to connect to local mongodb.
# Edit the conn.js file to connect to local mongodb.
file_path="src/db/connection.js"
sed -i "s/mongoDb:27017/localhost:27017/" "$file_path"

Expand Down Expand Up @@ -70,7 +70,7 @@ sudo -E env PATH=$PATH ./../../keployv2 test -c "npm test" --delay 5 --coverage
sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --delay 10 --testsets test-set-0

# Generate the keploy-config file.
./../../keployv2 generate-config
./../../keployv2 config --generate

# Update the global noise to ts.
config_file="./keploy-config.yaml"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_workflow_scripts/python-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ docker network create backend
rm -rf keploy/

# Generate the keploy-config file.
docker run --name keploy-v2 -p 16789:16789 --privileged --pid=host -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm keployv2 generate-config
docker run --name keploy-v2 -p 16789:16789 --privileged --pid=host -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm keployv2 config --generate

# Update the global noise to ignore the Allow header.
config_file="./keploy-config.yaml"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_workflow_scripts/python-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ python3 manage.py makemigrations
python3 manage.py migrate

# Generate the keploy-config file.
./../../../keployv2 generate-config
./../../../keployv2 config --generate

#Clean any keploy folders.
sudo rm -rf keploy/
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ RUN go build -ldflags="-X main.dsn=$SENTRY_DSN_DOCKER -X main.version=$VERSION"
# === Runtime Stage ===
FROM debian:bookworm-slim

ENV IS_DOCKER_CMD=true
ENV KEPLOY_INDOCKER=true

# Update the package lists and install required packages
RUN apt-get update && \
RUN apt-get tools && \
apt-get install -y ca-certificates curl sudo && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ Whether you're a newbie coder or a wizard 🧙‍♀️, your perspective is gol

⚙️ [Installation Guide](https://keploy.io/docs/application-development/)

📖 [Contribution Guide](https://docs.keploy.io/docs/devtools/server-contrib-guide/)
📖 [Contribution Guide](https://docs.keploy.io/docs/devtools/server-contrib-guide/)
File renamed without changes.
22 changes: 22 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Package cli provides functionality for the command-line interface of the application.
package cli

import (
"context"

"github.com/spf13/cobra"
"go.keploy.io/server/v2/config"

Check failure on line 8 in cli/cli.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package go.keploy.io/server/v2/config; to add it:
"go.uber.org/zap"
)

type HookFunc func(context.Context, *zap.Logger, *config.Config, ServiceFactory, CmdConfigurator) *cobra.Command

// Registered holds the registered command hooks
var Registered map[string]HookFunc

func Register(name string, f HookFunc) {
if Registered == nil {
Registered = make(map[string]HookFunc)
}
Registered[name] = f
}
74 changes: 74 additions & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package cli

import (
"context"
"errors"
"path/filepath"

"go.keploy.io/server/v2/config"

toolsSvc "go.keploy.io/server/v2/pkg/service/tools"

Check failure on line 10 in cli/config.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package go.keploy.io/server/v2/pkg/service/tools; to add it:
"go.keploy.io/server/v2/utils"

"github.com/spf13/cobra"
"go.uber.org/zap"
)

func init() {
Register("config", Config)
}

func Config(ctx context.Context, logger *zap.Logger, cfg *config.Config, servicefactory ServiceFactory, cmdConfigurator CmdConfigurator) *cobra.Command {
var cmd = &cobra.Command{
Use: "config",
Short: "manage keploy configuration file",
Example: "keploy config --generate --path /path/to/localdir",
PreRunE: func(cmd *cobra.Command, _ []string) error {
return cmdConfigurator.ValidateFlags(ctx, cmd, cfg)
},
RunE: func(cmd *cobra.Command, _ []string) error {

isGenerate, err := cmd.Flags().GetBool("generate")
if err != nil {
utils.LogError(logger, err, "failed to get generate flag")
return err
}

if isGenerate {
filePath := filepath.Join(cfg.Path, "keploy.yml")
if utils.CheckFileExists(filePath) {
override, err := utils.AskForConfirmation("Config file already exists. Do you want to override it?")
if err != nil {
utils.LogError(logger, err, "failed to ask for confirmation")
return err
}
if !override {
return nil
}
}
svc, err := servicefactory.GetService(ctx, cmd.Name(), *cfg)
if err != nil {
utils.LogError(logger, err, "failed to get service")
return err
}
var tools toolsSvc.Service
var ok bool
if tools, ok = svc.(toolsSvc.Service); !ok {
utils.LogError(logger, nil, "service doesn't satisfy tools service interface")
return err
}
if err := tools.CreateConfig(ctx, filePath, ""); err != nil {
utils.LogError(logger, err, "failed to create config")
return err
}
return nil
}
return errors.New("only generate flag is supported in the config command")
},
}
if err := cmdConfigurator.AddFlags(cmd, cfg); err != nil {
utils.LogError(logger, err, "failed to add flags")
return nil
}
return cmd
}
44 changes: 44 additions & 0 deletions cli/examples.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cli

import (
"context"
"fmt"

"go.keploy.io/server/v2/cli/provider"
"go.keploy.io/server/v2/config"
"go.keploy.io/server/v2/utils"
"go.uber.org/zap"

"github.com/spf13/cobra"
)

func init() {
Register("example", Example)
}

func Example(_ context.Context, logger *zap.Logger, _ *config.Config, _ ServiceFactory, _ CmdConfigurator) *cobra.Command {
var customSetup bool
var cmd = &cobra.Command{
Use: "example",
Short: "Example to record and test via keploy",
RunE: func(cmd *cobra.Command, _ []string) error {
customSetup, err := cmd.Flags().GetBool("customSetup")
if err != nil {
utils.LogError(logger, nil, "failed to read the customSetup flag")
return err
}
if customSetup {
fmt.Println(provider.Examples)
return nil
}
fmt.Println(provider.ExampleOneClickInstall)
fmt.Println(provider.WithoutexampleOneClickInstall)
return nil
},
}
cmd.SetHelpTemplate(provider.CustomHelpTemplate)

cmd.Flags().Bool("customSetup", customSetup, "Check if the user is using one click install")

return cmd
}
79 changes: 79 additions & 0 deletions cli/mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package cli

import (
"context"
"errors"

"github.com/spf13/cobra"
"go.keploy.io/server/v2/config"
recordSvc "go.keploy.io/server/v2/pkg/service/record"

Check failure on line 9 in cli/mock.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package go.keploy.io/server/v2/pkg/service/record; to add it:
replaySvc "go.keploy.io/server/v2/pkg/service/replay"

Check failure on line 10 in cli/mock.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package go.keploy.io/server/v2/pkg/service/replay; to add it:
"go.keploy.io/server/v2/utils"
"go.uber.org/zap"
)

func init() {
Register("mock", Mock)
}

func Mock(ctx context.Context, logger *zap.Logger, cfg *config.Config, serviceFactory ServiceFactory, cmdConfigurator CmdConfigurator) *cobra.Command {
var cmd = &cobra.Command{
Use: "mock",
Short: "Record and replay ougoung network traffic for the user application",
Example: `keploy mock -c "/path/to/user/app" --delay 10`,
RunE: func(cmd *cobra.Command, _ []string) error {
record, err := cmd.Flags().GetBool("record")
if err != nil {
utils.LogError(logger, nil, "failed to read the record flag")
return err
}
replay, err := cmd.Flags().GetBool("replay")
if err != nil {
utils.LogError(logger, nil, "failed to read the replay flag")
return err
}
if !record && !replay {
return errors.New("missing required --record or --replay flag")
}
if record && replay {
return errors.New("both --record and --replay flags are set")
}
if record {
svc, err := serviceFactory.GetService(ctx, "record", *cfg)
if err != nil {
utils.LogError(logger, err, "failed to get service")
return err
}
var recordService recordSvc.Service
var ok bool
if recordService, ok = svc.(recordSvc.Service); ok {
return recordService.StartMock(ctx)
}
utils.LogError(logger, nil, "service doesn't satisfy record service interface")
return err

}
if replay {
svc, err := serviceFactory.GetService(ctx, "replay", *cfg)
if err != nil {
utils.LogError(logger, err, "failed to get service")
return err
}
var replayService replaySvc.Service
var ok bool
if replayService, ok = svc.(replaySvc.Service); ok {
return replayService.ProvideMocks(ctx)
}
utils.LogError(logger, nil, "service doesn't satisfy replay service interface")
return err
}
return nil

},
}
if err := cmdConfigurator.AddFlags(cmd, cfg); err != nil {
utils.LogError(logger, err, "failed to add flags")
return nil
}
return cmd
}
Loading
Loading