Fix: Ensure all SSL Certs records are checked
- Addressing the issue where only a limited number (30) were being processed due to pagination. The fixed now fetches all records to ensure comprehensive SSL monitoring.
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package pocketbase
|
package pocketbase
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -11,37 +10,53 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SSLCertificatesResponse struct {
|
type SSLCertificatesResponse struct {
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
PerPage int `json:"perPage"`
|
PerPage int `json:"perPage"`
|
||||||
TotalItems int `json:"totalItems"`
|
TotalItems int `json:"totalItems"`
|
||||||
TotalPages int `json:"totalPages"`
|
TotalPages int `json:"totalPages"`
|
||||||
Items []types.SSLCertificate `json:"items"`
|
Items []types.SSLCertificate `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PocketBaseClient) GetSSLCertificates() ([]types.SSLCertificate, error) {
|
func (c *PocketBaseClient) GetSSLCertificates() ([]types.SSLCertificate, error) {
|
||||||
url := fmt.Sprintf("%s/api/collections/ssl_certificates/records", c.baseURL)
|
var allCertificates []types.SSLCertificate
|
||||||
|
page := 1
|
||||||
resp, err := c.httpClient.Get(url)
|
perPage := 200 // You can increase up to 500 if needed
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to fetch SSL certificates: %v", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
for {
|
||||||
return nil, fmt.Errorf("PocketBase returned status %d", resp.StatusCode)
|
url := fmt.Sprintf(
|
||||||
|
"%s/api/collections/ssl_certificates/records?page=%d&perPage=%d",
|
||||||
|
c.baseURL, page, perPage,
|
||||||
|
)
|
||||||
|
|
||||||
|
resp, err := c.httpClient.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to fetch SSL certificates: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("PocketBase returned status %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
var response SSLCertificatesResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to decode SSL certificates response: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
allCertificates = append(allCertificates, response.Items...)
|
||||||
|
|
||||||
|
if page >= response.TotalPages || len(response.Items) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
page++
|
||||||
}
|
}
|
||||||
|
|
||||||
var response SSLCertificatesResponse
|
return allCertificates, nil
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to decode SSL certificates response: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.Items, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PocketBaseClient) UpdateSSLCertificate(id string, data map[string]interface{}) error {
|
func (c *PocketBaseClient) UpdateSSLCertificate(id string, data map[string]interface{}) error {
|
||||||
url := fmt.Sprintf("%s/api/collections/ssl_certificates/records/%s", c.baseURL, id)
|
url := fmt.Sprintf("%s/api/collections/ssl_certificates/records/%s", c.baseURL, id)
|
||||||
|
|
||||||
jsonData, err := json.Marshal(data)
|
jsonData, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal SSL certificate data: %v", err)
|
return fmt.Errorf("failed to marshal SSL certificate data: %v", err)
|
||||||
@@ -53,7 +68,7 @@ func (c *PocketBaseClient) UpdateSSLCertificate(id string, data map[string]inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
resp, err := c.httpClient.Do(req)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to update SSL certificate: %v", err)
|
return fmt.Errorf("failed to update SSL certificate: %v", err)
|
||||||
@@ -69,7 +84,7 @@ func (c *PocketBaseClient) UpdateSSLCertificate(id string, data map[string]inter
|
|||||||
|
|
||||||
func (c *PocketBaseClient) GetSSLCertificateByID(id string) (*types.SSLCertificate, error) {
|
func (c *PocketBaseClient) GetSSLCertificateByID(id string) (*types.SSLCertificate, error) {
|
||||||
url := fmt.Sprintf("%s/api/collections/ssl_certificates/records/%s", c.baseURL, id)
|
url := fmt.Sprintf("%s/api/collections/ssl_certificates/records/%s", c.baseURL, id)
|
||||||
|
|
||||||
resp, err := c.httpClient.Get(url)
|
resp, err := c.httpClient.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to fetch SSL certificate: %v", err)
|
return nil, fmt.Errorf("failed to fetch SSL certificate: %v", err)
|
||||||
@@ -86,4 +101,4 @@ func (c *PocketBaseClient) GetSSLCertificateByID(id string) (*types.SSLCertifica
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &cert, nil
|
return &cert, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user