various: change OAuth and WIF auth key resolvers to take struct args
Change signature of OAuth and identityfederation auth key resolution hooks to take in structs instead of lists of args as they were getting unwieldily. Updates https://github.com/tailscale/tailscale/issues/20339 Signed-off-by: Mario Minardi <mario@tailscale.com>
This commit is contained in:
committed by
Mario Minardi
parent
3ccc7725a3
commit
c8ae72b537
@@ -33,15 +33,15 @@ func init() {
|
||||
// false. The "baseURL" defaults to https://api.tailscale.com.
|
||||
// The passed in tags are required, and must be non-empty. These will be
|
||||
// set on the authkey generated by the OAuth2 dance.
|
||||
func resolveAuthKey(ctx context.Context, clientSecret string, tags []string) (string, error) {
|
||||
if !strings.HasPrefix(clientSecret, "tskey-client-") {
|
||||
return clientSecret, nil
|
||||
func resolveAuthKey(ctx context.Context, args tailscale.ResolveAuthKeyArgs) (string, error) {
|
||||
if !strings.HasPrefix(args.AuthKey, "tskey-client-") {
|
||||
return args.AuthKey, nil
|
||||
}
|
||||
if len(tags) == 0 {
|
||||
if len(args.Tags) == 0 {
|
||||
return "", errors.New("oauth authkeys require --advertise-tags")
|
||||
}
|
||||
|
||||
strippedSecret, ephemeral, preauth, baseURL, err := parseOptionalAttributes(clientSecret)
|
||||
strippedSecret, ephemeral, preauth, baseURL, err := parseOptionalAttributes(args.AuthKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func resolveAuthKey(ctx context.Context, clientSecret string, tags []string) (st
|
||||
Reusable: false,
|
||||
Ephemeral: ephemeral,
|
||||
Preauthorized: preauth,
|
||||
Tags: tags,
|
||||
Tags: args.Tags,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/internal/client/tailscale"
|
||||
)
|
||||
|
||||
func TestResolveAuthKey(t *testing.T) {
|
||||
@@ -80,7 +82,10 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
got, err := resolveAuthKey(context.Background(), tt.clientID, tt.tags)
|
||||
got, err := resolveAuthKey(context.Background(), tailscale.ResolveAuthKeyArgs{
|
||||
AuthKey: tt.clientID,
|
||||
Tags: tt.tags,
|
||||
})
|
||||
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user