initial commit

This commit is contained in:
Adora Laura Kalb 2024-06-28 15:28:54 +02:00
commit a08df81967
Signed by: adoralaura
SSH key fingerprint: SHA256:3XrkbR8ikAZJVtYfaUliX1MhmJYVAe/ocIb/MiDHBJ8
13 changed files with 213 additions and 0 deletions

29
.gitignore vendored Normal file
View file

@ -0,0 +1,29 @@
# ---> Go
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
bin/
examples/testing/
*.toml
!examples/*.toml

1
LICENSE Normal file
View file

@ -0,0 +1 @@
Copyright © 2024 Laura Kalb <dev@lauka.net>

View file

@ -0,0 +1,22 @@
/*
Copyright © 2024 Laura Kalb <dev@lauka.net>
The code of this project is available under the MIT license. See the LICENSE file for more info.
*/
package cmd
import (
"os"
"code.lila.network/adoralaura/certwarden-deploy/internal/cli"
)
var cfgFile string
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := cli.RootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

8
config.yaml Normal file
View file

@ -0,0 +1,8 @@
base_path: "https://certs.lauka-home.net"
disable_certificate_validation: true
certificates:
- name: test.laura.ovh
api_key: CiwnqR3rF1KZhGCRMsydSHkKksdeeFPA
action: ""

15
go.mod Normal file
View file

@ -0,0 +1,15 @@
module code.lila.network/adoralaura/certwarden-deploy
go 1.22.2
require (
github.com/spf13/cobra v1.8.1
gopkg.in/yaml.v3 v3.0.1
)
require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)

21
go.sum Normal file
View file

@ -0,0 +1,21 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

17
internal/cli/root.go Normal file
View file

@ -0,0 +1,17 @@
package cli
import "github.com/spf13/cobra"
var RootCmd = &cobra.Command{
Use: "certwarden-deploy",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}

26
internal/config/config.go Normal file
View file

@ -0,0 +1,26 @@
package config
import (
"log/slog"
"os"
"gopkg.in/yaml.v3"
)
func InitializeConfig() {
if *ConfigFile != "" {
*ConfigFile = "/etc/certwarden-deploy/config.yaml"
}
data, err := os.ReadFile(*ConfigFile)
if err != nil {
slog.Error("failed to read config file", "file", *ConfigFile, "error", err)
os.Exit(1)
}
err = yaml.Unmarshal([]byte(data), &Config)
if err != nil {
slog.Error("failed to unmarshal config file", "file", *ConfigFile, "error", err)
os.Exit(1)
}
}

20
internal/config/models.go Normal file
View file

@ -0,0 +1,20 @@
package config
import "log/slog"
var Config *ConfigFileData
var ConfigFile *string
var Logger *slog.Logger
type ConfigFileData struct {
BaseURL string `yaml:"base_url"`
DisableCertificateValidation bool `yaml:"disable_certificate_validation"`
Certificates []CertificateData `yaml:"certificates"`
}
type CertificateData struct {
Name string `yaml:"name"`
ApiKey string `yaml:"api_key"`
Action string `yaml:"action"`
FilePath string `yaml:"file_path"`
}

View file

@ -0,0 +1,7 @@
package constants
const Version = "0.0.1"
const ChainApiPath = "/certwarden/api/v1/download/certrootchains/"
const CertificateApiPath = "/certwarden/api/v1/download/certificates/"
const ApiKeyHeaderName = "X-API-Key"
const UserAgent = "certwarden-deploy/" + Version + " +code.lila.network/adoralaura/certwarden-deploy"

18
internal/init/init.go Normal file
View file

@ -0,0 +1,18 @@
package init
import (
"code.lila.network/adoralaura/certwarden-deploy/internal/cli"
"code.lila.network/adoralaura/certwarden-deploy/internal/config"
"code.lila.network/adoralaura/certwarden-deploy/internal/logger"
"github.com/spf13/cobra"
)
func InitializeApp() {
cobra.OnInitialize(config.InitializeConfig, logger.InitializeLogger)
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
cli.RootCmd.PersistentFlags().StringVar(config.ConfigFile, "config", "", "config file (default is /etc/certwarden-deploy/config.yaml)")
}

18
internal/logger/logger.go Normal file
View file

@ -0,0 +1,18 @@
package logger
import (
"log/slog"
"os"
)
func InitializeLogger() {
// TODO: Different Log levels
opts := &slog.HandlerOptions{
Level: slog.LevelInfo,
}
handler := slog.NewTextHandler(os.Stdout, opts)
slog.SetDefault(slog.New(handler))
}

11
main.go Normal file
View file

@ -0,0 +1,11 @@
/*
Copyright © 2024 Laura Kalb <dev@lauka.net>
The code of this project is available under the MIT license. See the LICENSE file for more info.
*/
package main
import cmd "code.lila.network/adoralaura/certwarden-deploy/cmd/certwarden-deploy"
func main() {
cmd.Execute()
}