Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for basic authentication into ChartMuseum #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ To add a simple basic auth to ChartMuseumUI, you can add the following configura
BASIC_AUTH_USERS: '[{"username":"admin", "password":"password"}, {"username":"user", "password":"s3cr3t"}]'
```

### Adding back end authentication to ChartMuseumUI

To add a back end credentials to be used by ChartMuseumUI, you can add the following configuration

```
BACKEND_BASIC_AUTH_USER: username
BACKEND_BASIC_AUTH_PASS: password
```

## Built With

* [beego](https://beego.me/) - The web framework used
Expand Down
45 changes: 42 additions & 3 deletions controllers/chartmuseum.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,22 @@ func getCharts() map[string][]models.Chart {

l := logs.GetLogger()
l.Printf("Getting charts on url: %s\n", getBaseURL())
res, err := httplib.Get(getBaseURL()).Debug(true).Bytes()

backendUser := os.Getenv("BACKEND_BASIC_AUTH_USER")
backendPass := os.Getenv("BACKEND_BASIC_AUTH_PASS")

var err error
var res []byte
if len(backendUser) == 0 {
res, err = httplib.Get(getBaseURL()).Debug(true).Bytes()
} else if len(backendPass) == 0 {
l.Println("BACKEND_BASIC_AUTH_USER supplied without BACKEND_BASIC_AUTH_PASS, trying anyway")
res, err = httplib.Get(getBaseURL()).SetBasicAuth(backendUser, "").Debug(true).Bytes()
} else {
res, err = httplib.Get(getBaseURL()).SetBasicAuth(backendUser, backendPass).Debug(true).Bytes()
}


if err != nil {
l.Panic(err.Error)
}
Expand All @@ -36,7 +51,19 @@ func uploadChart(filePath string) {

l := logs.GetLogger()

cmd := exec.Command("curl", "-L", "--data-binary", "@"+filePath, getBaseURL())
backendUser := os.Getenv("BACKEND_BASIC_AUTH_USER")
backendPass := os.Getenv("BACKEND_BASIC_AUTH_PASS")

cmd := exec.Command("echo")
if len(backendUser) == 0 {
cmd = exec.Command("curl", "-L", "--data-binary", "@"+filePath, getBaseURL())
} else if len(backendPass) == 0 {
l.Println("BACKEND_BASIC_AUTH_USER supplied without BACKEND_BASIC_AUTH_PASS, trying anyway")
cmd = exec.Command("curl", "-L", "--user", backendUser+":", "--data-binary", "@"+filePath, getBaseURL())
} else {
cmd = exec.Command("curl", "-L", "--user", backendUser+":"+backendPass,"--data-binary", "@"+filePath, getBaseURL())
}

out, err := cmd.CombinedOutput()
if err != nil {
l.Fatalf("cmd.Run() failed with %s\n", err)
Expand All @@ -48,7 +75,19 @@ func deleteChart(name string, version string) {

l := logs.GetLogger()
l.Println("in deleteChart()")
cmd := exec.Command("curl", "-X", "DELETE", getBaseURL()+"/"+name+"/"+version)

backendUser := os.Getenv("BACKEND_BASIC_AUTH_USER")
backendPass := os.Getenv("BACKEND_BASIC_AUTH_PASS")

cmd := exec.Command("echo")
if len(backendUser) == 0 {
cmd = exec.Command("curl", "-X", "DELETE", getBaseURL()+"/"+name+"/"+version)
} else if len(backendPass) == 0 {
cmd = exec.Command("curl", "--user", backendUser+":", "-X", "DELETE", getBaseURL()+"/"+name+"/"+version)
} else {
cmd = exec.Command("curl", "--user", backendUser+":"+backendPass, "-X", "DELETE", getBaseURL()+"/"+name+"/"+version)
}

out, err := cmd.CombinedOutput()
if err != nil {
l.Fatalf("cmd.Run() failed with %s\n", err)
Expand Down