mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 04:40:05 +01:00
feat: add kubeconfig to payload if available
Signed-off-by: allanice001 <allanice001@gmail.com>
This commit is contained in:
@@ -69,7 +69,17 @@ func ListClusters(db *gorm.DB) http.HandlerFunc {
|
||||
|
||||
out := make([]dto.ClusterResponse, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
out = append(out, clusterToDTO(row))
|
||||
cr := clusterToDTO(row)
|
||||
|
||||
if row.EncryptedKubeconfig != "" && row.KubeIV != "" && row.KubeTag != "" {
|
||||
kubeconfig, err := utils.DecryptForOrg(orgID, row.EncryptedKubeconfig, row.KubeIV, row.KubeTag, db)
|
||||
if err != nil {
|
||||
utils.WriteError(w, http.StatusInternalServerError, "kubeconfig_decrypt_failed", "failed to decrypt kubeconfig")
|
||||
return
|
||||
}
|
||||
cr.Kubeconfig = &kubeconfig
|
||||
}
|
||||
out = append(out, cr)
|
||||
}
|
||||
utils.WriteJSON(w, http.StatusOK, out)
|
||||
}
|
||||
@@ -131,7 +141,18 @@ func GetCluster(db *gorm.DB) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
utils.WriteJSON(w, http.StatusOK, clusterToDTO(cluster))
|
||||
resp := clusterToDTO(cluster)
|
||||
|
||||
if cluster.EncryptedKubeconfig != "" && cluster.KubeIV != "" && cluster.KubeTag != "" {
|
||||
kubeconfig, err := utils.DecryptForOrg(orgID, cluster.EncryptedKubeconfig, cluster.KubeIV, cluster.KubeTag, db)
|
||||
if err != nil {
|
||||
utils.WriteError(w, http.StatusInternalServerError, "kubeconfig_decrypt_failed", "failed to decrypt kubeconfig")
|
||||
return
|
||||
}
|
||||
resp.Kubeconfig = &kubeconfig
|
||||
}
|
||||
|
||||
utils.WriteJSON(w, http.StatusOK, resp)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ type ClusterResponse struct {
|
||||
NodePools []NodePoolResponse `json:"node_pools,omitempty"`
|
||||
DockerImage string `json:"docker_image"`
|
||||
DockerTag string `json:"docker_tag"`
|
||||
Kubeconfig *string `json:"kubeconfig,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user