Skip to content

Commit

Permalink
new_pki part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ewan-carree authored and j9plante committed Aug 19, 2022
1 parent dd333d9 commit 210bc4a
Show file tree
Hide file tree
Showing 48 changed files with 2,968 additions and 2,114 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
!**/*.pem
!**/*.dot
!**/*.svg
!**/*.sh
!**/

!/.gitignore
!/go.mod
!/go.sum
!/LICENSE
!/README.md
!/Dockerfile

vendor
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:latest as setup-build-stage-git
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git
# temporary until merge to master
RUN git clone -b new_pki https://github.com/ditrit/shoset.git

FROM golang:1.18-bullseye as setup-build-stage-shoset
WORKDIR /app
COPY --from=setup-build-stage-git . /app
WORKDIR /app/shoset
RUN go get
WORKDIR /app/shoset/test
RUN go build -o shoset

FROM ubuntu:21.04 as setup-stage-production
COPY --from=setup-build-stage-shoset /app/shoset/test/shoset usr/bin/
RUN apt-get update

FROM setup-stage-production as stage-production
WORKDIR /usr/bin
CMD [ "./shoset", "4" ]
14 changes: 0 additions & 14 deletions certs/cert.pem

This file was deleted.

9 changes: 0 additions & 9 deletions certs/key.pem

This file was deleted.

62 changes: 0 additions & 62 deletions commandFuncs.go

This file was deleted.

87 changes: 87 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package shoset

import (
"os"
"sync"

"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)

// Config: collection of configuration information for a shoset.
type Config struct {
baseDir string
fileName string
viper *viper.Viper
mu sync.Mutex
}

// NewConfig returns a *Config object.
// Initialize home directory and viper.
func NewConfig() *Config {
homeDir := "."
homeDir, err := os.UserHomeDir()
if err != nil {
log.Error().Msg("couldn't home dir folder: " + err.Error())
}
cfg := &Config{
baseDir: homeDir + "/.shoset/",
viper: viper.New(),
}
if err := mkdir(cfg.baseDir); err != nil {
log.Error().Msg("couldn't create folder: " + err.Error())
}
return cfg
}

// GetBaseDir returns baseDir from config, baseDir corresponds to homeDir + shoset repertory.
func (cfg *Config) GetBaseDir() string { return cfg.baseDir }
// GetFileName returns fileName from config.
func (cfg *Config) GetFileName() string { return cfg.fileName }
// SetFileName sets fileName for a config.
func (cfg *Config) SetFileName(fileName string) { cfg.fileName = fileName }

// InitFolders creates following config folders if needed: <base>/<name>/{cert, config}.
func (cfg *Config) InitFolders(name string) (string, error) {
if err := mkdir(cfg.baseDir + name + "/"); err != nil {
return VOID, err
}
if err := mkdir(cfg.baseDir + name + PATH_CONFIG_DIR); err != nil {
return VOID, err
}
if err := mkdir(cfg.baseDir + name + PATH_CERT_DIR); err != nil {
return VOID, err
}
return cfg.baseDir, nil
}

// ReadConfig will load the configuration file from disk for a given fileName.
// Initialize viper parameters before reading.
func (cfg *Config) ReadConfig(fileName string) error {
cfg.viper.AddConfigPath(cfg.baseDir + fileName + PATH_CONFIG_DIR)
cfg.viper.SetConfigName(fileName)
cfg.viper.SetConfigType(CONFIG_TYPE)

return cfg.viper.ReadInConfig()
}

// WriteConfig writes current configuration to a given shoset.
func (cfg *Config) WriteConfig(fileName string) error {
cfg.mu.Lock()
defer cfg.mu.Unlock()

return cfg.viper.WriteConfigAs(cfg.baseDir + fileName + PATH_CONFIG_DIR + CONFIG_FILE)
}

// Set sets the value for a key for viper config.
func (cfg *Config) Set(key string, value interface{}) {
cfg.mu.Lock()
defer cfg.mu.Unlock()

cfg.viper.Set(key, value)
}

// GetSlice returns the viper config for a specific protocol.
func (cfg *Config) GetSlice(protocol string) []string {
return cfg.viper.GetStringSlice(protocol)
}
43 changes: 0 additions & 43 deletions configByeFuncs.go

This file was deleted.

63 changes: 0 additions & 63 deletions configFuncs.go

This file was deleted.

Loading

0 comments on commit 210bc4a

Please sign in to comment.