Skip to content
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a7e2329
[#1587] Exclude a common part of CLI parser
fivitti Jan 2, 2025
ac04f65
[#1587] Working general CLI parser
fivitti Jan 3, 2025
ffd2cf4
[#1587] Fix the wrong argument
fivitti Jan 7, 2025
8808118
[#1587] Unify agent and server parsers
fivitti Jan 7, 2025
e301a43
[#1587] Verify the envvars
fivitti Jan 7, 2025
30c4d21
[#1587] Fix linter issues
fivitti Jan 7, 2025
c8ca1c5
[#1587] Verify system environment variables
fivitti Jan 7, 2025
81b857a
[#1587] Add unit tests
fivitti Jan 7, 2025
48add73
[#1587] Extend unit test
fivitti Jan 7, 2025
06ba0b6
[#1587] Fix unit tests
fivitti Jan 7, 2025
cfb6ec4
[#1587] Simplify utility
fivitti Jan 7, 2025
7a29eb8
[#1587] Fix linter issue
fivitti Jan 8, 2025
522be1b
[#1587] Remove redundant flags
fivitti Jan 8, 2025
c6657d4
[#1587] Add unit tests
fivitti Jan 8, 2025
bf98f00
[#1587] Add a Changelog entry
fivitti Jan 8, 2025
19b7c94
[#1587] Unify the CLI handling in the Stork tool
fivitti Jan 8, 2025
66db02f
[#1587] Move package
fivitti Jan 8, 2025
425910d
[#1587] Exclude app to a separate file
fivitti Jan 8, 2025
7b201bd
[#1587] Unexport structs
fivitti Jan 8, 2025
6569020
[#1587] Unify code-gen CLI
fivitti Jan 8, 2025
27c6b7c
[#1587] Remove unnecessary dependencies
fivitti Jan 8, 2025
185123d
[#1587] Rename structs
fivitti Jan 9, 2025
f1d16f2
[#1587] Add unit tests
fivitti Jan 9, 2025
60f2fe4
[#1587] Rephrase a sentence
fivitti Jan 9, 2025
1acfd8d
[#1587] Support hooks only for agent and server
fivitti Jan 9, 2025
9285a3c
[#1587] Add unit test
fivitti Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[#1587] Unexport structs
  • Loading branch information
fivitti authored and tomaszmrugalski committed Jun 2, 2025
commit 7b201bd65949339d136105150aacc3dd1e7bfe56
56 changes: 28 additions & 28 deletions backend/cmd/stork-tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,56 @@ import (
const passwordGenRandomLength = 24

// The CLI flags for the db-create command.
type DatabaseCreateCommand struct {
type databaseCreateCommand struct {
cli.CLICommand
DatabaseSettings dbops.DatabaseCLIFlagsWithMaintenance
Force bool `long:"force" short:"f" description:"Recreate the database and the user if they exist" env:"STORK_TOOL_DB_FORCE"`
}

// The CLI flags for the db-init, db-up, db-down, db-reset, db-version commands.
type DatabaseCommand struct {
type databaseCommand struct {
cli.CLICommand
DatabaseSettings dbops.DatabaseCLIFlags
}

// The CLI flags for the db-up, db-down, and db-set-version commands.
type DatabaseVersionCommand struct {
type databaseVersionCommand struct {
cli.CLICommand
DatabaseSettings dbops.DatabaseCLIFlags
Version string `long:"version" short:"t" description:"Target database schema version (optional)" env:"STORK_TOOL_DB_VERSION"`
}

// The CLI flags for the cert-import command.
type CertificateImportCommand struct {
type certificateImportCommand struct {
cli.CLICommand
DatabaseSettings dbops.DatabaseCLIFlags
Object string `long:"object" short:"f" description:"The object to import; it can be one of 'cakey', 'cacert', 'srvkey', 'srvcert', 'srvtkn'" env:"STORK_TOOL_CERT_OBJECT" choice:"cakey" choice:"cacert" choice:"srvkey" choice:"srvcert" choice:"srvtkn"`
File string `long:"file" short:"i" description:"The file location from which the object should be imported" env:"STORK_TOOL_CERT_FILE"`
}

// The CLI flags for the cert-export command.
type CertificateExportCommand struct {
type certificateExportCommand struct {
cli.CLICommand
DatabaseSettings dbops.DatabaseCLIFlags
Object string `long:"object" short:"f" description:"The object to dump; it can be one of 'cakey', 'cacert', 'srvkey', 'srvcert', 'srvtkn'" env:"STORK_TOOL_CERT_OBJECT" choice:"cakey" choice:"cacert" choice:"srvkey" choice:"srvcert" choice:"srvtkn"`
File string `long:"file" short:"o" description:"The file location where the object should be saved; if not provided, then object is printed to stdout" env:"STORK_TOOL_CERT_FILE"`
}

// The CLI flags for the hook-inspect command.
type HookInspectCommand struct {
type hookInspectCommand struct {
cli.CLICommand
HookPath string `long:"hook-path" short:"p" description:"The path to the hook file or directory" env:"STORK_TOOL_HOOK_PATH"`
}

// The CLI flags for the deploy-login-page-welcome command.
type LoginScreenWelcomeDeployCommand struct {
type loginScreenWelcomeDeployCommand struct {
cli.CLICommand
File string `long:"file" short:"i" description:"HTML source file with a custom welcome message" env:"STORK_TOOL_LOGIN_SCREEN_WELCOME_FILE"`
RestStaticFilesDir string `long:"rest-static-files-dir" short:"d" description:"The directory with static files for the UI; if not provided the tool will try to use default locations" env:"STORK_TOOL_REST_STATIC_FILES_DIR"`
}

// The CLI flags for the undeploy-login-page-welcome command.
type LoginScreenWelcomeUndeployCommand struct {
type loginScreenWelcomeUndeployCommand struct {
cli.CLICommand
RestStaticFilesDir string `long:"rest-static-files-dir" short:"d" description:"The directory with static files for the UI; if not provided the tool will try to use default locations" env:"STORK_TOOL_REST_STATIC_FILES_DIR"`
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func getDBConn(flags dbops.DatabaseCLIFlags) *dbops.PgDB {
// Execute db-create command. It prepares new database for the Stork
// server. It also creates a user that can access this database using
// a generated or user-specified password and the pgcrypto extension.
func runDBCreate(command *DatabaseCreateCommand) {
func runDBCreate(command *databaseCreateCommand) {
var err error

// Prepare logging fields.
Expand Down Expand Up @@ -214,15 +214,15 @@ func runDBMigrate(databaseSettings dbops.DatabaseCLIFlags, command, version stri
}

// Execute cert export command.
func runCertExport(certificateCommand *CertificateExportCommand) error {
func runCertExport(certificateCommand *certificateExportCommand) error {
db := getDBConn(certificateCommand.DatabaseSettings)
defer db.Close()

return certs.ExportSecret(db, certificateCommand.Object, certificateCommand.File)
}

// Execute cert import command.
func runCertImport(certificateCommand *CertificateImportCommand) error {
func runCertImport(certificateCommand *certificateImportCommand) error {
db := getDBConn(certificateCommand.DatabaseSettings)
defer db.Close()

Expand Down Expand Up @@ -252,7 +252,7 @@ func inspectHookFile(path string, library *hooksutil.LibraryManager, err error)
}

// Execute inspect hook command.
func runHookInspect(hookInspectCommand *HookInspectCommand) error {
func runHookInspect(hookInspectCommand *hookInspectCommand) error {
hookPath := hookInspectCommand.HookPath
fileInfo, err := os.Stat(hookPath)
if err != nil {
Expand All @@ -278,7 +278,7 @@ func runHookInspect(hookInspectCommand *HookInspectCommand) error {
}

// Deploy specified static file view into assets/static-page-content.
func runStaticViewDeploy(settings *LoginScreenWelcomeDeployCommand, outFilename string) error {
func runStaticViewDeploy(settings *loginScreenWelcomeDeployCommand, outFilename string) error {
// Basic checks on the input file.
inFilename := settings.File
if _, err := os.Stat(inFilename); err != nil {
Expand Down Expand Up @@ -329,7 +329,7 @@ func runStaticViewDeploy(settings *LoginScreenWelcomeDeployCommand, outFilename
}

// Undeploy specified static file view from assets/static-page-content.
func runStaticViewUndeploy(settings *LoginScreenWelcomeUndeployCommand, filename string) error {
func runStaticViewUndeploy(settings *loginScreenWelcomeUndeployCommand, filename string) error {
// Get the directory where our file is to be copied.
directory, err := getOrLocateStaticPageContentDir(settings.RestStaticFilesDir)
if err != nil {
Expand Down Expand Up @@ -413,7 +413,7 @@ func newApp() *cli.App {
// feature.

// Database creation commands.
databaseCreateCommand := &DatabaseCreateCommand{}
databaseCreateCommand := &databaseCreateCommand{}
app.RegisterCommand(
"db-create", "Create new Stork database", databaseCreateCommand,
func() {
Expand All @@ -427,15 +427,15 @@ func newApp() *cli.App {
databasePasswordGenCommand, runDBPasswordGen,
)

databaseInitCommand := &DatabaseCommand{}
databaseInitCommand := &databaseCommand{}
app.RegisterCommand(
"db-init", "Create schema versioning table in the database",
databaseInitCommand, func() {
runDBMigrate(databaseInitCommand.DatabaseSettings, "init", "")
},
)

databaseUpCommand := &DatabaseVersionCommand{}
databaseUpCommand := &databaseVersionCommand{}
app.RegisterCommand(
"db-up", "Run all available migrations or use -t to specify version",
databaseUpCommand, func() {
Expand All @@ -447,7 +447,7 @@ func newApp() *cli.App {
},
)

databaseDownCommand := &DatabaseVersionCommand{}
databaseDownCommand := &databaseVersionCommand{}
app.RegisterCommand(
"db-down", "Revert last migration or use -t to specify version to downgrade to",
databaseDownCommand, func() {
Expand All @@ -459,23 +459,23 @@ func newApp() *cli.App {
},
)

databaseResetCommand := &DatabaseCommand{}
databaseResetCommand := &databaseCommand{}
app.RegisterCommand(
"db-reset", "Reset the database to the initial state",
databaseResetCommand, func() {
runDBMigrate(databaseResetCommand.DatabaseSettings, "reset", "")
},
)

databaseVersionCommand := &DatabaseCommand{}
dbVersionCommand := &databaseCommand{}
app.RegisterCommand(
"db-version", "Get the current database schema version",
databaseVersionCommand, func() {
runDBMigrate(databaseVersionCommand.DatabaseSettings, "version", "")
dbVersionCommand, func() {
runDBMigrate(dbVersionCommand.DatabaseSettings, "version", "")
},
)

databaseSetVersionCommand := &DatabaseVersionCommand{}
databaseSetVersionCommand := &databaseVersionCommand{}
app.RegisterCommand(
"db-set-version", "Set the database schema version",
databaseSetVersionCommand, func() {
Expand All @@ -488,7 +488,7 @@ func newApp() *cli.App {
)

// Certificate management commands.
certificateExportCommand := &CertificateExportCommand{}
certificateExportCommand := &certificateExportCommand{}
app.RegisterCommand(
"cert-export", "Export Stork Server keys, certificates, and tokens",
certificateExportCommand, func() {
Expand All @@ -499,7 +499,7 @@ func newApp() *cli.App {
},
)

certificateImportCommand := &CertificateImportCommand{}
certificateImportCommand := &certificateImportCommand{}
app.RegisterCommand(
"cert-import", "Import Stork Server keys, certificates, and tokens",
certificateImportCommand, func() {
Expand All @@ -511,7 +511,7 @@ func newApp() *cli.App {
)

// Hook inspection command.
hookInspectCommand := &HookInspectCommand{}
hookInspectCommand := &hookInspectCommand{}
app.RegisterCommand(
"hook-inspect", "Inspect the hook file or directory",
hookInspectCommand, func() {
Expand All @@ -523,7 +523,7 @@ func newApp() *cli.App {
)

// Static views deployment commands.
loginScreenWelcomeDeployCommand := &LoginScreenWelcomeDeployCommand{}
loginScreenWelcomeDeployCommand := &loginScreenWelcomeDeployCommand{}
app.RegisterCommand(
"deploy-login-page-welcome",
"Deploy custom welcome message on the login screen",
Expand All @@ -538,7 +538,7 @@ func newApp() *cli.App {
},
)

loginScreenWelcomeUndeployCommand := &LoginScreenWelcomeUndeployCommand{}
loginScreenWelcomeUndeployCommand := &loginScreenWelcomeUndeployCommand{}
app.RegisterCommand(
"undeploy-login-page-welcome",
"Undeploy custom welcome message on the login screen",
Expand Down