Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/internal/jenkinsapi/jenkinsapi.go b/internal/jenkinsapi/jenkinsapi.go
- index 70ad8c5..51ff2c6 100644
- --- a/internal/jenkinsapi/jenkinsapi.go
- +++ b/internal/jenkinsapi/jenkinsapi.go
- @@ -15,6 +15,7 @@ import (
- //JenkinsAPI contains API to check whether Jenkins for the current user is idle|running|starting
- type JenkinsAPI interface {
- Start(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- + Status(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- }
- // JenkinsAPIImpl implements JenkinsAPI
- @@ -31,6 +32,34 @@ func NewJenkinsAPI(tenant clients.TenantService, idler clients.IdlerService) Jen
- }
- }
- +// Returns the Jenkins pods status for current user
- +func (api *jenkinsAPIImpl) Status(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
- + resp := clients.StatusResponse{}
- +
- + authHeader := r.Header.Get("Authorization")
- + if !strings.HasPrefix(authHeader, "Bearer ") {
- + HandleError(w, resp, errors.New("Could not find Bearer token in Authorization Header"), http.StatusUnauthorized)
- + return
- + }
- + accessToken := strings.Split(r.Header.Get("Authorization"), " ")[1]
- + namespace, err := api.tenant.GetNamespace(accessToken)
- + if err != nil {
- + HandleError(w, resp, err, http.StatusUnauthorized)
- + return
- + }
- + log.Infof("Found token info in the query. Namespace is %s and clusterURL is %s", namespace.Name, namespace.ClusterURL)
- +
- + status, err := api.idler.State(namespace.Name, namespace.ClusterURL)
- + if err != nil {
- + HandleError(w, resp, err, http.StatusInternalServerError)
- + return
- + }
- + resp.Data = &clients.JenkinsInfo{
- + State: status,
- + }
- + json.NewEncoder(w).Encode(resp)
- +}
- +
- // Start returns the Jenkins status for the current user
- func (api *jenkinsAPIImpl) Start(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
- resp := clients.StatusResponse{}
- diff --git a/internal/router/router.go b/internal/router/router.go
- index cbf9775..cec53c3 100644
- --- a/internal/router/router.go
- +++ b/internal/router/router.go
- @@ -27,6 +27,14 @@ func CreateJenkinsAPIRouter(jenkinsAPI jenkinsapi.JenkinsAPI) *httprouter.Router
- return jenkinsAPIRouter
- }
- +// GetJenkinsStatus is getting status of jenkins pods
- +func GetJenkinsPodsStatus(jenkinsAPI jenkinsapi.JenkinsAPI) *httprouter.Router {
- + // Create router for API
- + jenkinsAPIRouter := httprouter.New()
- + jenkinsAPIRouter.GET("/api/jenkins/status", jenkinsAPI.Status);
- + return jenkinsAPIRouter
- +}
- +
- // CreateProxyRouter is the HTTP server handler which handles the incoming webhook and UI requests.
- func CreateProxyRouter(proxy *proxy.Proxy) *http.ServeMux {
- proxyMux := http.NewServeMux()
Add Comment
Please, Sign In to add comment