mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-30 10:11:23 +02:00
commit
3c50918eb5
@ -35,11 +35,7 @@ const (
|
||||
pathUsers = "%s/api/users"
|
||||
pathUser = "%s/api/users/%s"
|
||||
pathBuildQueue = "%s/api/builds"
|
||||
pathServers = "%s/api/servers"
|
||||
pathServer = "%s/api/servers/%s"
|
||||
pathScalerPause = "%s/api/pause"
|
||||
pathScalerResume = "%s/api/resume"
|
||||
pathVarz = "%s/varz"
|
||||
pathQueue = "%s/api/queue"
|
||||
pathVersion = "%s/version"
|
||||
)
|
||||
|
||||
@ -48,53 +44,6 @@ type client struct {
|
||||
addr string
|
||||
}
|
||||
|
||||
// // Options provides a list of client options.
|
||||
// type Options struct {
|
||||
// token string
|
||||
// proxy string
|
||||
// pool *x509.CertPool
|
||||
// conf *tls.Config
|
||||
// skip bool
|
||||
// }
|
||||
//
|
||||
// // Option defines client options.
|
||||
// type Option func(opts *Options)
|
||||
//
|
||||
// // WithToken returns an option to set the token.
|
||||
// func WithToken(token string) Option {
|
||||
// return func(opts *Options) {
|
||||
// opts.token = token
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // WithTLS returns an option to use custom tls configuration.
|
||||
// func WithTLS(conf *tls.Config) Option {
|
||||
// return func(opts *Options) {
|
||||
// opts.conf = conf
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // WithSocks returns a client option to provide a socks5 proxy.
|
||||
// func WithSocks(proxy string) Option {
|
||||
// return func(opts *Options) {
|
||||
// opts.proxy = proxy
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // WithSkipVerify returns a client option to skip ssl verification.
|
||||
// func WithSkipVerify(skip bool) Option {
|
||||
// return func(opts *Options) {
|
||||
// opts.skip = skip
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // WithCertPool returns a client option to provide a custom cert pool.
|
||||
// func WithCertPool(pool *x509.CertPool) Option {
|
||||
// return func(opts *Options) {
|
||||
// opts.pool = pool
|
||||
// }
|
||||
// }
|
||||
|
||||
// New returns a client at the specified url.
|
||||
func New(uri string) Client {
|
||||
return &client{http.DefaultClient, strings.TrimSuffix(uri, "/")}
|
||||
@ -406,52 +355,9 @@ func (c *client) SecretDelete(owner, name, secret string) error {
|
||||
return c.delete(uri)
|
||||
}
|
||||
|
||||
// Server returns the named servers details.
|
||||
func (c *client) Server(name string) (*Server, error) {
|
||||
out := new(Server)
|
||||
uri := fmt.Sprintf(pathServer, c.addr, name)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// ServerList returns a list of all active build servers.
|
||||
func (c *client) ServerList() ([]*Server, error) {
|
||||
var out []*Server
|
||||
uri := fmt.Sprintf(pathServers, c.addr)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// ServerCreate creates a new server.
|
||||
func (c *client) ServerCreate() (*Server, error) {
|
||||
out := new(Server)
|
||||
uri := fmt.Sprintf(pathServers, c.addr)
|
||||
err := c.post(uri, nil, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// ServerDelete terminates a server.
|
||||
func (c *client) ServerDelete(name string) error {
|
||||
uri := fmt.Sprintf(pathServer, c.addr, name)
|
||||
return c.delete(uri)
|
||||
}
|
||||
|
||||
// AutoscalePause pauses the autoscaler.
|
||||
func (c *client) AutoscalePause() error {
|
||||
uri := fmt.Sprintf(pathScalerPause, c.addr)
|
||||
return c.post(uri, nil, nil)
|
||||
}
|
||||
|
||||
// AutoscaleResume resumes the autoscaler.
|
||||
func (c *client) AutoscaleResume() error {
|
||||
uri := fmt.Sprintf(pathScalerResume, c.addr)
|
||||
return c.post(uri, nil, nil)
|
||||
}
|
||||
|
||||
// AutoscaleVersion resumes the autoscaler.
|
||||
func (c *client) AutoscaleVersion() (*Version, error) {
|
||||
out := new(Version)
|
||||
uri := fmt.Sprintf(pathVersion, c.addr)
|
||||
func (c *client) QueueInfo() (*Info, error) {
|
||||
out := new(Info)
|
||||
uri := fmt.Sprintf(pathQueue+"/info", c.addr)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
46
drone-go/drone/client_test.go
Normal file
46
drone-go/drone/client_test.go
Normal file
@ -0,0 +1,46 @@
|
||||
package drone
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_QueueInfo(t *testing.T) {
|
||||
fixtureHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{
|
||||
"pending": null,
|
||||
"running": [
|
||||
{
|
||||
"id": "4696",
|
||||
"data": "",
|
||||
"labels": {
|
||||
"platform": "linux/amd64",
|
||||
"repo": "laszlocph/drone-oss-08"
|
||||
},
|
||||
"Dependencies": [],
|
||||
"DepStatus": {},
|
||||
"RunOn": null
|
||||
}
|
||||
],
|
||||
"stats": {
|
||||
"worker_count": 3,
|
||||
"pending_count": 0,
|
||||
"running_count": 1,
|
||||
"completed_count": 0
|
||||
},
|
||||
"Paused": false
|
||||
}`)
|
||||
}
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(fixtureHandler))
|
||||
defer ts.Close()
|
||||
|
||||
client := NewClient(ts.URL, http.DefaultClient)
|
||||
|
||||
info, err := client.QueueInfo()
|
||||
if info.Stats.Workers != 3 {
|
||||
t.Errorf("Unexpected worker count: %v, %v", info, err)
|
||||
}
|
||||
}
|
@ -123,24 +123,6 @@ type Client interface {
|
||||
// SecretDelete deletes a secret.
|
||||
SecretDelete(owner, name, secret string) error
|
||||
|
||||
// Server returns the named servers details.
|
||||
Server(name string) (*Server, error)
|
||||
|
||||
// ServerList returns a list of all active build servers.
|
||||
ServerList() ([]*Server, error)
|
||||
|
||||
// ServerCreate creates a new server.
|
||||
ServerCreate() (*Server, error)
|
||||
|
||||
// ServerDelete terminates a server.
|
||||
ServerDelete(name string) error
|
||||
|
||||
// AutoscalePause pauses the autoscaler.
|
||||
AutoscalePause() error
|
||||
|
||||
// AutoscaleResume resumes the autoscaler.
|
||||
AutoscaleResume() error
|
||||
|
||||
// AutoscaleVersion returns the autoscaler version.
|
||||
AutoscaleVersion() (*Version, error)
|
||||
// QueueInfo returns the queue state.
|
||||
QueueInfo() (*Info, error)
|
||||
}
|
||||
|
@ -140,33 +140,21 @@ type (
|
||||
Email string `json:"author_email,omitempty"`
|
||||
}
|
||||
|
||||
// Server represents a server node.
|
||||
Server struct {
|
||||
ID string `json:"id"`
|
||||
Provider string `json:"provider"`
|
||||
State string `json:"state"`
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
Region string `json:"region"`
|
||||
Size string `json:"size"`
|
||||
Address string `json:"address"`
|
||||
Capacity int `json:"capacity"`
|
||||
Secret string `json:"secret"`
|
||||
Error string `json:"error"`
|
||||
CAKey []byte `json:"ca_key"`
|
||||
CACert []byte `json:"ca_cert"`
|
||||
TLSKey []byte `json:"tls_key"`
|
||||
TLSCert []byte `json:"tls_cert"`
|
||||
Created int64 `json:"created"`
|
||||
Updated int64 `json:"updated"`
|
||||
Started int64 `json:"started"`
|
||||
Stopped int64 `json:"stopped"`
|
||||
}
|
||||
|
||||
// Version provides system version details.
|
||||
Version struct {
|
||||
Source string `json:"source,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Commit string `json:"commit,omitempty"`
|
||||
}
|
||||
|
||||
// Info provides queue stats.
|
||||
Info struct {
|
||||
Stats struct {
|
||||
Workers int `json:"worker_count"`
|
||||
Pending int `json:"pending_count"`
|
||||
Running int `json:"running_count"`
|
||||
Complete int `json:"completed_count"`
|
||||
} `json:"stats"`
|
||||
Paused bool `json:"paused,omitempty"`
|
||||
}
|
||||
)
|
||||
|
@ -140,16 +140,12 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl
|
||||
)
|
||||
}
|
||||
|
||||
info := e.Group("/api/info")
|
||||
queue := e.Group("/api/queue")
|
||||
{
|
||||
info.GET("/queue",
|
||||
queue.GET("/info",
|
||||
session.MustAdmin(),
|
||||
server.GetQueueInfo,
|
||||
)
|
||||
}
|
||||
|
||||
queue := e.Group("/api/queue")
|
||||
{
|
||||
queue.GET("/pause",
|
||||
session.MustAdmin(),
|
||||
server.PauseQueue,
|
||||
|
Loading…
Reference in New Issue
Block a user