-
Notifications
You must be signed in to change notification settings - Fork 58
/
missioncontrolutils.go
46 lines (42 loc) · 1.11 KB
/
missioncontrolutils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package utils
import (
"encoding/json"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-client-go/utils/io/httputils"
)
func GetMissionControlHttpClientDetails(serverDetails *config.ServerDetails) httputils.HttpClientDetails {
return httputils.HttpClientDetails{
User: serverDetails.User,
Password: serverDetails.Password,
AccessToken: serverDetails.AccessToken,
Headers: map[string]string{"Content-Type": "application/json"}}
}
func ReadMissionControlHttpMessage(resp []byte) string {
var response map[string][]HttpResponse
err := json.Unmarshal(resp, &response)
if err != nil {
return string(resp)
}
responseMessage := ""
for i := range response["errors"] {
item := response["errors"][i]
if item.Message != "" {
if responseMessage != "" {
responseMessage += ", "
}
responseMessage += item.Message
for i := 0; i < len(item.Details); i++ {
responseMessage += " " + item.Details[i]
}
}
}
if responseMessage == "" {
return string(resp)
}
return responseMessage
}
type HttpResponse struct {
Message string
Type string
Details []string
}