mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-04 04:22:59 +00:00
* feat(acme): implement CRUD API for proxmox cluster ACME plugins Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * feat(acme): implement acme_plugins data source Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * feat(acme): implement acme_plugin data source Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * feat(acme): implement plugin resource creation Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * feat(acme): implement plugin resource read Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * feat(acme): implement plugin resource update Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * feat(acme): implement plugin resource deletion Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * feat(acme): implement plugin resource import Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * docs(acme): generate documentation Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * fix: apply suggestions from code review Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * refactor: extract common fields into BasePluginData Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * fix: restrict plugin resource to type=dns only because type=standalone is not configurable and always enabled by default. Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * fix: remove unused 'nodes' property https://github.com/bpg/terraform-provider-proxmox/pull/1479/files#r1710916265 Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * fix: remove "delete" property https://github.com/bpg/terraform-provider-proxmox/pull/1479/files#r1710908809 Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * feat: implement attribute deletion Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * fix: ignore empty lines in dns plugin data Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * fix: partial revert of code review suggestions Joining the values with a string literal would produce \\n instead of \n and splitting at \\n doesn't match a newline. Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * refactor: extract acme plugin models into separate file Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * fix: format disable parameter as int Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> --------- Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
84 lines
2.2 KiB
Go
84 lines
2.2 KiB
Go
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
package plugins
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"sort"
|
|
|
|
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
|
|
)
|
|
|
|
// List returns a list of ACME plugins.
|
|
func (c *Client) List(ctx context.Context) ([]*ACMEPluginsListResponseData, error) {
|
|
resBody := &ACMEPluginsListResponseBody{}
|
|
|
|
err := c.DoRequest(ctx, http.MethodGet, c.ExpandPath(""), nil, resBody)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error listing ACME plugins: %w", err)
|
|
}
|
|
|
|
if resBody.Data == nil {
|
|
return nil, api.ErrNoDataObjectInResponse
|
|
}
|
|
|
|
sort.Slice(resBody.Data, func(i, j int) bool {
|
|
return resBody.Data[i].Plugin < resBody.Data[j].Plugin
|
|
})
|
|
|
|
return resBody.Data, nil
|
|
}
|
|
|
|
// Get retrieves a single ACME plugin based on its identifier.
|
|
func (c *Client) Get(ctx context.Context, id string) (*ACMEPluginsGetResponseData, error) {
|
|
resBody := &ACMEPluginsGetResponseBody{}
|
|
|
|
err := c.DoRequest(ctx, http.MethodGet, c.ExpandPath(url.PathEscape(id)), nil, resBody)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error reading ACME plugin: %w", err)
|
|
}
|
|
|
|
if resBody.Data == nil {
|
|
return nil, api.ErrNoDataObjectInResponse
|
|
}
|
|
|
|
return resBody.Data, nil
|
|
}
|
|
|
|
// Create creates a new ACME plugin.
|
|
func (c *Client) Create(ctx context.Context, data *ACMEPluginsCreateRequestBody) error {
|
|
err := c.DoRequest(ctx, http.MethodPost, c.ExpandPath(""), data, nil)
|
|
if err != nil {
|
|
return fmt.Errorf("error creating ACME plugin: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Update updates an existing ACME plugin.
|
|
func (c *Client) Update(ctx context.Context, id string, data *ACMEPluginsUpdateRequestBody) error {
|
|
err := c.DoRequest(ctx, http.MethodPut, c.ExpandPath(url.PathEscape(id)), data, nil)
|
|
if err != nil {
|
|
return fmt.Errorf("error updating ACME plugin: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Delete removes an ACME plugin.
|
|
func (c *Client) Delete(ctx context.Context, id string) error {
|
|
err := c.DoRequest(ctx, http.MethodDelete, c.ExpandPath(url.PathEscape(id)), nil, nil)
|
|
if err != nil {
|
|
return fmt.Errorf("error deleting ACME plugin: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|