github.com/olljanat/moby@v1.13.1/client/secret_inspect.go (about)

     1  package client
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/json"
     6  	"io/ioutil"
     7  	"net/http"
     8  
     9  	"github.com/docker/docker/api/types/swarm"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  // SecretInspectWithRaw returns the secret information with raw data
    14  func (cli *Client) SecretInspectWithRaw(ctx context.Context, id string) (swarm.Secret, []byte, error) {
    15  	resp, err := cli.get(ctx, "/secrets/"+id, nil, nil)
    16  	if err != nil {
    17  		if resp.statusCode == http.StatusNotFound {
    18  			return swarm.Secret{}, nil, secretNotFoundError{id}
    19  		}
    20  		return swarm.Secret{}, nil, err
    21  	}
    22  	defer ensureReaderClosed(resp)
    23  
    24  	body, err := ioutil.ReadAll(resp.body)
    25  	if err != nil {
    26  		return swarm.Secret{}, nil, err
    27  	}
    28  
    29  	var secret swarm.Secret
    30  	rdr := bytes.NewReader(body)
    31  	err = json.NewDecoder(rdr).Decode(&secret)
    32  
    33  	return secret, body, err
    34  }