Skip to content

Commit

Permalink
Issue fabric8-services#143 Creates endpoint to clean user data from a…
Browse files Browse the repository at this point in the history
… namespace
  • Loading branch information
lordofthejars committed Jul 24, 2018
1 parent 740e88b commit 4f3339e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/fabric8-jenkins-idler/idler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (idler *Idler) startWorkers(ctx context.Context, wg *sync.WaitGroup, cancel
apirouter := router.CreateAPIRouter(idlerAPI)
router := router.NewRouter(apirouter)
router.AddMetrics(apirouter)
router.AddCleanData(apirouter, userIdlers)
router.Start(ctx, wg, cancel)
}()

Expand Down
16 changes: 16 additions & 0 deletions internal/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (
"time"

"github.com/fabric8-services/fabric8-jenkins-idler/internal/api"
"github.com/fabric8-services/fabric8-jenkins-idler/internal/openshift"
"github.com/julienschmidt/httprouter"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)

var routerLogger = log.WithFields(log.Fields{"component": "router"})
var userIdlersData *openshift.UserIdlerMap

const (
defaultHTTPServerPort = 8080
Expand Down Expand Up @@ -46,6 +48,20 @@ func (r *Router) AddMetrics(router *httprouter.Router) {
router.Handler("GET", "/metrics", prometheus.Handler())
}

func deleteUserInfoInNamespace(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

ns := ps.ByName("namespace")
userIdlersData.Delete(ns)

w.WriteHeader(http.StatusOK)
}

// AddCleanData adds a route endpoint to remove all data from a given namespace
func (r *Router) AddCleanData(router *httprouter.Router, userIdlers *openshift.UserIdlerMap) {
userIdlersData = userIdlers
router.DELETE("/users/:namespace", deleteUserInfoInNamespace)
}

// Start starts the HTTP router.
func (r *Router) Start(ctx context.Context, wg *sync.WaitGroup, cancel context.CancelFunc) {
wg.Add(1)
Expand Down

0 comments on commit 4f3339e

Please sign in to comment.