MCPcopy
hub / github.com/koderover/zadig / NewContextWithAuthorization

Function NewContextWithAuthorization

pkg/shared/handler/base.go:137–150  ·  view source on GitHub ↗

NewContextWithAuthorization returns a context with user authorization info. This function should only be called when one need authorization information for api caller.

(c *gin.Context)

Source from the content-addressed store, hash-verified

135// NewContextWithAuthorization returns a context with user authorization info.
136// This function should only be called when one need authorization information for api caller.
137func NewContextWithAuthorization(c *gin.Context) (*Context, error) {
138 logger := ginzap.WithContext(c).Sugar()
139 var resourceAuthInfo *user.AuthorizedResources
140 var err error
141 resp := NewContext(c)
142 // there is a case where the request does not have token (system call), in this case we will have admin access
143 resourceAuthInfo, err = user.New().GetUserAuthInfo(resp.UserID)
144 if err != nil {
145 logger.Errorf("failed to generate user authorization info, error: %s", err)
146 return resp, err
147 }
148 resp.Resources = resourceAuthInfo
149 return resp, nil
150}
151
152func NewBackgroupContext() *Context {
153 return &Context{

Callers

nothing calls this directly

Calls 5

WithContextFunction · 0.92
NewFunction · 0.92
GetUserAuthInfoMethod · 0.80
NewContextFunction · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected