MCPcopy
hub / github.com/spacecloud-io/space-cloud / login

Function login

space-cli/cmd/utils/login.go:15–40  ·  view source on GitHub ↗

Login logs the user in

(selectedAccount *model.Account)

Source from the content-addressed store, hash-verified

13
14// Login logs the user in
15func login(selectedAccount *model.Account) (*model.LoginResponse, error) {
16 requestBody, err := json.Marshal(map[string]string{
17 "user": selectedAccount.UserName,
18 "key": selectedAccount.Key,
19 })
20 if err != nil {
21 _ = LogError(fmt.Sprintf("error in login unable to marshal data - %s", err.Error()), nil)
22 return nil, err
23 }
24
25 resp, err := file.File.Post(fmt.Sprintf("%s/v1/config/login?cli=true", selectedAccount.ServerURL), "application/json", bytes.NewBuffer(requestBody))
26 if err != nil {
27 _ = LogError(fmt.Sprintf("error in login unable to send http request - %s", err.Error()), nil)
28 return nil, err
29 }
30 defer CloseTheCloser(resp.Body)
31
32 loginResp := new(model.LoginResponse)
33 _ = json.NewDecoder(resp.Body).Decode(loginResp)
34
35 if resp.StatusCode != 200 {
36 _ = LogError(fmt.Sprintf("error in login got http status code %v with error message - %v", resp.StatusCode, loginResp.Error), nil)
37 return nil, fmt.Errorf("error in login got http status code %v with error message - %v", resp.StatusCode, loginResp.Error)
38 }
39 return loginResp, err
40}
41
42// LoginStart take info of the user
43func LoginStart(userName, ID, key, url string) error {

Callers 3

Test_loginFunction · 0.70
LoginStartFunction · 0.70
LoginWithSelectedAccountFunction · 0.70

Calls 4

LogErrorFunction · 0.85
CloseTheCloserFunction · 0.70
ErrorMethod · 0.65
PostMethod · 0.65

Tested by 1

Test_loginFunction · 0.56