diff options
author | 2020-09-25 05:28:09 +0000 | |
---|---|---|
committer | 2020-09-29 20:14:46 +0000 | |
commit | 8a25158d77311eec27d1fb3dc41e16bfbfceebcc (patch) | |
tree | 930471e99f87b4cd20bb90ae58583ba1de92f0d3 /src/dcm/api/clusterHandler.go | |
parent | b069e7e63469a34e380e2a139aa2bfeaa9fb4c7f (diff) |
Implement Kubeconfig endpoint in DCM
The /kubeconfig API path allows a client to retrieve a kubeconfig
file for a specified cluster reference of a logical cloud.
- includes CA cert, address, user private key and signed cert.
This commit includes the "lazy-loading" implementation of certificate
retrieval per cluster from Rsync (which happens when clients call).
The certificate is read from the cluster status in appcontext.
Thus, Monitor and Rsync need to be configured and running.
Issue-ID: MULTICLOUD-1143
Change-Id: Ie94cd128e14c8a944861eced2bdc886d95fab6ed
Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
Diffstat (limited to 'src/dcm/api/clusterHandler.go')
-rw-r--r-- | src/dcm/api/clusterHandler.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/dcm/api/clusterHandler.go b/src/dcm/api/clusterHandler.go index d0c1e62c..db110399 100644 --- a/src/dcm/api/clusterHandler.go +++ b/src/dcm/api/clusterHandler.go @@ -168,3 +168,44 @@ func (h clusterHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) } + +// getConfigHandler handles GET operations on kubeconfigs +// Returns a kubeconfig file +func (h clusterHandler) getConfigHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["cluster-reference"] + var ret interface{} + var err error + + ret, err = h.client.GetCluster(project, logicalCloud, name) + if err != nil { + if err.Error() == "Cluster Reference does not exist" { + http.Error(w, err.Error(), http.StatusNotFound) + } else { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + return + } + + ret, err = h.client.GetClusterConfig(project, logicalCloud, name) + if err != nil { + if err.Error() == "The certificate for this cluster hasn't been issued yet. Please try later." { + http.Error(w, err.Error(), http.StatusAccepted) + } else if err.Error() == "Logical Cloud hasn't been applied yet" { + http.Error(w, err.Error(), http.StatusBadRequest) + } else { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + return + } + + w.Header().Set("Content-Type", "application/yaml") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} |