Skip to content
Snippets Groups Projects
Commit 3da7c373 authored by Gabriel Zachmann's avatar Gabriel Zachmann
Browse files

Merge branch 'master' into dev

parents 9b274fa5 246596c5
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,7 @@
<!-- ### Dependencies -->
<!-- -->
## mytoken 0.3.1-dev
## mytoken 0.4.0
### API
......@@ -23,6 +23,10 @@
- Removed buttons from webinterface in the tokeninfo tabs. The content now loads directly when switching the tab.
## mytoken 0.3.1
- Improved helper tools
## mytoken 0.3.0
### Features
......@@ -63,4 +67,4 @@
- Add PKCE support
### Dependencies
- Bumped several dependencies
\ No newline at end of file
- Bumped several dependencies
......@@ -6,16 +6,14 @@ import (
"strings"
"time"
log "github.com/sirupsen/logrus"
"github.com/zachmann/cli/v2"
"golang.org/x/term"
"github.com/oidc-mytoken/server/internal/config"
"github.com/oidc-mytoken/server/internal/db"
"github.com/oidc-mytoken/server/shared/utils/fileutil"
log "github.com/sirupsen/logrus"
"github.com/oidc-mytoken/server/internal/model/version"
"github.com/oidc-mytoken/server/shared/utils/fileutil"
)
var configFile string
......
......@@ -4,65 +4,63 @@ import (
"fmt"
"io/ioutil"
"os"
"time"
"github.com/Songmu/prompter"
flags "github.com/jessevdk/go-flags"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/zachmann/cli/v2"
"github.com/oidc-mytoken/server/internal/config"
"github.com/oidc-mytoken/server/internal/jws"
"github.com/oidc-mytoken/server/internal/model/version"
loggerUtils "github.com/oidc-mytoken/server/internal/utils/logger"
"github.com/oidc-mytoken/server/internal/utils/zipdownload"
"github.com/oidc-mytoken/server/shared/utils/fileutil"
)
var genSigningKeyComm commandGenSigningKey
var createDBComm commandCreateDB
var installComm struct {
GeoIP commandInstallGeoIPDB `command:"geoip-db" description:"Installs the ip geolocation database."`
var app = &cli.App{
Name: "mytoken-setup",
Usage: "Command line client for easily setting up a mytoken server",
Version: version.VERSION(),
Compiled: time.Time{},
Authors: []*cli.Author{{
Name: "Gabriel Zachmann",
Email: "gabriel.zachmann@kit.edu",
}},
Copyright: "Karlsruhe Institute of Technology 2020-2021",
UseShortOptionHandling: true,
Commands: cli.Commands{
&cli.Command{
Name: "signing-key",
Aliases: []string{"key"},
Usage: "Generates a new signing key",
Description: "Generates a new signing key according to the properties specified in the config file and stores it.",
Action: createSigningKey,
},
&cli.Command{
Name: "install",
Usage: "Installs needed dependencies",
Subcommands: cli.Commands{
&cli.Command{
Name: "geoip-db",
Aliases: []string{"geo-ip-db"},
Usage: "Installs the ip geolocation database.",
Action: installGEOIPDB,
},
},
},
},
}
func main() {
config.LoadForSetup()
loggerUtils.Init()
parser := flags.NewNamedParser("mytoken", flags.HelpFlag|flags.PassDoubleDash)
if _, err := parser.AddCommand("signing-key", "Generates a new signing key", "Generates a new signing key according to the properties specified in the config file and stores it.", &genSigningKeyComm); err != nil {
log.WithError(err).Fatal()
os.Exit(1)
}
if _, err := parser.AddCommand("db", "Setups the database", "Setups the database as needed and specified in the config file.", &createDBComm); err != nil {
log.WithError(err).Fatal()
os.Exit(1)
}
if _, err := parser.AddCommand("install", "Installs needed dependencies", "", &installComm); err != nil {
log.WithError(err).Fatal()
os.Exit(1)
}
if _, err := parser.Parse(); err != nil {
var flagError *flags.Error
if errors.As(err, &flagError) {
if flagError.Type == flags.ErrHelp {
fmt.Println(err)
os.Exit(0)
}
}
log.WithError(err).Fatal()
os.Exit(1)
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
type commandGenSigningKey struct{}
type commandCreateDB struct {
Username string `short:"u" long:"user" default:"root" description:"This username is used to connect to the database to create a new database, database user, and tables."`
Password *string `short:"p" optional:"true" optional-value:"" long:"password" description:"The password for the database user"`
}
type commandInstallGeoIPDB struct{}
// Execute implements the flags.Commander interface
func (c *commandInstallGeoIPDB) Execute(args []string) error {
func installGEOIPDB(context *cli.Context) error {
archive, err := zipdownload.DownloadZipped("https://download.ip2location.com/lite/IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP")
if err != nil {
return err
......@@ -76,8 +74,7 @@ func (c *commandInstallGeoIPDB) Execute(args []string) error {
return err
}
// Execute implements the flags.Commander interface
func (c *commandGenSigningKey) Execute(args []string) error {
func createSigningKey(context *cli.Context) error {
sk, _, err := jws.GenerateKeyPair()
if err != nil {
return err
......
......@@ -364,4 +364,5 @@ func load() {
// not required for setup
func LoadForSetup() {
load()
conf.Logging.Internal.StdErr = true
}
......@@ -7,8 +7,8 @@ import (
// Version segments
const (
MAJOR = 0
MINOR = 3
FIX = 1
MINOR = 4
FIX = 0
DEV = true
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment