mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 06:49:40 +02:00
feat(kubernetes): fetch config file with endpoint name (#5368) [EE-1159]
This commit is contained in:
parent
0ff9d49c6f
commit
5fd92d8a3f
2 changed files with 9 additions and 3 deletions
|
@ -68,17 +68,19 @@ func (handler *Handler) getKubernetesConfig(w http.ResponseWriter, r *http.Reque
|
||||||
return &httperror.HandlerError{http.StatusNotFound, "Unable to generate Kubeconfig", err}
|
return &httperror.HandlerError{http.StatusNotFound, "Unable to generate Kubeconfig", err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filenameBase := fmt.Sprintf("%s-%s", tokenData.Username, endpoint.Name)
|
||||||
contentAcceptHeader := r.Header.Get("Accept")
|
contentAcceptHeader := r.Header.Get("Accept")
|
||||||
if contentAcceptHeader == "text/yaml" {
|
if contentAcceptHeader == "text/yaml" {
|
||||||
yaml, err := kcli.GenerateYAML(config)
|
yaml, err := kcli.GenerateYAML(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &httperror.HandlerError{http.StatusInternalServerError, "Failed to generate Kubeconfig", err}
|
return &httperror.HandlerError{http.StatusInternalServerError, "Failed to generate Kubeconfig", err}
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Disposition", `attachment; filename=config.yaml`)
|
|
||||||
|
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; %s.yaml", filenameBase))
|
||||||
return YAML(w, yaml)
|
return YAML(w, yaml)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Disposition", `attachment; filename="config.json"`)
|
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; %s.json", filenameBase))
|
||||||
return response.JSON(w, config)
|
return response.JSON(w, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,11 @@ class KubernetesConfigService {
|
||||||
|
|
||||||
async downloadConfig() {
|
async downloadConfig() {
|
||||||
const response = await this.KubernetesConfig.get();
|
const response = await this.KubernetesConfig.get();
|
||||||
return this.FileSaver.saveAs(response.data, 'config');
|
|
||||||
|
const headers = response.headers();
|
||||||
|
const contentDispositionHeader = headers['content-disposition'];
|
||||||
|
const filename = contentDispositionHeader.replace('attachment;', '').trim();
|
||||||
|
return this.FileSaver.saveAs(response.data, filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue