Skip to content
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

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

denopink
Copy link
Contributor

@denopink denopink commented Jan 9, 2025

  • 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

@denopink denopink added the enhancement improvement or small functionality added to an existing feature label Jan 9, 2025
@denopink denopink self-assigned this Jan 9, 2025
auth/acquire.go Outdated
Comment on lines 4 to 10
package auth

// Acquirer acquires the credential for http request authorization headers.
type Acquirer interface {
// Acquire gets a credential string.
Acquire() (string, error)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaces bascule.Acquirer

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 94.11765% with 2 lines in your changes missing coverage. Please review.

Project coverage is 83.29%. Comparing base (35dae74) to head (fef0665).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
transport.go 80.00% 1 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
unittests 83.29% <94.11%> (+0.70%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +8 to +10
type PartnerIDsKey struct{}

type PrincipalKey struct{}
Copy link
Contributor Author

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

Comment on lines -126 to -170
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 {
Copy link
Contributor Author

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

@denopink denopink changed the title feat: introduce ancla auth.Acquirer interface feat: introduce ancla auth package (removing bascule and jwt dependency) Jan 9, 2025
@denopink denopink force-pushed the denopink/feat/auth-interface branch 2 times, most recently from cfaf49c to acc3c87 Compare January 9, 2025 21:42
@denopink denopink changed the title feat: introduce ancla auth package (removing bascule and jwt dependency) feat: introducing the auth package (removing bascule and jwt dependency) Jan 9, 2025
Comment on lines 12 to 19
"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"
)

Copy link
Contributor Author

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
}

Copy link
Contributor Author

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
}

Copy link
Contributor Author

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

Copy link
Contributor Author

@denopink denopink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭

@denopink denopink changed the title feat: introducing the auth package (removing bascule and jwt dependency) feat: introducing the auth package (removing bascule, spf13 and jwt dependency) Jan 13, 2025
@denopink denopink force-pushed the denopink/feat/auth-interface branch from acc3c87 to f8c742d Compare January 13, 2025 13:20
… 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
@denopink denopink force-pushed the denopink/feat/auth-interface branch from f8c742d to cc9b408 Compare January 13, 2025 13:24
@denopink denopink requested a review from schmidtw January 13, 2025 19:36
@schmidtw schmidtw merged commit e259449 into main Jan 13, 2025
17 checks passed
@schmidtw schmidtw deleted the denopink/feat/auth-interface branch January 13, 2025 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improvement or small functionality added to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants