github.com/hms58/moby@v1.13.1/client/secret_list.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/url"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/api/types/filters"
     9  	"github.com/docker/docker/api/types/swarm"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  // SecretList returns the list of secrets.
    14  func (cli *Client) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
    15  	query := url.Values{}
    16  
    17  	if options.Filters.Len() > 0 {
    18  		filterJSON, err := filters.ToParam(options.Filters)
    19  		if err != nil {
    20  			return nil, err
    21  		}
    22  
    23  		query.Set("filters", filterJSON)
    24  	}
    25  
    26  	resp, err := cli.get(ctx, "/secrets", query, nil)
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  
    31  	var secrets []swarm.Secret
    32  	err = json.NewDecoder(resp.body).Decode(&secrets)
    33  	ensureReaderClosed(resp)
    34  	return secrets, err
    35  }