Files
moby/client/swarm_get_unlock_key.go
Austin Vazquez 612342198c client: refactor swarm api functions to wrap params/responses
Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-10-21 10:17:04 -05:00

27 lines
660 B
Go

package client
import (
"context"
"encoding/json"
"github.com/moby/moby/api/types/swarm"
)
// SwarmGetUnlockKeyResult contains the swarm unlock key.
type SwarmGetUnlockKeyResult struct {
Key string
}
// SwarmGetUnlockKey retrieves the swarm's unlock key.
func (cli *Client) SwarmGetUnlockKey(ctx context.Context) (SwarmGetUnlockKeyResult, error) {
resp, err := cli.get(ctx, "/swarm/unlockkey", nil, nil)
defer ensureReaderClosed(resp)
if err != nil {
return SwarmGetUnlockKeyResult{}, err
}
var response swarm.UnlockKeyResponse
err = json.NewDecoder(resp.Body).Decode(&response)
return SwarmGetUnlockKeyResult{Key: response.UnlockKey}, err
}