38 lines
1.7 KiB
Go
38 lines
1.7 KiB
Go
package panel
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"net/url"
|
|
"regexp"
|
|
"strconv"
|
|
)
|
|
|
|
var managedPasswordPattern = regexp.MustCompile(`^[A-Za-z0-9_-]{20,128}$`)
|
|
|
|
func (c *Client) SetFTPPassword(ctx context.Context, id int64, name, password string) error {
|
|
if id <= 0 || !brokerHostPattern.MatchString(name) || !managedPasswordPattern.MatchString(password) {
|
|
return errors.New("invalid managed credential reset")
|
|
}
|
|
_, err := c.call(ctx, http.MethodPost, "/ftp", url.Values{"action": {"SetUserPassword"}, "id": {strconv.FormatInt(id, 10)}, "ftp_username": {name}, "new_password": {password}})
|
|
return err
|
|
}
|
|
func (c *Client) SetDatabasePassword(ctx context.Context, id int64, name, password string) error {
|
|
if id <= 0 || !brokerHostPattern.MatchString(name) || !managedPasswordPattern.MatchString(password) {
|
|
return errors.New("invalid managed credential reset")
|
|
}
|
|
_, err := c.call(ctx, http.MethodPost, "/database", url.Values{"action": {"ResDatabasePassword"}, "id": {strconv.FormatInt(id, 10)}, "name": {name}, "password": {password}})
|
|
return err
|
|
}
|
|
func (c *BrokerClient) SetFTPPassword(ctx context.Context, id int64, name, password string) error {
|
|
_, err := c.operation(ctx, brokerRequest{Operation: "set_ftp_password", ID: id, Username: name, Password: password})
|
|
return err
|
|
}
|
|
func (c *BrokerClient) SetDatabasePassword(ctx context.Context, id int64, name, password string) error {
|
|
_, err := c.operation(ctx, brokerRequest{Operation: "set_database_password", ID: id, Name: name, Password: password})
|
|
return err
|
|
}
|
|
func (*Mock) SetFTPPassword(context.Context, int64, string, string) error { return nil }
|
|
func (*Mock) SetDatabasePassword(context.Context, int64, string, string) error { return nil }
|