-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: introducing the auth
package (removing bascule, spf13 and jwt dependency)
#273
Conversation
auth/acquire.go
Outdated
package auth | ||
|
||
// Acquirer acquires the credential for http request authorization headers. | ||
type Acquirer interface { | ||
// Acquire gets a credential string. | ||
Acquire() (string, error) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaces bascule.Acquirer
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #273 +/- ##
==========================================
+ Coverage 82.58% 83.29% +0.70%
==========================================
Files 18 19 +1
Lines 890 808 -82
==========================================
- Hits 735 673 -62
+ Misses 130 117 -13
+ Partials 25 18 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
type PartnerIDsKey struct{} | ||
|
||
type PrincipalKey struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get partnerIDs and Principal instead of relying on bascule
func extractPartnerIDs(config transportConfig, c context.Context, r *http.Request) ([]string, error) { | ||
auth, present := bascule.FromContext(c) | ||
if !present { | ||
return nil, errAuthNotPresent | ||
} | ||
if auth.Token == nil { | ||
return nil, errAuthTokenIsNil | ||
} | ||
|
||
var partners []string | ||
|
||
switch auth.Token.Type() { | ||
case basicstr: | ||
authHeader := r.Header[config.basicPartnerIDsHeader] | ||
for _, value := range authHeader { | ||
fields := strings.Split(value, ",") | ||
for i := 0; i < len(fields); i++ { | ||
fields[i] = strings.TrimSpace(fields[i]) | ||
} | ||
partners = append(partners, fields...) | ||
} | ||
return partners, nil | ||
case jwtstr: | ||
authToken := auth.Token | ||
partnersInterface, attrExist := bascule.GetNestedAttribute(authToken.Attributes(), basculechecks.PartnerKeys()...) | ||
if !attrExist { | ||
return nil, errPartnerIDsDoNotExist | ||
} | ||
vals, err := cast.ToStringSliceE(partnersInterface) | ||
if err != nil { | ||
return nil, fmt.Errorf("%w: %v", errGettingPartnerIDs, err) | ||
} | ||
partners = vals | ||
return partners, nil | ||
} | ||
return nil, errAuthIsNotOfTypeBasicOrJWT | ||
} | ||
|
||
func encodeAddWebhookResponse(ctx context.Context, rw http.ResponseWriter, _ interface{}) error { | ||
rw.Header().Set(contentTypeHeader, jsonContentType) | ||
rw.Write([]byte(`{"message": "Success"}`)) | ||
return nil | ||
} | ||
|
||
func getOwner(ctx context.Context) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting principal and partner ids via context instead of using bascule
auth.Acquirer
interfaceauth
package (removing bascule and jwt dependency)
cfaf49c
to
acc3c87
Compare
auth
package (removing bascule and jwt dependency) auth
package (removing bascule and jwt dependency)
"io" | ||
"net/http" | ||
|
||
"github.com/xmidt-org/ancla/auth" | ||
"github.com/xmidt-org/ancla/model" | ||
"github.com/xmidt-org/bascule/acquire" | ||
"go.uber.org/zap" | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace bascule acquire with ancla's auth.Acquirer
} | ||
return &acquire.DefaultAcquirer{}, nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required for bascule, no longer needed
cfg.BasicClientConfig.Auth.JWT.GetExpiration = p.expiration | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required by bascule, no longer needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭
auth
package (removing bascule and jwt dependency)auth
package (removing bascule, spf13 and jwt dependency)
acc3c87
to
f8c742d
Compare
… dependency) - removed bascule, spf13 and jwt dependency (and related code) by introducing the `auth` package - ancla will rely on the `auth.Acquirer` interface for cred renewal instead of using bascule - ancla will receive cred principal and partner IDs via context instead of using bascule
f8c742d
to
cc9b408
Compare
auth
packageauth.Acquirer
interface for cred renewal instead of using bascule