Squashed commit of the following:
commitf5baab4e88Author: DaneEveritt <dane@daneeveritt.com> Date: Sat Jul 9 17:50:53 2022 -0400 Finalize activity event sending logic and cron config commit9830387f21Author: DaneEveritt <dane@daneeveritt.com> Date: Sat Jul 9 16:26:13 2022 -0400 Send power events in a more usable format commit49f3a61d16Author: DaneEveritt <dane@daneeveritt.com> Date: Sat Jul 9 15:47:24 2022 -0400 Configure cron to actually send to endpoint commit28137c4c14Author: DaneEveritt <dane@daneeveritt.com> Date: Sat Jul 9 15:42:29 2022 -0400 Copy the body buffer otherwise subsequent backoff attempts will not have a buffer to send commit20e44bdc55Author: DaneEveritt <dane@daneeveritt.com> Date: Sat Jul 9 14:38:41 2022 -0400 Add internal logic to process activity events and send them to the panel commit0380488cd2Author: DaneEveritt <dane@daneeveritt.com> Date: Mon Jul 4 17:55:17 2022 -0400 Track power events commit9eab08b92fAuthor: DaneEveritt <dane@daneeveritt.com> Date: Mon Jul 4 17:36:03 2022 -0400 Initial logic to support logging activity on Wings to send back to the panel
This commit is contained in:
@@ -30,6 +30,7 @@ type Client interface {
|
||||
SetInstallationStatus(ctx context.Context, uuid string, successful bool) error
|
||||
SetTransferStatus(ctx context.Context, uuid string, successful bool) error
|
||||
ValidateSftpCredentials(ctx context.Context, request SftpAuthRequest) (SftpAuthResponse, error)
|
||||
SendActivityLogs(ctx context.Context, activity []json.RawMessage) error
|
||||
}
|
||||
|
||||
type client struct {
|
||||
@@ -128,10 +129,19 @@ func (c *client) requestOnce(ctx context.Context, method, path string, body io.R
|
||||
// and adds the required authentication headers to the request that is being
|
||||
// created. Errors returned will be of the RequestError type if there was some
|
||||
// type of response from the API that can be parsed.
|
||||
func (c *client) request(ctx context.Context, method, path string, body io.Reader, opts ...func(r *http.Request)) (*Response, error) {
|
||||
func (c *client) request(ctx context.Context, method, path string, body *bytes.Buffer, opts ...func(r *http.Request)) (*Response, error) {
|
||||
var res *Response
|
||||
err := backoff.Retry(func() error {
|
||||
r, err := c.requestOnce(ctx, method, path, body, opts...)
|
||||
var b bytes.Buffer
|
||||
if body != nil {
|
||||
// We have to create a copy of the body, otherwise attempting this request again will
|
||||
// send no data if there was initially a body since the "requestOnce" method will read
|
||||
// the whole buffer, thus leaving it empty at the end.
|
||||
if _, err := b.Write(body.Bytes()); err != nil {
|
||||
return backoff.Permanent(errors.Wrap(err, "http: failed to copy body buffer"))
|
||||
}
|
||||
}
|
||||
r, err := c.requestOnce(ctx, method, path, &b, opts...)
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return backoff.Permanent(err)
|
||||
|
||||
@@ -3,6 +3,7 @@ package remote
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/goccy/go-json"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
@@ -178,6 +179,16 @@ func (c *client) SendRestorationStatus(ctx context.Context, backup string, succe
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendActivityLogs sends activity logs back to the Panel for processing.
|
||||
func (c *client) SendActivityLogs(ctx context.Context, activity []json.RawMessage) error {
|
||||
resp, err := c.Post(ctx, "/activity", d{"data": activity})
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
}
|
||||
_ = resp.Body.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// getServersPaged returns a subset of servers from the Panel API using the
|
||||
// pagination query parameters.
|
||||
func (c *client) getServersPaged(ctx context.Context, page, limit int) ([]RawServerData, Pagination, error) {
|
||||
|
||||
@@ -2,11 +2,10 @@ package remote
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goccy/go-json"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/pterodactyl/wings/parser"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user