feat: delete firmware
This commit is contained in:
@@ -267,6 +267,39 @@ func (c *RegistryClient) DownloadFirmware(name, version string) ([]byte, error)
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// DeleteFirmware deletes firmware from the registry
|
||||
func (c *RegistryClient) DeleteFirmware(name, version string) (map[string]interface{}, error) {
|
||||
url := fmt.Sprintf("%s/firmware/%s/%s", c.BaseURL, name, version)
|
||||
|
||||
req, err := http.NewRequest(http.MethodDelete, url, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create delete request: %w", err)
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to delete firmware: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return nil, fmt.Errorf("firmware delete request failed with status %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
var result map[string]interface{}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode delete response: %w", err)
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"name": name,
|
||||
"version": version,
|
||||
}).Info("Deleted firmware from registry")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// HealthCheck checks if the registry is healthy
|
||||
func (c *RegistryClient) HealthCheck() error {
|
||||
url := fmt.Sprintf("%s/health", c.BaseURL)
|
||||
|
||||
Reference in New Issue
Block a user