Reference returns the reference of a node. The special value "self" for a node reference is mapped to the current node, hence the node ID is retrieved using the `/info` endpoint.
(ctx context.Context, apiClient client.APIClient, ref string)
| 44 | // reference is mapped to the current node, hence the node ID is retrieved using |
| 45 | // the `/info` endpoint. |
| 46 | func Reference(ctx context.Context, apiClient client.APIClient, ref string) (string, error) { |
| 47 | if ref == "self" { |
| 48 | res, err := apiClient.Info(ctx, client.InfoOptions{}) |
| 49 | if err != nil { |
| 50 | return "", err |
| 51 | } |
| 52 | if res.Info.Swarm.NodeID == "" { |
| 53 | // If there's no node ID in /info, the node probably |
| 54 | // isn't a manager. Call a swarm-specific endpoint to |
| 55 | // get a more specific error message. |
| 56 | // |
| 57 | // FIXME(thaJeztah): this should not require calling a Swarm endpoint, and we could just suffice with info / ping (which has swarm status). |
| 58 | _, err = apiClient.NodeList(ctx, client.NodeListOptions{}) |
| 59 | if err != nil { |
| 60 | return "", err |
| 61 | } |
| 62 | return "", errors.New("node ID not found in /info") |
| 63 | } |
| 64 | return res.Info.Swarm.NodeID, nil |
| 65 | } |
| 66 | return ref, nil |
| 67 | } |
no test coverage detected
searching dependent graphs…