2024-04-26 11:46:55 +00:00
|
|
|
package woodpecker
|
|
|
|
|
2024-11-27 06:53:35 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
)
|
2024-04-26 11:46:55 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
pathGlobalSecrets = "%s/api/secrets"
|
|
|
|
pathGlobalSecret = "%s/api/secrets/%s"
|
|
|
|
)
|
|
|
|
|
2024-05-04 12:13:43 +00:00
|
|
|
// GlobalSecret returns an global secret by name.
|
2024-04-26 11:46:55 +00:00
|
|
|
func (c *client) GlobalSecret(secret string) (*Secret, error) {
|
|
|
|
out := new(Secret)
|
|
|
|
uri := fmt.Sprintf(pathGlobalSecret, c.addr, secret)
|
|
|
|
err := c.get(uri, out)
|
|
|
|
return out, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobalSecretList returns a list of all global secrets.
|
2024-11-27 06:53:35 +00:00
|
|
|
func (c *client) GlobalSecretList(opt SecretListOptions) ([]*Secret, error) {
|
2024-04-26 11:46:55 +00:00
|
|
|
var out []*Secret
|
2024-11-27 06:53:35 +00:00
|
|
|
uri, _ := url.Parse(fmt.Sprintf(pathGlobalSecrets, c.addr))
|
|
|
|
uri.RawQuery = opt.getURLQuery().Encode()
|
|
|
|
err := c.get(uri.String(), &out)
|
2024-04-26 11:46:55 +00:00
|
|
|
return out, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobalSecretCreate creates a global secret.
|
|
|
|
func (c *client) GlobalSecretCreate(in *Secret) (*Secret, error) {
|
|
|
|
out := new(Secret)
|
|
|
|
uri := fmt.Sprintf(pathGlobalSecrets, c.addr)
|
|
|
|
err := c.post(uri, in, out)
|
|
|
|
return out, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobalSecretUpdate updates a global secret.
|
|
|
|
func (c *client) GlobalSecretUpdate(in *Secret) (*Secret, error) {
|
|
|
|
out := new(Secret)
|
|
|
|
uri := fmt.Sprintf(pathGlobalSecret, c.addr, in.Name)
|
|
|
|
err := c.patch(uri, in, out)
|
|
|
|
return out, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobalSecretDelete deletes a global secret.
|
|
|
|
func (c *client) GlobalSecretDelete(secret string) error {
|
|
|
|
uri := fmt.Sprintf(pathGlobalSecret, c.addr, secret)
|
|
|
|
return c.delete(uri)
|
|
|
|
}
|