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
22 changes: 11 additions & 11 deletions docs/content/deployment/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,23 @@ SERVICE_DEBUG=true # Development (verbose)
- `true`: Detailed logs, useful for debugging
- `false`: Minimal logs, recommended for production

### SERVICE_AUTH_VERBOSE
### SERVICE_VERBOSE

Enable verbose authentication logging.
Enable verbose logging.

- **Type:** Boolean
- **Required:** No
- **Default:** `false`
- **Environment Variable:** `SERVICE_AUTH_VERBOSE`
- **Command-line Flag:** `--auth-verbose`
- **Environment Variable:** `SERVICE_VERBOSE`
- **Command-line Flag:** `--verbose`

**Description:** Controls authentication log output. When enabled, logs all authentication attempts including successful and failed authentications. When disabled (default), authentication operates silently.
**Description:** Controls verbose log output. When enabled, logs all authentication attempts, project lookups, and other operational details. When disabled (default), most operational logs are suppressed for cleaner output.

**Example:**

```bash
SERVICE_AUTH_VERBOSE=false # Quiet mode (default, recommended for production)
SERVICE_AUTH_VERBOSE=true # Verbose mode (useful for debugging)
SERVICE_VERBOSE=false # Quiet mode (default, recommended for production)
SERVICE_VERBOSE=true # Verbose mode (useful for debugging)
```

**Use Cases:**
Expand Down Expand Up @@ -320,7 +320,7 @@ SERVICE_DBNAME=embapi_test # Testing database
```bash
# .env file for development
SERVICE_DEBUG=true
SERVICE_AUTH_VERBOSE=true
SERVICE_VERBOSE=true
SERVICE_HOST=localhost
SERVICE_PORT=8880
SERVICE_DBHOST=localhost
Expand All @@ -337,7 +337,7 @@ ENCRYPTION_KEY=dev-encryption-key-min-32-chars-long
```bash
# .env file for Docker Compose
SERVICE_DEBUG=false
SERVICE_AUTH_VERBOSE=false
SERVICE_VERBOSE=false
SERVICE_HOST=0.0.0.0
SERVICE_PORT=8880
SERVICE_DBHOST=postgres
Expand All @@ -354,7 +354,7 @@ ENCRYPTION_KEY=generated_encryption_key_from_setup_script
```bash
# .env file for production (or use secrets management)
SERVICE_DEBUG=false
SERVICE_AUTH_VERBOSE=false
SERVICE_VERBOSE=false
SERVICE_HOST=0.0.0.0
SERVICE_PORT=8880
SERVICE_DBHOST=db.internal.example.com
Expand Down Expand Up @@ -432,7 +432,7 @@ Some variables support command-line flags:
```bash
./embapi \
--debug \
--auth-verbose \
--verbose \
--host 0.0.0.0 \
--port 8880 \
--admin-key your-admin-key \
Expand Down
23 changes: 12 additions & 11 deletions docs/content/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ All configuration can be set via environment variables. Use a `.env` file to kee
| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| `SERVICE_DEBUG` | Enable debug logging | `true` | No |
| `SERVICE_AUTH_VERBOSE` | Enable verbose authentication logging | `false` | No |
| `SERVICE_VERBOSE` | Enable verbose logging | `false` | No |
| `SERVICE_HOST` | Hostname to listen on | `localhost` | No |
| `SERVICE_PORT` | Port to listen on | `8880` | No |

Expand Down Expand Up @@ -44,7 +44,7 @@ Create a `.env` file in the project root:
```bash
# Service Configuration
SERVICE_DEBUG=false
SERVICE_AUTH_VERBOSE=false
SERVICE_VERBOSE=false
SERVICE_HOST=0.0.0.0
SERVICE_PORT=8880

Expand All @@ -67,7 +67,7 @@ You can also provide configuration via command-line flags:
```bash
./embapi \
--debug \
--auth-verbose \
--verbose \
-p 8880 \
--db-host localhost \
--db-port 5432 \
Expand Down Expand Up @@ -119,7 +119,7 @@ Configuration is loaded in the following order (later sources override earlier o
```bash
# .env (development)
SERVICE_DEBUG=true
SERVICE_AUTH_VERBOSE=true
SERVICE_VERBOSE=true
SERVICE_HOST=localhost
SERVICE_PORT=8880
SERVICE_DBHOST=localhost
Expand All @@ -136,7 +136,7 @@ ENCRYPTION_KEY=dev-encryption-key-32-chars-min
```bash
# .env (production)
SERVICE_DEBUG=false
SERVICE_AUTH_VERBOSE=false
SERVICE_VERBOSE=false
SERVICE_HOST=0.0.0.0
SERVICE_PORT=8880
SERVICE_DBHOST=prod-db.example.com
Expand All @@ -150,27 +150,28 @@ ENCRYPTION_KEY=$(cat /run/secrets/encryption_key)

## Logging Configuration

### Authentication Logging
### Verbose Logging

The `SERVICE_AUTH_VERBOSE` flag controls authentication log output. This is particularly useful for production environments or during bulk operations:
The `SERVICE_VERBOSE` flag controls verbose log output. This is particularly useful for production environments or during bulk operations:

- **`SERVICE_AUTH_VERBOSE=true`** (verbose mode): Logs all authentication attempts, including successful and failed authentications. Useful for debugging authentication issues or monitoring security events.
- **`SERVICE_VERBOSE=true`** (verbose mode): Logs all authentication attempts, project lookups, and other operational details. Useful for debugging or monitoring system behavior.

- **`SERVICE_AUTH_VERBOSE=false`** (quiet mode, default): Suppresses authentication logs. Recommended for production, especially during:
- **`SERVICE_VERBOSE=false`** (quiet mode, default): Suppresses verbose logs. Recommended for production, especially during:
- Bulk upload operations
- High-traffic scenarios
- When crawlers or automated tools access the API frequently

Example log output with `SERVICE_AUTH_VERBOSE=true`:
Example log output with `SERVICE_VERBOSE=true`:
```
Owner authentication successful: alice
Reader auth for owner=bob project=test definition= instance= running...
Checking project access...
Reader authentication successful
Found project test1 ...
Authentication failed.
```

With `SERVICE_AUTH_VERBOSE=false`, these messages are suppressed while authentication still works normally.
With `SERVICE_VERBOSE=false`, these messages are suppressed while operations still work normally.

## Validation

Expand Down
54 changes: 27 additions & 27 deletions internal/auth/auth_verbose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ import (
"github.com/stretchr/testify/assert"
)

// TestAuthVerboseFlag tests that authentication logging is controlled by the AuthVerbose flag
func TestAuthVerboseFlag(t *testing.T) {
// TestVerboseFlag tests that authentication logging is controlled by the Verbose flag
func TestVerboseFlag(t *testing.T) {
// Set required environment variables for testing
if os.Getenv("ENCRYPTION_KEY") == "" {
os.Setenv("ENCRYPTION_KEY", "test-encryption-key-32-bytes-long-1234567890")
}

tests := []struct {
name string
authVerbose bool
expectLogs bool
name string
verbose bool
expectLogs bool
}{
{
name: "AuthVerbose=true should produce logs",
authVerbose: true,
expectLogs: true,
name: "Verbose=true should produce logs",
verbose: true,
expectLogs: true,
},
{
name: "AuthVerbose=false should suppress logs",
authVerbose: false,
expectLogs: false,
name: "Verbose=false should suppress logs",
verbose: false,
expectLogs: false,
},
}

Expand All @@ -50,8 +50,8 @@ func TestAuthVerboseFlag(t *testing.T) {

// Create test options
options := &models.Options{
AuthVerbose: tt.authVerbose,
AdminKey: "test-admin-key",
Verbose: tt.verbose,
AdminKey: "test-admin-key",
}

// Create a simple API and router
Expand Down Expand Up @@ -128,25 +128,25 @@ func TestAuthVerboseFlag(t *testing.T) {
}
}

// TestAuthVerboseEnvironmentVariable tests that the environment variable is properly handled
func TestAuthVerboseEnvironmentVariable(t *testing.T) {
// TestVerboseEnvironmentVariable tests that the environment variable is properly handled
func TestVerboseEnvironmentVariable(t *testing.T) {
tests := []struct {
name string
envValue string
expected bool
}{
{
name: "SERVICE_AUTH_VERBOSE=true",
name: "SERVICE_VERBOSE=true",
envValue: "true",
expected: true,
},
{
name: "SERVICE_AUTH_VERBOSE=false",
name: "SERVICE_VERBOSE=false",
envValue: "false",
expected: false,
},
{
name: "SERVICE_AUTH_VERBOSE empty",
name: "SERVICE_VERBOSE empty",
envValue: "",
expected: false, // default value
},
Expand All @@ -155,28 +155,28 @@ func TestAuthVerboseEnvironmentVariable(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Clean up environment
os.Unsetenv("SERVICE_AUTH_VERBOSE")
os.Unsetenv("SERVICE_VERBOSE")

if tt.envValue != "" {
os.Setenv("SERVICE_AUTH_VERBOSE", tt.envValue)
defer os.Unsetenv("SERVICE_AUTH_VERBOSE")
os.Setenv("SERVICE_VERBOSE", tt.envValue)
defer os.Unsetenv("SERVICE_VERBOSE")
}

options := &models.Options{
AuthVerbose: false, // default
Verbose: false, // default
}

// Simulate what main.go does
if os.Getenv("SERVICE_AUTH_VERBOSE") != "" {
options.AuthVerbose = os.Getenv("SERVICE_AUTH_VERBOSE") == "true"
if os.Getenv("SERVICE_VERBOSE") != "" {
options.Verbose = os.Getenv("SERVICE_VERBOSE") == "true"
}

assert.Equal(t, tt.expected, options.AuthVerbose, "AuthVerbose should match expected value")
assert.Equal(t, tt.expected, options.Verbose, "Verbose should match expected value")
})
}
}

// TestNoAuthLogsInQuietMode verifies that with AuthVerbose=false, various auth scenarios don't produce logs
// TestNoAuthLogsInQuietMode verifies that with Verbose=false, various auth scenarios don't produce logs
func TestNoAuthLogsInQuietMode(t *testing.T) {
// This test demonstrates the fix for the bulk upload/crawler scenario
// Capture stdout
Expand All @@ -185,7 +185,7 @@ func TestNoAuthLogsInQuietMode(t *testing.T) {
os.Stdout = w

options := &models.Options{
AuthVerbose: false, // Quiet mode
Verbose: false, // Quiet mode
AdminKey: "test-admin-key",
}

Expand Down
Loading