@@ -30,12 +30,12 @@ func List(c *drycc.Client, appID string, results int) (api.PodsList, int, error)
3030}
3131
3232// Exec a command in a container.
33- func Exec (c * drycc.Client , app , pod string , command api.Command ) (* websocket.Conn , error ) {
33+ func Exec (c * drycc.Client , appID , podID string , command api.Command ) (* websocket.Conn , error ) {
3434 scheme := "ws"
3535 if c .ControllerURL .Scheme == "https" {
3636 scheme = "wss"
3737 }
38- path := fmt .Sprintf ("v2/apps/%s/pods/%s/exec/" , app , pod )
38+ path := fmt .Sprintf ("v2/apps/%s/pods/%s/exec/" , appID , podID )
3939 u := url.URL {Scheme : scheme , Host : c .ControllerURL .Host , Path : path }
4040 config , err := websocket .NewConfig (u .String (), c .ControllerURL .String ())
4141 if err != nil {
@@ -54,6 +54,35 @@ func Exec(c *drycc.Client, app, pod string, command api.Command) (*websocket.Con
5454 return conn , nil
5555}
5656
57+ // Logs retrieves logs from an pod. The number of log lines fetched can be set by the lines
58+ func Logs (c * drycc.Client , appID , podID string , request api.PodLogsRequest ) (* websocket.Conn , error ) {
59+ scheme := "ws"
60+ if c .ControllerURL .Scheme == "https" {
61+ scheme = "wss"
62+ }
63+ path := fmt .Sprintf ("v2/apps/%s/pods/%s/logs/" , appID , podID )
64+ endpoint := url.URL {Scheme : scheme , Host : c .ControllerURL .Host , Path : path }
65+
66+ config , err := websocket .NewConfig (endpoint .String (), c .ControllerURL .String ())
67+ if err != nil {
68+ return nil , err
69+ }
70+ config .Header = http.Header {
71+ "User-Agent" : {c .UserAgent },
72+ "Authorization" : {"token " + c .Token },
73+ "X-Drycc-Builder-Auth" : {c .HooksToken },
74+ }
75+ conn , err := websocket .DialConfig (config )
76+ if err != nil {
77+ return nil , err
78+ }
79+ err = websocket .JSON .Send (conn , request )
80+ if err != nil {
81+ return nil , err
82+ }
83+ return conn , nil
84+ }
85+
5786// Scale increases or decreases an app's processes. The processes are specified in the target argument,
5887// a key-value map, where the key is the process name and the value is the number of replicas
5988func Scale (c * drycc.Client , appID string , targets map [string ]int ) error {
@@ -66,6 +95,9 @@ func Scale(c *drycc.Client, appID string, targets map[string]int) error {
6695 }
6796
6897 res , err := c .Request ("POST" , u , body )
98+ if err != nil && ! drycc .IsErrAPIMismatch (err ) {
99+ return err
100+ }
69101 defer res .Body .Close ()
70102 return err
71103}
@@ -83,6 +115,9 @@ func Restart(c *drycc.Client, appID string, procType string) error {
83115 }
84116
85117 res , err := c .Request ("POST" , u , nil )
118+ if err != nil && ! drycc .IsErrAPIMismatch (err ) {
119+ return err
120+ }
86121 defer res .Body .Close ()
87122 return err
88123}
0 commit comments