Add skip daemon flag and send recently authed tokens to daemon (#3883)
* Add skip daemon flag and send recently authed tokens to daemon * Rename flag skip-daemon to skip-cache-daemon * adding option test * move common.Options to base.Option * SocketAddress returns *url.URL, fix search test
This commit is contained in:
1 parent
2f7459fa40
commit
3a7ea64a31
27 files changed
+429
-419
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -52,8 +53,7 @@ func listener(ctx context.Context, path string) (net.Listener, error) {
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// SocketAddress returns the unix socket filename with a 'unix://' prefix.
|
||||
// The returned value can be passed directly into the api.Client
|
||||
func SocketAddress(path string) string {
|
||||
return fmt.Sprintf("unix://%s", filepath.Join(path, sockAddr))
|
||||
// SocketAddress returns the unix socket *url.URL with the scheme set to 'unix'.
|
||||
func SocketAddress(path string) (*url.URL, error) {
|
||||
return url.Parse(fmt.Sprintf("unix://%s", filepath.Join(path, sockAddr)))
|
||||
}
|
||||
@@ -45,7 +45,9 @@ func TestListenComms(t *testing.T) {
|
||||
|
||||
client, err := api.NewClient(nil)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, client.SetAddr(SocketAddress(path)))
|
||||
u, err := SocketAddress(path)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, client.SetAddr(u.String()))
|
||||
client.SetToken("")
|
||||
req, err := client.NewRequest(ctx, "GET", "/test", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -35,7 +35,6 @@ import (
|
||||
// and retrieve the keyring and token information used by a command.
|
||||
type Commander interface {
|
||||
ClientProvider
|
||||
DiscoverKeyringTokenInfo() (string, string, error)
|
||||
ReadTokenFromKeyring(keyringType, tokenName string) *authtokens.AuthToken
|
||||
}
|
||||
|
||||
@@ -207,27 +206,6 @@ func (s *CacheServer) Serve(ctx context.Context, cmd Commander, opt ...Option) e
|
||||
return errors.Wrap(ctx, err, op)
|
||||
}
|
||||
|
||||
// If we have a token info already, add it to the repository immediately so
|
||||
// it can start to get updated.
|
||||
func() {
|
||||
client, err := cmd.Client()
|
||||
if err != nil {
|
||||
event.WriteError(ctx, op, err)
|
||||
return
|
||||
}
|
||||
krType, tokName, err := cmd.DiscoverKeyringTokenInfo()
|
||||
if err != nil {
|
||||
event.WriteError(ctx, op, err)
|
||||
return
|
||||
}
|
||||
if at := cmd.ReadTokenFromKeyring(krType, tokName); at != nil {
|
||||
if err := repo.AddKeyringToken(ctx, client.Addr(), cache.KeyringToken{KeyringType: krType, TokenName: tokName, AuthTokenId: at.Id}); err != nil {
|
||||
event.WriteError(ctx, op, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
refreshService, err := cache.NewRefreshService(ctx, repo)
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op)
|
||||
|
||||
@@ -68,6 +68,19 @@ func (s *TestServer) Serve(t *testing.T, opt ...Option) error {
|
||||
return s.CacheServer.Serve(ctx, s.cmd, opt...)
|
||||
}
|
||||
|
||||
func (s *TestServer) AddKeyringToken(t *testing.T, address, keyring, tokenName, tokenId string, atReadFn cache.BoundaryTokenReaderFn) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
r, err := cache.NewRepository(ctx, s.CacheServer.store, &sync.Map{}, s.cmd.ReadTokenFromKeyring, atReadFn)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, r.AddKeyringToken(ctx, address, cache.KeyringToken{
|
||||
KeyringType: keyring,
|
||||
TokenName: tokenName,
|
||||
AuthTokenId: tokenId,
|
||||
}))
|
||||
}
|
||||
|
||||
// AddResources adds targets to the cache for the provided address, token name,
|
||||
// and keyring type. They token info must already be known to the server.
|
||||
func (s *TestServer) AddResources(t *testing.T, p *authtokens.AuthToken, tars []*targets.Target, sess []*sessions.Session, atReadFn cache.BoundaryTokenReaderFn) {
|
||||
|
||||
Reference in new issue
Block a user