clientcache commands now can output curl strings (#4042)
This commit is contained in:
1 parent
b71d134e06
commit
9aab26e91b
8 files changed
+131
-21
No files matched your search
@@ -109,7 +109,11 @@ func (c *AddTokenCommand) Add(ctx context.Context, apiClient *api.Client, keyrin
|
||||
} else {
|
||||
return nil, nil, errors.New("The found auth token is not in the proper format.")
|
||||
}
|
||||
pa.AuthToken = token
|
||||
if c.FlagOutputCurlString {
|
||||
pa.AuthToken = "/*token*/"
|
||||
} else {
|
||||
pa.AuthToken = token
|
||||
}
|
||||
default:
|
||||
at := c.ReadTokenFromKeyring(keyringType, tokenName)
|
||||
if at == nil {
|
||||
@@ -121,15 +125,19 @@ func (c *AddTokenCommand) Add(ctx context.Context, apiClient *api.Client, keyrin
|
||||
}
|
||||
pa.AuthTokenId = at.Id
|
||||
}
|
||||
var opts []client.Option
|
||||
if c.FlagOutputCurlString {
|
||||
opts = append(opts, client.WithOutputCurlString())
|
||||
}
|
||||
|
||||
dotPath, err := DefaultDotDirectory(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return addToken(ctx, dotPath, &pa)
|
||||
return addToken(ctx, dotPath, &pa, opts...)
|
||||
}
|
||||
|
||||
func addToken(ctx context.Context, daemonPath string, p *daemon.UpsertTokenRequest) (*api.Response, *api.Error, error) {
|
||||
func addToken(ctx context.Context, daemonPath string, p *daemon.UpsertTokenRequest, opt ...client.Option) (*api.Response, *api.Error, error) {
|
||||
addr, err := daemon.SocketAddress(daemonPath)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Error when retrieving the socket address: %w", err)
|
||||
@@ -143,7 +151,7 @@ func addToken(ctx context.Context, daemonPath string, p *daemon.UpsertTokenReque
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Error when making a new client: %w.", err)
|
||||
}
|
||||
resp, err := c.Post(ctx, "/v1/tokens", p)
|
||||
resp, err := c.Post(ctx, "/v1/tokens", p, opt...)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Error when sending request to the daemon: %w.", err)
|
||||
}
|
||||
|
||||
@@ -96,11 +96,15 @@ func (c *StatusCommand) Status(ctx context.Context) (*api.Response, *daemon.Stat
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
var opts []client.Option
|
||||
if c.FlagOutputCurlString {
|
||||
opts = append(opts, client.WithOutputCurlString())
|
||||
}
|
||||
|
||||
return status(ctx, dotPath)
|
||||
return status(ctx, dotPath, opts...)
|
||||
}
|
||||
|
||||
func status(ctx context.Context, daemonPath string) (*api.Response, *daemon.StatusResult, *api.Error, error) {
|
||||
func status(ctx context.Context, daemonPath string, opt ...client.Option) (*api.Response, *daemon.StatusResult, *api.Error, error) {
|
||||
const op = "daemon.status"
|
||||
addr, err := daemon.SocketAddress(daemonPath)
|
||||
if err != nil {
|
||||
@@ -115,7 +119,7 @@ func status(ctx context.Context, daemonPath string) (*api.Response, *daemon.Stat
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
resp, err := c.Get(ctx, "/v1/status", nil)
|
||||
resp, err := c.Get(ctx, "/v1/status", nil, opt...)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("client do failed"))
|
||||
}
|
||||
|
||||
@@ -132,11 +132,11 @@ func (c *SearchCommand) Run(args []string) int {
|
||||
}
|
||||
|
||||
func (c *SearchCommand) Search(ctx context.Context) (*api.Response, *daemon.SearchResult, *api.Error, error) {
|
||||
client, err := c.Client()
|
||||
cl, err := c.Client()
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
t := client.Token()
|
||||
t := cl.Token()
|
||||
if t == "" {
|
||||
return nil, nil, nil, fmt.Errorf("Auth Token selected for searching is empty.")
|
||||
}
|
||||
@@ -150,15 +150,19 @@ func (c *SearchCommand) Search(ctx context.Context) (*api.Response, *daemon.Sear
|
||||
resource: c.flagResource,
|
||||
authTokenId: strings.Join(tSlice[:2], "_"),
|
||||
}
|
||||
var opts []client.Option
|
||||
if c.FlagOutputCurlString {
|
||||
opts = append(opts, client.WithOutputCurlString())
|
||||
}
|
||||
|
||||
dotPath, err := daemoncmd.DefaultDotDirectory(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
return search(ctx, dotPath, tf)
|
||||
return search(ctx, dotPath, tf, opts...)
|
||||
}
|
||||
|
||||
func search(ctx context.Context, daemonPath string, fb filterBy) (*api.Response, *daemon.SearchResult, *api.Error, error) {
|
||||
func search(ctx context.Context, daemonPath string, fb filterBy, opt ...client.Option) (*api.Response, *daemon.SearchResult, *api.Error, error) {
|
||||
addr, err := daemon.SocketAddress(daemonPath)
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("Error when retrieving the socket address: %w", err)
|
||||
@@ -175,7 +179,7 @@ func search(ctx context.Context, daemonPath string, fb filterBy) (*api.Response,
|
||||
q.Add("auth_token_id", fb.authTokenId)
|
||||
q.Add("resource", fb.resource)
|
||||
q.Add("query", fb.flagQuery)
|
||||
resp, err := c.Get(ctx, "/v1/search", q)
|
||||
resp, err := c.Get(ctx, "/v1/search", q, opt...)
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("Error when sending request to the daemon: %w.", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user