Skip to content

Commit

Permalink
Merge pull request chartmuseum#21 from fmotrifork/errorHandlingFromCM
Browse files Browse the repository at this point in the history
Logging errors from ChartMuseum, added support for organizations in CM
  • Loading branch information
idobry authored Feb 20, 2019
2 parents f45c32a + 2b92700 commit 818227e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ $ curl -L --data-binary "@<packge-name>" <chartmuseum-url>/api/charts

In the browser, navigate to localhost and view your charts

### Using with ChartMuseum with Multitenancy enabled

To use ChartMuseumUI on a ChartMuseum with Multitenancy support enabled, add the following environment variable to ChartMuseumUI

```
CHART_MUSESUM_API_GET_CHARTS: "/api/org1/charts"
```

Currently only one organization is allowed per ChartMuseumUI.

## Built With

Expand Down
22 changes: 18 additions & 4 deletions controllers/chartmuseum.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ import (
func getCharts() map[string][]models.Chart {

l := logs.GetLogger()
res, err := httplib.Get(os.Getenv("CHART_MUSESUM_URL") + api_get_charts).Debug(true).Bytes()
l.Printf("Getting charts on url: %s\n", getBaseUrl())
res, err := httplib.Get(getBaseUrl()).Debug(true).Bytes()
if err != nil {
l.Panic(err.Error)
}

charts, err := models.NewCharts(res)
if err != nil {
l.Panic(err)
errorRes, innerErr := models.NewError(res)
if innerErr != nil {
l.Panic(innerErr)
}
l.Panicf("Error received from ChartMuseum application: %s\n", errorRes.Message, err)
}
return charts
}
Expand All @@ -29,7 +34,7 @@ func uploadChart(filePath string) {

l := logs.GetLogger()

cmd := exec.Command("curl", "-L", "--data-binary", "@"+filePath, os.Getenv("CHART_MUSESUM_URL")+api_get_charts)
cmd := exec.Command("curl", "-L", "--data-binary", "@"+filePath, getBaseUrl())
out, err := cmd.CombinedOutput()
if err != nil {
l.Fatalf("cmd.Run() failed with %s\n", err)
Expand All @@ -41,10 +46,19 @@ func deleteChart(name string, version string) {

l := logs.GetLogger()
l.Println("in deleteChart()")
cmd := exec.Command("curl", "-X", "DELETE", os.Getenv("CHART_MUSESUM_URL")+api_get_charts+"/"+name+"/"+version)
cmd := exec.Command("curl", "-X", "DELETE", getBaseUrl() + "/"+name+"/" + version)
out, err := cmd.CombinedOutput()
if err != nil {
l.Fatalf("cmd.Run() failed with %s\n", err)
}
l.Printf("combined out:\n%s\n", string(out))
}

func getBaseUrl() string {
api := os.Getenv("CHART_MUSESUM_API_GET_CHARTS")
if len(api) == 0 {
api = api_get_charts
}
url := os.Getenv("CHART_MUSESUM_URL") + api
return url
}
15 changes: 15 additions & 0 deletions models/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package models

import (
"encoding/json"
)

type Error struct {
Message string `json:"error"`
}

func NewError(data []byte) (Error, error) {
var e Error
err := json.Unmarshal(data, &e)
return e, err
}

0 comments on commit 818227e

Please sign in to comment.