Skip to content
This repository has been archived by the owner on Oct 15, 2018. It is now read-only.

Commit

Permalink
Adding username and password to env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbafilho committed Apr 6, 2017
1 parent b6f7986 commit c803164
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -4,5 +4,5 @@ RUN apk add --no-cache ca-certificates

COPY ./dist/helm-chart-publisher_linux-amd64 /helm-chart-publisher

CMD ["/helm-chart-publisher", "-c", "/config.yaml"]
CMD ["/helm-chart-publisher", "-c", "/etc/helm-chart-publisher/config.yaml"]

5 changes: 5 additions & 0 deletions api/api.go
Expand Up @@ -38,6 +38,11 @@ func (api *API) Serve(address string) {
func (api *API) registerHandlers() {
api.echo.GET("/:repo/index.yaml", api.getIndexHandler)
api.echo.PUT("/charts", api.publishChartHandler)
api.echo.GET("/health", api.healthHandler)
}

func (api *API) healthHandler(c echo.Context) error {
return c.String(http.StatusOK, "WORKING")
}

func (api *API) getIndexHandler(c echo.Context) error {
Expand Down
14 changes: 14 additions & 0 deletions storage/s3/factory.go
@@ -1,6 +1,8 @@
package s3

import (
"os"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
Expand Down Expand Up @@ -42,6 +44,8 @@ func decodeAndValidateConfig(c map[string]interface{}) (*Config, error) {
return nil, err
}

mergeEnviromentVariables(&config)

if config.AccessKey == "" {
return nil, errors.New("Invalid config. Access Key is required.")
}
Expand All @@ -57,3 +61,13 @@ func decodeAndValidateConfig(c map[string]interface{}) (*Config, error) {

return &config, nil
}

func mergeEnviromentVariables(config *Config) {
if accessKey := os.Getenv("AWS_ACCESS_KEY"); accessKey != "" {
config.AccessKey = accessKey
}

if secretKey := os.Getenv("AWS_SECRET_KEY"); secretKey != "" {
config.SecretKey = secretKey
}
}
13 changes: 13 additions & 0 deletions storage/swift/factory.go
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/tls"
"errors"
"net/http"
"os"
"time"

"github.com/luizbafilho/helm-chart-publisher/storage"
Expand Down Expand Up @@ -59,6 +60,8 @@ func decodeAndValidateConfig(c map[string]interface{}) (*Config, error) {
return nil, err
}

mergeEnviromentVariables(&config)

if config.Username == "" {
return nil, errors.New("Invalid config. Username is required.")
}
Expand All @@ -77,3 +80,13 @@ func decodeAndValidateConfig(c map[string]interface{}) (*Config, error) {

return &config, nil
}

func mergeEnviromentVariables(config *Config) {
if username := os.Getenv("SWIFT_USERNAME"); username != "" {
config.Username = username
}

if password := os.Getenv("SWIFT_PASSWORD"); password != "" {
config.Password = password
}
}

0 comments on commit c803164

Please sign in to comment.