-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
448 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
FROM golang:1.21.1 | ||
FROM golang:1.23.4 | ||
|
||
COPY . / | ||
ENV CGO_ENABLED=0 | ||
ENV GOOS=linux | ||
ENV GOARCH=amd64 | ||
WORKDIR / | ||
RUN go mod download | ||
RUN go build -ldflags="-s -w" -o ./main.go | ||
RUN go build -ldflags="-s -w" -o ./cmd/main.go | ||
ENTRYPOINT [ "sleep","600" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
test: | ||
go test ./... -v | ||
build: | ||
CGO_ENABLED=0 go build -ldflags="-s -w -X main.version=dev-build" -o ./tfvar-cli ./cmd/main.go | ||
lint-install: | ||
@curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin | ||
lint: | ||
golangci-lint run ./... -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ezhische/tfvar-cli/internal/config" | ||
"github.com/ezhische/tfvar-cli/internal/kubeclient" | ||
"github.com/ezhische/tfvar-cli/internal/rcfile" | ||
envparse "github.com/hashicorp/go-envparse" | ||
coreV1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var ( | ||
version string | ||
mirrorList = []string{"terraform-mirror.yandexcloud.net", "registry.comcloud.xyz"} | ||
) | ||
|
||
func main() { | ||
cfg := config.NewConfig() | ||
cfg.Parse() | ||
|
||
if *cfg.ShowVersion { | ||
printVersion() | ||
os.Exit(0) | ||
} | ||
if *cfg.Terraformrc { | ||
if err := rcfile.CreateFile(mirrorList); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} | ||
client, err := kubeclient.New(cfg) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
secret, err := client.ReadSecret(*cfg.Secret) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
printSecret(cfg, secret) | ||
} | ||
|
||
func printSecret(cfg *config.Config, secret *coreV1.Secret) { | ||
for key, value := range secret.Data { | ||
if key == *cfg.Project { | ||
envs, _ := envparse.Parse(strings.NewReader(string(value))) | ||
for key, value := range envs { | ||
fmt.Printf("export %s=%s\n", key, value) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func printVersion() { | ||
fmt.Println("Version: ", version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.