### Get gRPC Hello World Code Source: https://github.com/dgate-io/dgate-api/blob/main/functional-tests/grpc_tests/README.md Fetches the necessary Go packages for the gRPC greeter client and server examples. ```console $ go get google.golang.org/grpc/examples/helloworld/greeter_client $ go get google.golang.org/grpc/examples/helloworld/greeter_server ``` -------------------------------- ### Run gRPC Hello World Server Source: https://github.com/dgate-io/dgate-api/blob/main/functional-tests/grpc_tests/README.md Starts the gRPC greeter server in the background. Assumes Go environment is set up. ```console $ $(go env GOPATH)/bin/greeter_server & ``` -------------------------------- ### Install DGate Server and CLI Source: https://github.com/dgate-io/dgate-api/blob/main/README.md Installs the DGate Server and DGate CLI using Go modules. Requires Go version 1.22 or later. ```bash # requires go 1.22+ # install dgate-server go install github.com/dgate-io/dgate-api/cmd/dgate-server@latest # install dgate-cli go install github.com/dgate-io/dgate-api/cmd/dgate-cli@latest ``` -------------------------------- ### Run gRPC Hello World Client Source: https://github.com/dgate-io/dgate-api/blob/main/functional-tests/grpc_tests/README.md Executes the gRPC greeter client to send a request to the server and display the greeting. Shows expected output. ```console $ $(go env GOPATH)/bin/greeter_client Greeting: Hello world ``` -------------------------------- ### DGate CLI Server Management Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Commands for managing the DGate proxy and server instances. Includes starting, stopping, restarting, checking status, and retrieving logs and statistics. ```bash # Example: Start the DGate proxy dgate-cli server start-proxy # Example: View server logs dgate-cli server logs --tail 100 ``` -------------------------------- ### DGate CLI Help Command Example Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Demonstrates how the DGate CLI displays required and optional variables when the help command is invoked for a specific subcommand, such as 'ns mk'. This improves user experience by clearly indicating necessary inputs. ```bash dgate-cli ns mk --help # Expected output should show 'name' as a required variable and other optional variables. ``` -------------------------------- ### Dgate Todo App Commands Source: https://github.com/dgate-io/dgate-api/blob/main/functional-tests/ws_tests/websockets.html Lists the available commands for interacting with the Dgate todo application via its WebSocket interface. These commands allow users to add new tasks and mark existing tasks as done. ```apidoc Dgate Todo App Commands: - add [task] - Description: Adds a new task to the todo list. - Parameters: - task: The description of the task to add. - done [task] - Description: Marks an existing task as completed. - Parameters: - task: The description of the task to mark as done. ``` -------------------------------- ### WebSocket Client for Dgate Todo App Source: https://github.com/dgate-io/dgate-api/blob/main/functional-tests/ws_tests/websockets.html A JavaScript implementation of a WebSocket client to interact with the Dgate todo application's WebSocket server. It handles connection, message sending, and receiving server responses. ```javascript var input = document.getElementById("input"); var output = document.getElementById("output"); var socket = new WebSocket("ws://dgate-ws-test.local.ufosoup.com:18080/todo"); socket.onopen = function () { output.innerHTML += "Status: Connected\n"; }; socket.onmessage = function (e) { output.innerHTML += "\nServer: " + e.data + "\n"; }; function send() { socket.send(input.value); input.value = ""; } ``` -------------------------------- ### ModuleContext Interface and Example Usage Source: https://github.com/dgate-io/dgate-api/blob/main/pkg/modules/README.md Defines the ModuleContext interface, which provides access to various DGate API objects like request, response, namespace, service, route, module, node, and cluster. It also includes an example of how to access node properties within a module function. ```ts interface ModuleContext { // this is the request object (requires request permission/minimal) request: Request; // this is the response object, this may not available for all modules (requires response permission/minimal) response: Response; // this is the namespace object (requires namespace permission/basic) namespace: Namespace; // this is the service object (requires service permission/basic) service: Service; // this is the route object (requires route permission/basic) route: Route; // this is the module object (requires module permission/basic) module: Module; // this is the node object (requires node permission/advanced) node: Node; // this is the cluster object (requires cluster permission/advanced) cluster: Cluster; } function exampleModule(): string { const tags = this.node.tags; const version = this.node.version; } ``` -------------------------------- ### DGate Declarative Configuration with PKL Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Describes the use of PKL for defining DGate resources in a declarative manner. This allows for infrastructure-as-code practices. ```pkl import dgate.resources namespace { name = "my-app-ns" } domain { name = "example.com" namespace = ns.name } service { name = "user-service" namespace = ns.name port = 8080 routes = [ { path = "/users", methods = ["GET", "POST"] } ] } ``` -------------------------------- ### DGate Bundles for Extensibility Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Explains the concept of DGate bundles, which are collections of resources used to extend DGate's functionality, such as adding new modules or authentication methods. ```APIDOC Bundles: Purpose: - Extend DGate functionality by grouping related resources (modules, configurations, routes). Example Use Case: - OAuth2 Authentication Bundle: - Includes necessary modules for OAuth2 processing. - Configures routes for authentication endpoints. - Sets up required configurations for OAuth2 providers. ``` -------------------------------- ### DGate Metrics Exposition Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Details the metrics to be exposed by DGate for monitoring purposes, covering proxy server, admin server, and module performance. Supports integration with systems like Prometheus and Datadog. ```APIDOC Metrics: Proxy Server Metrics: - request_count: Total number of requests handled by the proxy. - request_latency_seconds: Latency of incoming requests. - request_module_latency_seconds: Latency spent within modules. - request_upstream_latency_seconds: Latency spent communicating with upstream servers. - request_error_count: Count of requests resulting in errors. Admin Server Metrics: - request_count: Total number of requests handled by the admin server. - request_latency_seconds: Latency of incoming admin requests. - request_error_count: Count of admin requests resulting in errors. Module Metrics: - request_count: Number of times a module was invoked. - request_latency_seconds: Latency of module execution. - request_error_count: Count of errors during module execution. - request_error_latency_seconds: Latency associated with module errors. Integration: - Supports Prometheus and Datadog exposition formats. ``` -------------------------------- ### DGate CLI Other Commands Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Utility commands for DGate, such as backup and restore operations. These are also noted as lower priority. ```bash # Example: Backup DGate configuration (hypothetical command) dgate-cli backup create --file backup.tar.gz # Example: Restore DGate configuration (hypothetical command) dgate-cli restore from backup.tar.gz ``` -------------------------------- ### DGate CLI Resource Management Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Commands for managing DGate resources such as namespaces, domains, and services. This includes Create, Read, Update, and Delete (CRUD) operations. ```bash # Example: Add a new namespace dgate-cli namespace create --name my-namespace # Example: Get service details dgate-cli service get --namespace my-namespace --name my-service ``` -------------------------------- ### DGate Server Tagging Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Defines the syntax and rules for applying tags to DGate servers. Tags are used for various purposes, including canary deployments and time-based routing. ```APIDOC Server Tags: Rules: - No special characters are allowed in tag names or values. Formats: - key:value - Standard key-value tag. - canary@0.01%:canary_mod - Example of a canary tag, indicating a 0.01% traffic split to 'canary_mod'. - @(2022-01-01T00:00:00Z)#key:value - Time-based tagging. The tag 'key:value' is applied at the specified timestamp. ``` -------------------------------- ### DGate Background Job Cron Jobs Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Configuration for scheduling background jobs using cron-like syntax. Supports predefined intervals and custom cron schedules. ```go // Example: Schedule a job to run every minute @every 1m func MyPeriodicJob() { // Job logic here } // Example: Schedule a job to run daily at midnight @cron 0 0 * * * func DailyCleanup() { // Cleanup logic here } ``` -------------------------------- ### DGate Module Permissions Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Defines a system for module permissions, allowing granular control over access to DGate resources and operating system functionalities. ```APIDOC Module Permissions: Purpose: - Allow users to define permissions for modules to access specific DGate resources or OS functionalities. Examples: - resource:document:read - Permission to read documents from the DGate resource store. - resource:document:write - Permission to write documents to the DGate resource store. - os:net:(http/tcp/udp) - Permission to perform network operations (HTTP, TCP, UDP). - os:file:read - Permission to read files from the operating system. - os:env:read - Permission to read environment variables. ``` -------------------------------- ### DGate Resource Tagging Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Specifies the tagging conventions for DGate resources, including rules for applying, requiring, and excluding tags for resource matching. ```APIDOC Resource Tags: Tagging Conventions: - name:data - Standard tag. Ignored by default unless prefixed. - #name:data - Required tag: The server must possess this tag for the resource to be applied. - !name:data - Excluded tag: The server must NOT possess this tag for the resource to be applied. - ?name:data1,data2 - Any tag match: The server must have at least one of the specified tags (data1 OR data2). - ?*name:data1,data2 - One tag match: The server must have exactly one of the specified tags (data1 XOR data2). ``` -------------------------------- ### Coraza WAF Integration Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Details the integration of the Coraza Web Application Firewall (WAF) into the DGate system. Coraza provides robust security features to protect against common web vulnerabilities. ```APIDOC Coraza WAF Integration: Overview: Integrates the Coraza WAF to provide protection against OWASP Top 10 vulnerabilities and other web attacks. Configuration: - Enable WAF: Set a configuration flag to activate the WAF module. - Rule Sets: Load and manage SecRules compatible rule sets. - Logging: Configure logging levels for WAF events and blocked requests. Usage: Requests are inspected by Coraza before being processed by the application. Malicious requests are blocked based on the loaded rules. Dependencies: - Coraza WAF library - SecRules compatible rule sets (e.g., Sigma, OWASP CRS) Example Configuration Snippet (Conceptual): ```yaml waf: enabled: true rules_path: /etc/coraza/rules/ log_level: "info" ``` Related Features: - Security Auditing - Intrusion Detection/Prevention ``` -------------------------------- ### DGate Module/Plugin Variables Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Describes the feature allowing users to define and utilize variables within modules and plugins, configurable via the Admin Console. ```APIDOC Module/Plugin Variables: Purpose: - Enable users to define custom variables for use in modules and plugins. Configuration: - Variables can be set by users, ideally through the Admin Console. Usage: - Variables are accessible within module/plugin code for dynamic behavior. ``` -------------------------------- ### Module Debugability: Stack Tracing for TypeScript Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Enhances the debuggability of TypeScript modules within the DGate system by implementing stack tracing. This provides developers with detailed error information, aiding in faster issue resolution. ```typescript // Example of how stack tracing might be implemented in a TypeScript module try { // Some operation that might fail throw new Error("Something went wrong in the module"); } catch (error) { console.error(`Module Error: ${error.message}\nStack Trace:\n${error.stack}`); // Further error handling or reporting } ``` -------------------------------- ### DGate CLI Cluster Management Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Commands for managing the DGate cluster, including Raft consensus and replica operations. These are noted as lower priority. ```bash # Example: Get Raft status (hypothetical command) dgate-cli cluster raft status # Example: View replica information (hypothetical command) dgate-cli cluster replicas list ``` -------------------------------- ### Request Module API Source: https://github.com/dgate-io/dgate-api/blob/main/pkg/modules/README.md Details the Request module within the DGate API, including its available functions and properties. The `body()` function retrieves the request body, and the `status` property indicates the request status. ```APIDOC Request Module: functions: body(): Returns the request body. properties: status: The status of the request. ``` -------------------------------- ### DGate Background Job Event Listeners Source: https://github.com/dgate-io/dgate-api/blob/main/TODO.md Defines event listeners for background jobs in DGate. These listeners can intercept and modify events such as HTTP requests, resource operations, and custom events. ```javascript // Example: Intercepting an incoming HTTP request module.exports = { onHttpRequest: async (request, context) => { // Modify request headers or body request.headers['X-DGate-Processed'] = 'true'; return request; } }; // Example: Handling resource creation events module.exports = { onResourceCreate: async (resource, context) => { console.log(`Resource created: ${resource.type}/${resource.name}`); // Perform actions based on resource creation return resource; } }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.