Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
parametalol committed Nov 27, 2023
1 parent 957304e commit 30cfaed
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
7 changes: 7 additions & 0 deletions internal/dinosaur/pkg/api/admin/private/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ paths:
schema:
type: string
style: form
- explode: true
in: query
name: reason
required: true
schema:
type: string
style: form
responses:
"200":
content:
Expand Down
4 changes: 3 additions & 1 deletion internal/dinosaur/pkg/api/admin/private/api_default.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 23 additions & 7 deletions internal/dinosaur/pkg/handlers/admin_dinosaur.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"net/http"
"time"

"github.com/golang/glog"
"github.com/gorilla/mux"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/admin/private"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/dbapi"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/public"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/config"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/presenters"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/services"
"github.com/stackrox/acs-fleet-manager/pkg/api"
"github.com/stackrox/acs-fleet-manager/pkg/errors"
"github.com/stackrox/acs-fleet-manager/pkg/handlers"
coreServices "github.com/stackrox/acs-fleet-manager/pkg/services"
Expand Down Expand Up @@ -238,16 +240,30 @@ func (h adminCentralHandler) RotateSecrets(w http.ResponseWriter, r *http.Reques
func (h adminCentralHandler) SetExpiredAt(w http.ResponseWriter, r *http.Request) {
cfg := &handlers.HandlerConfig{
Action: func() (i interface{}, serviceError *errors.ServiceError) {
reason := r.PostFormValue("reason")
if reason == "" {
return nil, errors.New(errors.ErrorBadRequest, "No reason provided")
}

id := mux.Vars(r)["id"]
ts := r.PostForm.Get("timestamp")
central := &dbapi.CentralRequest{ClusterID: id}
expired_at, err := time.Parse(time.RFC3339, ts)
if err != nil {
return nil, errors.NewWithCause(errors.ErrorBadRequest, err, "Cannot parse timestamp: %s", err.Error())
ts := r.PostFormValue("timestamp")
expired_at := time.Now()
if ts != "" {
var err error
expired_at, err = time.Parse(time.RFC3339, ts)
if err != nil {
return nil, errors.NewWithCause(errors.ErrorBadRequest, err, "Cannot parse timestamp: %s", err.Error())
}
}
return nil, h.service.Updates(central, map[string]interface{}{
"expired_at": expired_at.UTC().Format(time.RFC3339),
glog.Warningf("Setting expired_at to %q for central %q: %s", ts, id, reason)
central := &dbapi.CentralRequest{Meta: api.Meta{ID: id}}
svcErr := h.service.Updates(central, map[string]interface{}{
"expired_at": &expired_at,
})
if svcErr != nil {
glog.Warningf("error: ", svcErr)
}
return nil, svcErr
},
}
handlers.Handle(w, r, cfg, http.StatusOK)
Expand Down
5 changes: 5 additions & 0 deletions openapi/fleet-manager-private-admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ paths:
schema:
type: string
required: false
- in: query
name: reason
schema:
type: string
required: true
security:
- Bearer: [ ]
operationId: updateCentralExpiredAtById
Expand Down

0 comments on commit 30cfaed

Please sign in to comment.