Skip to content

Official Argus provider for remote configuration management through HashiCorp Consul. It enables real-time configuration loading and watching from Consul KV store with native blocking queries, multi-datacenter support, and production-ready security features.

License

Notifications You must be signed in to change notification settings

agilira/argus-provider-consul

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

argus-provider-consul: Argus remote provider for HashiCorp Consul

an AGILira library

Official Argus provider for remote configuration management through HashiCorp Consul. It enables real-time configuration loading and watching from Consul KV store with native blocking queries, multi-datacenter support, and production-ready security features.

CI CodeQL Security Go Report Card Made For Argus

FeaturesInstallationQuick StartConfigurationDemoRequirements

Features

  • Real-time Native Watch: Leverages Consul blocking queries for instant updates with minimal overhead.
  • Multi-Datacenter Support: Specify the desired datacenter directly in the configuration URL.
  • ACL Token Authentication: Secure integration with protected Consul environments.
  • TLS Connections: Support for encrypted communication with the Consul cluster.
  • Secure by Design: Red-team tested against path traversal, SSRF, resource exhaustion & TLS bypass attacks.
  • Resource Protection: Built-in limits for concurrent connections, memory usage, and goroutine management.
  • Integrated Health Check: Verifies connectivity and Consul cluster status.

Compatibility and Support

argus-provider-consul is designed to work with Consul 1.32+ and follows Long-Term Support guidelines to ensure consistent performance across production deployments.

Installation

go get github.com/agilira/argus-provider-consul

Quick Start

To use the provider, import it and register it with Argus:

package main

import (
    "context"
    "log"
    "time"

    "github.com/agilira/argus" // Argus core
    consul "github.com/agilira/argus-provider-consul" // Consul provider
)

func main() {
    // Register the Consul provider
    consulProvider, err := consul.GetProvider()
    if err != nil {
        log.Fatal("Failed to create Consul provider:", err)
    }
    
    if err := argus.RegisterRemoteProvider("consul", consulProvider); err != nil {
        log.Fatal("Failed to register Consul provider:", err)
    }

    consulURL := "consul://localhost:8500/config/myapp"

    // --- Single Load ---
    log.Println("Loading configuration from Consul...")
    config, err := argus.LoadRemoteConfig(consulURL)
    if err != nil {
        log.Fatalf("Configuration loading error: %v", err)
    }
    log.Printf("Configuration loaded: %+v\n", config)


    // --- Real-time Monitoring ---
    log.Println("\nStarting real-time monitoring (watch)...")
    ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    defer cancel()

    configChan, err := argus.WatchRemoteConfigWithContext(ctx, consulURL)
    if err != nil {
        log.Fatalf("Watch startup error: %v", err)
    }

    // Goroutine to handle updates
    go func() {
        for newConfig := range configChan {
            log.Printf("Configuration update received: %+v\n", newConfig)
            // Apply new configuration to your application here
        }
        log.Println("Watch channel closed.")
    }()

    // Keep application running to receive updates
    <-ctx.Done()
}

Configuration

URL Format

The provider is configured through a specific URL:

consul://[user:pass@]host:port/key/path[?query_params]

Components:

  • host:port: Your Consul agent address (default: localhost:8500)
  • key/path: Complete path in Consul's K/V store where configuration is stored
  • query_params (optional):
    • datacenter=dc1: Specify a different Consul datacenter
    • token=SECRET_TOKEN: Provide ACL token for authentication
    • tls=true: Enable HTTPS communication

Examples

// Basic configuration
"consul://localhost:8500/services/my-app/config"

// Multi-datacenter with authentication
"consul://consul.my-domain.com/production/database/config?datacenter=us-east-1&token=a1b2-c3d4"

// Secure connection
"consul://127.0.0.1:8500/features/flags?tls=true"

Storing Configuration in Consul

The provider expects the value associated with the key in Consul to be a JSON string.

Example with Consul CLI:

consul kv put config/myapp '{
  "service_name": "my-awesome-app",
  "port": 8080,
  "debug": true,
  "features": {
    "enable_feature_x": true
  }
}'

Demo

Requirements

License

Mozilla Public License 2.0 - see the LICENSE file for details.


argus-provider-consul • an AGILira library

About

Official Argus provider for remote configuration management through HashiCorp Consul. It enables real-time configuration loading and watching from Consul KV store with native blocking queries, multi-datacenter support, and production-ready security features.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •