A Go client library and CLI application for interacting with the Aruba Central API.
- Complete OAuth2 authentication flow implementation
- Automatic token refresh
- Rate limit detection and handling
- Structured error types with proper error handling
- CLI application for easy interaction
To install the library and CLI tool, run:
go get github.com/tphakala/aruba-central-goCreate a config.json file with your Aruba Central API credentials:
{
"api": {
"endpoint": "https://apigw-prod2.central.arubanetworks.com",
"client_id": "your_client_id",
"client_secret": "your_client_secret",
"username": "your_username",
"password": "your_password",
"timeouts": {
"default": 60,
"auth": 30,
"status": 60
},
"refresh_buffer": 900
},
"token_cache": {},
"cache": {
"enabled": true,
"ttl": 300,
"path": "ap_cache.bolt"
}
}The package includes a CLI tool called arubactl for interacting with Aruba Central.
go build -o arubactl ./cmd/arubactlList all access points:
./arubactl --config config.json --tenant your_tenant_id --listGet detailed status for a specific access point:
./arubactl --config config.json --tenant your_tenant_id --serial AP_SERIAL_NUMBEREnable debug output:
./arubactl --config config.json --tenant your_tenant_id --serial AP_SERIAL_NUMBER --debugAdjust timeout:
./arubactl --config config.json --tenant your_tenant_id --list --timeout 120Enable automatic retry when rate limited:
./arubactl --config config.json --tenant your_tenant_id --list --auto-retry --max-retries 5The CLI tool provides built-in rate limit handling with the following features:
- Detailed rate limit error messages showing limits and remaining quota
- Automatic retry capability with the
--auto-retryflag - Configurable retry attempts with
--max-retries(default: 3) - Automatic waiting for the recommended retry period
import "github.com/tphakala/aruba-central-go/pkg/central"
// Create a new client with debug logging enabled
client, err := central.NewClient("config.json", true)
if err != nil {
// Handle error
}
// Ensure we have a valid token for the specified tenant
err = client.EnsureValidToken("tenant-id")
if err != nil {
// Handle authentication error
}import "context"
// Create a context with timeout
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Get status for a specific AP
status, err := client.GetAPStatus(ctx, "AP-SERIAL", "TENANT-ID")
if err != nil {
// Check for specific error types
if central.IsRateLimited(err) {
retryAfter := central.GetRetryAfter(err)
fmt.Printf("Rate limited. Retry after %d seconds\n", retryAfter)
} else if central.IsNotFound(err) {
fmt.Println("AP not found")
} else {
fmt.Printf("Error: %v\n", err)
}
return
}
// Print AP status
fmt.Printf("AP %s status: %s\n", status.Name, status.Status)// Get status for a specific AP and retrieve all APs at once
status, allAPs, err := client.GetAPStatusAndAll(ctx, "AP-SERIAL", "TENANT-ID")
if err != nil {
// Handle error (see above for error type checking)
}
// Process all APs
fmt.Printf("Retrieved %d access points\n", len(allAPs))
for _, ap := range allAPs {
// Work with each AP
fmt.Printf("AP %s: %s (Status: %s)\n", ap.Serial, ap.Name, ap.Status)
}