Skip to content

Refactor client and server structure with configuration improvements#149

Merged
akiidjk merged 52 commits intodevfrom
refactor/config
Apr 12, 2026
Merged

Refactor client and server structure with configuration improvements#149
akiidjk merged 52 commits intodevfrom
refactor/config

Conversation

@akiidjk
Copy link
Copy Markdown
Collaborator

@akiidjk akiidjk commented Apr 8, 2026

This pull request refactors and reorganizes the CookieFarm client command-line interface, focusing on improving code structure, configuration management, and exploit command handling. It also introduces minor linter configuration changes. The most important changes are summarized below:

CLI Command Refactoring and Structure:

  • Refactored the CLI command structure by replacing global command variables (ConfigCmd, ExploitCmd) with builder functions (buildConfigCmd, buildExploitCmd), improving encapsulation and modularity. Command initialization and flag definitions are now encapsulated within these functions. [1] [2]
  • Renamed cookiefarm/client/cmd/config.go to args.go and updated variable names for CLI flags to use lower-case, more consistent naming.

Configuration Management Improvements:

  • Updated configuration management to use a singleton pattern (config.GetInstance()) instead of config.GetConfigManager(), simplifying access and state management. Updated all relevant command handlers (reset, update, login, logout, show) to use the new instance method. [1] [2]
  • Improved the LoginHandler logic to write the session token and update shared configuration after a successful login, ensuring session state is properly persisted.

Exploit Command Handling:

  • Refactored the exploit run and test flows to use a new exploit.ExploitArgs struct, and separated the setup and execution logic for better clarity and maintainability. Submission of flags is now handled via the new submitter package.
  • Updated exploit template creation to use the template package instead of exploit.Create, reflecting improved separation of concerns.

API and Linter Configuration:

  • Removed the unused cookiefarm/client/api/api.go file, cleaning up obsolete code.
  • Enabled the dupl linter in .golangci.yml to detect code duplication, promoting code quality.

These changes collectively improve code organization, maintainability, and reliability of the CookieFarm client CLI.

ADDITIONAL FIX AND ADDONS

This pull request introduces several significant updates across the build, release, configuration, and Dockerization processes for the CookieFarm project. The most notable changes include a major refactor of the client configuration command handling, improved Docker build logic, enhanced release safety, and updates to the build and linting toolchain. These changes collectively improve maintainability, security, and developer experience.

Client CLI & Configuration Refactor:

  • The client configuration command (config) has been refactored for clarity and maintainability. The file was renamed from config.go to args.go, and the configuration management now uses a singleton pattern (GetInstance()), simplifying state management. Command flag handling is more consistent, and the login flow now writes the session token and shared config to disk after successful authentication. [1] [2] [3] [4]

Dockerization & Build Improvements:

  • The Dockerfile for the server has been streamlined: unnecessary build dependencies were removed, the build process now directly compiles the server and plugins, and file paths were updated for improved structure. The runtime stage ensures correct permissions and ownership, and the entrypoint script is now properly included and executable.
  • The .dockerignore now excludes all plugin .so files in pkg/plugins/, reducing build context size.

Release & Build Pipeline Updates:

  • The release script .github/release.sh now ensures git tags are unique before proceeding and pushes tags explicitly, preventing accidental overwrites.
  • The .goreleaser.yaml was renamed and updated: it now uses go work sync instead of go mod tidy, corrects the client build path, updates archive naming, and improves the Discord release message format. [1] [2] [3]

Linting and Toolchain Updates:

  • The Go linter version is bumped to v2.11.4 in the GitHub Actions workflow, and the dupl linter is enabled with a threshold of 100 in .golangci.yml, improving code quality checks. [1] [2]

Other Notable Cleanups:

  • The obsolete client/api/api.go file was removed, reflecting a shift in how the client interacts with the server API.
  • The sample environment file was renamed and the unused BACKEND_URL variable was removed for clarity.

References:

akiidjk and others added 28 commits March 8, 2026 13:24
Remove legacy client config manager and split client into
internal and pkg modules. Update go.work to include internal
packages and client/pkg/config. Clean up imports, whitespace and
tidy go.mod/go.sum dependencies.
Refactor client code for improved structure and performance
Update go.work to reference new internal paths and add
server/internal/config go.mod

Refactor config package: use sharedconfig.Shared for SharedConfig
and add a Config struct to hold flagTTL
Convert flag status from string to int across models, database schema,
queries, protocols and tests
Add a ConfigManager singleton for server configuration and inject it
into
Runner, handlers and related components
Update sqlc config and internal package paths, add controllers module,
and misc refactors (slice append optimization, import tweaks)
Refactor server configuration and internal module structure
For testing use `just setup-tests` and the command: `./bin/ckc exploit
run -e main -n CookieService -t 10 --debug` (remember to copy the
exploits @example_total.py inside ~/.config/cookiefarm/exploits/main.py)
part the token is taken from the config instance
- Setup now accepts *ExploitArgs and returns error
- Callers pass &exploitArgs and handle error
- Use normalizedPath when constructing ExploitPath
- Serve assets from server/public in PrepareStatic and fix the stray
  slash in the JS route
- Add logger and models imports to templates.go
- Reformat layouts/main.html for consistent indentation and updated
  classes
- Refactor dashboard.html markup to a cleaner structure
- Update flags_rows.html to show the code and inline action buttons
Make sure the behavior of the client is intended + some fix at exploiter and server templating
@akiidjk akiidjk added Clean Code Clean THIS! dependencies Pull requests that update a dependency file go Pull requests that update go code labels Apr 8, 2026
akiidjk and others added 24 commits April 9, 2026 09:11
Return an error if exploit name is empty in template.Create with the
message "exploit name cannot be empty". Replace logger.Fatal with
logger.Error in the config loader to avoid exiting the process. Add
test-related indirect dependencies to client/internal/websockets go.mod.
Add extensive table-driven and category-partition tests covering many
areas of the client:

- internal/api: HTTP helpers and high-level API calls (Login, GetConfig,
  SubmitBatchDirect, SubmitFlag)
- internal/exploit: parser paths and buildSuccessFlag field mapping
- internal/submitter: batching and channel lifecycle behaviour
- internal/template: template create/remove and path handling
- internal/websockets: CircuitBreaker lifecycle and concurrency
- pkg/config: ConfigManager getters/setters, file I/O, and concurrency
- pkg/process: process start/wait/kill and stdout handling
Close HTTP response bodies in tests to avoid leaks
Replace repetitive cases with table-driven tests and helper asserts
Consolidate config string-field tests and service/port mappings
Minor cleanups: use errors.New, remove redundant shadowing, rename tests
Build server binary and plugins during the build stage using go build
(buildmode=plugin) and remove the just dependency. Add .dockerignore to
exclude generated plugin .so files. Copy repo files into the image,
adjust UI views path, include run.sh, set ownership/executable bits and
expose 8080. Add env_file: .env to docker-compose and default PASSWORD
in
run.sh; simplify runtime argument handling.
Add a robust CLI launcher that resolves platform-specific binaries,
supports a user cache, optional remote downloading, atomic writes, and
verbose diagnostics via COOKIEFARM_* env vars. Also bump version to
1.2.11 and update pyproject metadata (license and homepage).
Too long RUN instruction should be split into multiple linesdocker:S7020
Enhance behavior with example flag IDs, context, and logging
necessary for when the image is taken from docker hub
Provide install.sh interactive installer using gum
Prompts for server settings, writes .env and config.yml, and can
clone and build CookieFarm or download the docker-compose and start
containers. Includes colorized output, robust error handling, and
automatic fetching/installation of the gum binary.
@akiidjk akiidjk merged commit 15209f1 into dev Apr 12, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Clean Code Clean THIS! dependencies Pull requests that update a dependency file go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants