/
supported.go
139 lines (120 loc) · 3.63 KB
/
supported.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package api
import (
"github.com/banzaicloud/banzai-types/components"
"github.com/banzaicloud/banzai-types/constants"
"github.com/banzaicloud/pipeline/auth"
"github.com/banzaicloud/pipeline/cluster/supported"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"net/http"
)
// GetSupportedClusterList sends back the supported cluster list
func GetSupportedClusterList(c *gin.Context) {
log := logger.WithFields(logrus.Fields{"tag": "GetSupportedClusterList"})
log.Info("Start getting supported clusters")
organizationID := auth.GetCurrentOrganization(c.Request).IDString()
log.Infof("Organization id: %s", organizationID)
c.JSON(http.StatusOK, components.SupportedClustersResponse{
Items: []components.SupportedClusterItem{
{
Name: "Amazon Web Services",
Key: constants.Amazon,
Enabled: true,
Icon: "assets/images/amazon.png",
},
{
Name: "Amazon EKS",
Key: "unknown",
Enabled: false,
Icon: "assets/images/aws-eks.png",
},
{
Name: "Azure Container Service",
Key: constants.Azure,
Enabled: true,
Icon: "assets/images/azure.png",
},
{
Name: "Google Kubernetes Engine",
Key: constants.Google,
Enabled: true,
Icon: "assets/images/google.png",
},
{
Name: "Kubernetes Cluster",
Key: constants.Kubernetes,
Enabled: true,
Icon: "assets/images/kubernetes.png",
},
{
Name: "Open Shift",
Key: "unknown",
Enabled: false,
Icon: "assets/images/open_shift.png",
},
{
Name: "Oracle Cluster",
Key: "unknown",
Enabled: false,
Icon: "assets/images/oracle.png",
},
{
Name: "Alibaba Cloud",
Key: "unknown",
Enabled: false,
Icon: "assets/images/alibaba_cloud.png",
},
{
Name: "Digital Ocean",
Key: "unknown",
Enabled: false,
Icon: "assets/images/digital_ocean.png",
},
},
})
}
// GetSupportedFilters sends back the supported filter words
func GetSupportedFilters(c *gin.Context) {
log := logger.WithFields(logrus.Fields{"tag": "GetSupportedFilters"})
log.Info("Start getting filter keys")
c.JSON(http.StatusOK, components.SupportedFilters{
Keys: supported.Keywords,
})
}
// GetCloudInfo sends back the supported locations/k8sVersions/machineTypes
func GetCloudInfo(c *gin.Context) {
log := logger.WithFields(logrus.Fields{"tag": "GetCloudInfo"})
log.Info("Start getting cloud info")
organizationID := auth.GetCurrentOrganization(c.Request).ID
log.Infof("Organization id: %d", organizationID)
cloudType := c.Param("cloudtype")
log.Debugf("Cloud type: %s", cloudType)
log.Info("Binding request")
var request components.CloudInfoRequest
if err := c.ShouldBindJSON(&request); err != nil {
log.Errorf("Error during binding request: %s", err.Error())
}
log.Info("Binding request succeeded")
request.OrganizationId = organizationID
if resp, err := processCloudInfo(cloudType, &request); err != nil {
log.Errorf("Error during getting cloud info: %s", err.Error())
c.JSON(http.StatusBadRequest, components.ErrorResponse{
Code: http.StatusBadRequest,
Message: "Error during getting cloud info",
Error: err.Error(),
})
} else {
log.Debugf("Cloud info: %#v", resp)
c.JSON(http.StatusOK, resp)
}
}
// processCloudInfo returns the cloud info with the supported fields
func processCloudInfo(cloudType string, r *components.CloudInfoRequest) (*components.GetCloudInfoResponse, error) {
log.Info("Create cloud info model")
m, err := supported.GetCloudInfoModel(cloudType, r)
if err != nil {
return nil, err
}
log.Info("Process filtering")
return supported.ProcessFilter(m, r)
}