MCPcopy Index your code
hub / github.com/anchordotdev/cli / NewClient

Function NewClient

api/api.go:54–106  ·  view source on GitHub ↗

TODO: rename to NewSession

(ctx context.Context, cfg *cli.Config)

Source from the content-addressed store, hash-verified

52
53// TODO: rename to NewSession
54func NewClient(ctx context.Context, cfg *cli.Config) (*Session, error) {
55 anc := &Session{
56 Client: &http.Client{
57 Transport: Middlewares{
58 urlRewriter{
59 url: cfg.API.URL,
60 },
61 responseChecker,
62 userAgentSetter,
63 preferSetter{
64 cfg: cfg,
65 },
66 autoRetrier,
67 }.RoundTripper(new(http.Transport)),
68 },
69 cfg: cfg,
70 }
71
72 apiToken := cfg.API.Token
73 if apiToken == "" {
74 var (
75 kr = keyring.Keyring{Config: cfg}
76
77 err error
78 )
79
80 if apiToken, err = kr.Get(keyring.APIToken); err == keyring.ErrNotFound {
81 return anc, ErrSignedOut
82 }
83 if err != nil && gnomeKeyringMissing(cfg) {
84 return anc, ErrGnomeKeyringRequired
85 }
86
87 if apiToken != "" {
88 if !strings.HasPrefix(apiToken, "ap0_") || len(apiToken) != 64 {
89 return nil, fmt.Errorf("read invalid PAT token from keyring")
90 }
91 }
92 }
93
94 anc.Client.Transport = basicAuther{
95 RoundTripper: anc.Client.Transport,
96 PAT: apiToken,
97 }
98
99 if info, err := anc.UserInfo(ctx); err == nil {
100 if err := version.MinimumVersionCheck(info.MinimumCliVersion); err != nil {
101 return nil, err
102 }
103 }
104
105 return anc, nil
106}
107
108func attachServicePath(orgSlug, serviceSlug string) string {
109 return "/orgs/" + url.QueryEscape(orgSlug) + "/services/" + url.QueryEscape(serviceSlug) + "/actions/attach"

Callers 9

TestAuditFunction · 0.92
RunTUIMethod · 0.92
runTUIMethod · 0.92
PerformMethod · 0.92
TestSelectorFunction · 0.92
TestSetupFunction · 0.92
TestLclFunction · 0.92
TestVerifyFunction · 0.92
TestVerifyErrorsFunction · 0.92

Calls 5

UserInfoMethod · 0.95
MinimumVersionCheckFunction · 0.92
gnomeKeyringMissingFunction · 0.85
GetMethod · 0.80
RoundTripperMethod · 0.65

Tested by 6

TestAuditFunction · 0.74
TestSelectorFunction · 0.74
TestSetupFunction · 0.74
TestLclFunction · 0.74
TestVerifyFunction · 0.74
TestVerifyErrorsFunction · 0.74