Skip to content
Open
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
34 changes: 34 additions & 0 deletions pkg/plugins/cloudflare/cloudflareplugin/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cloudflareplugin

import (
"encoding/json"
"fmt"
"os"
)

// CloudflareConfig holds the configuration for the Cloudflare plugin
type CloudflareConfig struct {
APIKey string `json:"cloudflare_api_key"`
Email string `json:"cloudflare_email"`
AccountID string `json:"cloudflare_account_id"`
LogLevel string `json:"cloudflare_plugin_log_level"`
}

// GetCloudflareConfig reads and parses the Cloudflare configuration file
func GetCloudflareConfig(configFilePath string) (*CloudflareConfig, error) {
var result CloudflareConfig
bytes, err := os.ReadFile(configFilePath)
if err != nil {
return nil, fmt.Errorf("error reading config file for Cloudflare config @ %s: %v", configFilePath, err)
}
err = json.Unmarshal(bytes, &result)
if err != nil {
return nil, fmt.Errorf("error marshaling json into Cloudflare config %v", err)
}

if result.LogLevel == "" {
result.LogLevel = "info"
}

return &result, nil
}
97 changes: 97 additions & 0 deletions pkg/plugins/cloudflare/cloudflareplugin/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package cloudflareplugin

// Cloudflare API response types
// Based on Cloudflare API: https://developers.cloudflare.com/api/

// CloudflareBillingHistory represents a billing history entry
type CloudflareBillingHistory struct {
ID string `json:"id"`
Type string `json:"type"`
Action string `json:"action"`
Description string `json:"description"`
OccurredAt string `json:"occurred_at"`
CreatedAt string `json:"created_at"`
Currency string `json:"currency"`
Amount float32 `json:"amount"`
TypeInfo CloudflareBillingTypeInfo `json:"type_info"`
}

// CloudflareBillingTypeInfo contains details about the billing type
type CloudflareBillingTypeInfo struct {
Description string `json:"description"`
Unit string `json:"unit"`
Quantity float32 `json:"quantity"`
Item string `json:"item"`
}

// CloudflareBillingResponse is the API response for billing history
type CloudflareBillingResponse struct {
Result []CloudflareBillingHistory `json:"result"`
Success bool `json:"success"`
Errors []CloudflareAPIError `json:"errors"`
Messages []string `json:"messages"`
ResultInfo CloudflareResultInfo `json:"result_info"`
}

// CloudflareZoneBilling represents zone-level billing info
type CloudflareZoneBilling struct {
ID string `json:"id"`
Name string `json:"name"`
Plan string `json:"plan"`
Status string `json:"status"`
Cost float32 `json:"cost"`
}

// CloudflareZone represents a Cloudflare zone
type CloudflareZone struct {
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Plan CloudflareZonePlan `json:"plan"`
}

// CloudflareZonePlan represents the plan on a zone
type CloudflareZonePlan struct {
ID string `json:"id"`
Name string `json:"name"`
Price float32 `json:"price"`
Frequency string `json:"frequency"`
Legacy bool `json:"legacy"`
IsSub bool `json:"is_subscribed"`
}

// CloudflareZonesResponse is the API response for zones
type CloudflareZonesResponse struct {
Result []CloudflareZone `json:"result"`
Success bool `json:"success"`
Errors []CloudflareAPIError `json:"errors"`
ResultInfo CloudflareResultInfo `json:"result_info"`
}

// CloudflareAPIError represents an API error
type CloudflareAPIError struct {
Code int `json:"code"`
Message string `json:"message"`
}

// CloudflareResultInfo contains pagination info
type CloudflareResultInfo struct {
Page int `json:"page"`
PerPage int `json:"per_page"`
TotalPages int `json:"total_pages"`
Count int `json:"count"`
TotalCount int `json:"total_count"`
}

// CloudflareBillingLineItem represents a line item from billing
type CloudflareBillingLineItem struct {
Description string `json:"description"`
Amount float32 `json:"amount"`
Currency string `json:"currency"`
Quantity float32 `json:"quantity"`
Unit string `json:"unit"`
ZoneName string `json:"zone_name,omitempty"`
Product string `json:"product,omitempty"`
OccurredAt string `json:"occurred_at"`
Subscription bool `json:"subscription,omitempty"`
}
Loading