Skip to content

Commit 149e114

Browse files
committed
opUser from context all rolled out
1 parent 5e76a2d commit 149e114

File tree

13 files changed

+29
-30
lines changed

13 files changed

+29
-30
lines changed

clients.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/ctdk/goiardi/actor"
2424
"github.com/ctdk/goiardi/client"
2525
"github.com/ctdk/goiardi/loginfo"
26+
"github.com/ctdk/goiardi/reqctx"
2627
"github.com/ctdk/goiardi/util"
2728
"net/http"
2829
)
@@ -31,7 +32,7 @@ func clientHandler(w http.ResponseWriter, r *http.Request) {
3132
w.Header().Set("Content-Type", "application/json")
3233
path := splitPath(r.URL.Path)
3334
clientName := path[1]
34-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
35+
opUser, oerr := reqctx.CtxReqUser(r.Context())
3536
if oerr != nil {
3637
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
3738
return

cookbooks.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ package main
2121
import (
2222
"encoding/json"
2323
"fmt"
24-
"github.com/ctdk/goiardi/actor"
2524
"github.com/ctdk/goiardi/cookbook"
2625
"github.com/ctdk/goiardi/loginfo"
26+
"github.com/ctdk/goiardi/reqctx"
2727
"github.com/ctdk/goiardi/util"
2828
"net/http"
2929
)
@@ -33,7 +33,7 @@ func cookbookHandler(w http.ResponseWriter, r *http.Request) {
3333
pathArray := splitPath(r.URL.Path)
3434
cookbookResponse := make(map[string]interface{})
3535

36-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
36+
opUser, oerr := reqctx.CtxReqUser(r.Context())
3737
if oerr != nil {
3838
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
3939
return
@@ -101,10 +101,7 @@ func cookbookHandler(w http.ResponseWriter, r *http.Request) {
101101
headResponse(w, r, http.StatusOK)
102102
return
103103
}
104-
permCheck := func(r *http.Request, clientName string, opUser actor.Actor) util.Gerror {
105-
return nil // because this is always OK
106-
}
107-
headChecking(w, r, opUser, cookbookName, cookbook.DoesExist, permCheck)
104+
headChecking(w, r, opUser, cookbookName, cookbook.DoesExist, nilPermCheck)
108105
return
109106
}
110107

@@ -148,7 +145,7 @@ func cookbookHandler(w http.ResponseWriter, r *http.Request) {
148145
cookbookName := pathArray[1]
149146
var cookbookVersion string
150147
var vererr util.Gerror
151-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
148+
opUser, oerr := reqctx.CtxReqUser(r.Context())
152149
if oerr != nil {
153150
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
154151
return
@@ -174,10 +171,7 @@ func cookbookHandler(w http.ResponseWriter, r *http.Request) {
174171
headResponse(w, r, err.Status())
175172
return
176173
}
177-
permCheck := func(r *http.Request, cbv string, opUser actor.Actor) util.Gerror {
178-
return nil // because this is always OK
179-
}
180-
headChecking(w, r, opUser, cookbookVersion, cb.DoesVersionExist, permCheck)
174+
headChecking(w, r, opUser, cookbookVersion, cb.DoesVersionExist, nilPermCheck)
181175
return
182176
case http.MethodDelete, http.MethodGet:
183177
if opUser.IsValidator() {

data.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/ctdk/goiardi/actor"
2525
"github.com/ctdk/goiardi/databag"
2626
"github.com/ctdk/goiardi/loginfo"
27+
"github.com/ctdk/goiardi/reqctx"
2728
"github.com/ctdk/goiardi/util"
2829
"net/http"
2930
)
@@ -34,7 +35,7 @@ func dataHandler(w http.ResponseWriter, r *http.Request) {
3435
pathArray := splitPath(r.URL.Path)
3536

3637
dbResponse := make(map[string]interface{})
37-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
38+
opUser, oerr := reqctx.CtxReqUser(r.Context())
3839
if oerr != nil {
3940
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
4041
return

environments.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/ctdk/goiardi/environment"
3030
"github.com/ctdk/goiardi/loginfo"
3131
"github.com/ctdk/goiardi/node"
32+
"github.com/ctdk/goiardi/reqctx"
3233
"github.com/ctdk/goiardi/role"
3334
"github.com/ctdk/goiardi/util"
3435
"github.com/tideland/golib/logger"
@@ -42,7 +43,7 @@ func environmentHandler(w http.ResponseWriter, r *http.Request) {
4243
return
4344
}
4445

45-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
46+
opUser, oerr := reqctx.CtxReqUser(r.Context())
4647
if oerr != nil {
4748
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
4849
return

events.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"github.com/ctdk/goiardi/actor"
2525
"github.com/ctdk/goiardi/loginfo"
26+
"github.com/ctdk/goiardi/reqctx"
2627
"github.com/ctdk/goiardi/util"
2728
"net/http"
2829
"strconv"
@@ -31,7 +32,7 @@ import (
3132
// The whole list
3233
func eventListHandler(w http.ResponseWriter, r *http.Request) {
3334
w.Header().Set("Content-Type", "application/json")
34-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
35+
opUser, oerr := reqctx.CtxReqUser(r.Context())
3536
if oerr != nil {
3637
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
3738
return
@@ -168,7 +169,7 @@ func eventListHandler(w http.ResponseWriter, r *http.Request) {
168169
// Individual log events
169170
func eventHandler(w http.ResponseWriter, r *http.Request) {
170171
w.Header().Set("Content-Type", "application/json")
171-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
172+
opUser, oerr := reqctx.CtxReqUser(r.Context())
172173
if oerr != nil {
173174
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
174175
return

lists.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package main
2121
import (
2222
"encoding/json"
2323
"fmt"
24-
"github.com/ctdk/goiardi/actor"
2524
"github.com/ctdk/goiardi/client"
2625
"github.com/ctdk/goiardi/loginfo"
2726
"github.com/ctdk/goiardi/node"

reports.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package main
1919
import (
2020
"encoding/json"
2121
"fmt"
22-
"github.com/ctdk/goiardi/actor"
2322
"github.com/ctdk/goiardi/report"
23+
"github.com/ctdk/goiardi/reqctx"
2424
"github.com/ctdk/goiardi/util"
2525
"net/http"
2626
"net/url"
@@ -51,7 +51,7 @@ func reportHandler(w http.ResponseWriter, r *http.Request) {
5151
return
5252
}
5353

54-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
54+
opUser, oerr := reqctx.CtxReqUser(r.Context())
5555
if oerr != nil {
5656
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
5757
return

roles.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/ctdk/goiardi/actor"
2424
"github.com/ctdk/goiardi/environment"
2525
"github.com/ctdk/goiardi/loginfo"
26+
"github.com/ctdk/goiardi/reqctx"
2627
"github.com/ctdk/goiardi/role"
2728
"github.com/ctdk/goiardi/util"
2829
"net/http"
@@ -31,7 +32,7 @@ import (
3132
func roleHandler(w http.ResponseWriter, r *http.Request) {
3233
w.Header().Set("Content-Type", "application/json")
3334

34-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
35+
opUser, oerr := reqctx.CtxReqUser(r.Context())
3536
if oerr != nil {
3637
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
3738
return

sandboxes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package main
2020

2121
import (
2222
"encoding/json"
23-
"github.com/ctdk/goiardi/actor"
23+
"github.com/ctdk/goiardi/reqctx"
2424
"github.com/ctdk/goiardi/sandbox"
2525
"github.com/ctdk/goiardi/util"
2626
"net/http"
@@ -30,7 +30,7 @@ func sandboxHandler(w http.ResponseWriter, r *http.Request) {
3030
w.Header().Set("Content-Type", "application/json")
3131
pathArray := splitPath(r.URL.Path)
3232
sboxResponse := make(map[string]interface{})
33-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
33+
opUser, oerr := reqctx.CtxReqUser(r.Context())
3434
if oerr != nil {
3535
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
3636
return

search.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ package main
2121
import (
2222
"encoding/json"
2323
"fmt"
24-
"github.com/ctdk/goiardi/actor"
2524
"github.com/ctdk/goiardi/client"
2625
"github.com/ctdk/goiardi/config"
2726
"github.com/ctdk/goiardi/databag"
2827
"github.com/ctdk/goiardi/environment"
2928
"github.com/ctdk/goiardi/indexer"
3029
"github.com/ctdk/goiardi/node"
30+
"github.com/ctdk/goiardi/reqctx"
3131
"github.com/ctdk/goiardi/role"
3232
"github.com/ctdk/goiardi/search"
3333
"github.com/ctdk/goiardi/util"
@@ -60,7 +60,7 @@ func searchHandler(w http.ResponseWriter, r *http.Request) {
6060
pathArray := splitPath(r.URL.Path)
6161
pathArrayLen := len(pathArray)
6262

63-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
63+
opUser, oerr := reqctx.CtxReqUser(r.Context())
6464
if oerr != nil {
6565
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
6666
return
@@ -204,7 +204,7 @@ func searchHandler(w http.ResponseWriter, r *http.Request) {
204204
func reindexHandler(w http.ResponseWriter, r *http.Request) {
205205
w.Header().Set("Content-Type", "application/json")
206206
reindexResponse := make(map[string]interface{})
207-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
207+
opUser, oerr := reqctx.CtxReqUser(r.Context())
208208
if oerr != nil {
209209
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
210210
return

shovey.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package main
1919
import (
2020
"encoding/json"
2121
"fmt"
22-
"github.com/ctdk/goiardi/actor"
2322
"github.com/ctdk/goiardi/config"
23+
"github.com/ctdk/goiardi/reqctx"
2424
"github.com/ctdk/goiardi/shovey"
2525
"github.com/ctdk/goiardi/util"
2626
"github.com/tideland/golib/logger"
@@ -30,7 +30,7 @@ import (
3030

3131
func shoveyHandler(w http.ResponseWriter, r *http.Request) {
3232
w.Header().Set("Content-Type", "application/json")
33-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
33+
opUser, oerr := reqctx.CtxReqUser(r.Context())
3434
if oerr != nil {
3535
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
3636
return

status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ package main
1919
import (
2020
"encoding/json"
2121
"fmt"
22-
"github.com/ctdk/goiardi/actor"
2322
"github.com/ctdk/goiardi/node"
23+
"github.com/ctdk/goiardi/reqctx"
2424
"github.com/ctdk/goiardi/util"
2525
"net/http"
2626
)
2727

2828
func statusHandler(w http.ResponseWriter, r *http.Request) {
2929
w.Header().Set("Content-Type", "application/json")
30-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
30+
opUser, oerr := reqctx.CtxReqUser(r.Context())
3131
if oerr != nil {
3232
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
3333
return

users.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/json"
2323
"github.com/ctdk/goiardi/actor"
2424
"github.com/ctdk/goiardi/loginfo"
25+
"github.com/ctdk/goiardi/reqctx"
2526
"github.com/ctdk/goiardi/user"
2627
"github.com/ctdk/goiardi/util"
2728
"net/http"
@@ -31,7 +32,7 @@ func userHandler(w http.ResponseWriter, r *http.Request) {
3132
w.Header().Set("Content-Type", "application/json")
3233
path := splitPath(r.URL.Path)
3334
userName := path[1]
34-
opUser, oerr := actor.GetReqUser(r.Header.Get("X-OPS-USERID"))
35+
opUser, oerr := reqctx.CtxReqUser(r.Context())
3536
if oerr != nil {
3637
jsonErrorReport(w, r, oerr.Error(), oerr.Status())
3738
return

0 commit comments

Comments
 (0)