Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions internal/manage/actions/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package action
import (
"encoding/json"
"fmt"
"os"

"github.com/OpenSlides/openslides-cli/internal/logger"
"github.com/OpenSlides/openslides-cli/internal/manage/client"
Expand Down Expand Up @@ -46,8 +47,16 @@ func Cmd() *cobra.Command {
passwordFile := cmd.Flags().String("password-file", "", "file with password for authorization (required)")
payloadFile := cmd.Flags().StringP("file", "f", "", "JSON file with the payload, or - for stdin")

_ = cmd.MarkFlagRequired("address")
_ = cmd.MarkFlagRequired("password-file")
if addressEnv := os.Getenv("OSMANAGE_BACKEND_ADDRESS"); addressEnv != "" {
address = &addressEnv
} else {
_ = cmd.MarkFlagRequired("address")
}
if passwordFileEnv := os.Getenv("OSMANAGE_BACKEND_PASSWORD_FILE"); passwordFileEnv != "" {
passwordFile = &passwordFileEnv
} else {
_ = cmd.MarkFlagRequired("password-file")
}

cmd.RunE = func(cmd *cobra.Command, args []string) error {
logger.Info("=== ACTION ===")
Expand Down
13 changes: 11 additions & 2 deletions internal/manage/actions/createuser/createuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package createuser
import (
"encoding/json"
"fmt"
"os"

"github.com/OpenSlides/openslides-cli/internal/logger"
"github.com/OpenSlides/openslides-cli/internal/manage/client"
Expand Down Expand Up @@ -46,8 +47,16 @@ func Cmd() *cobra.Command {
passwordFile := cmd.Flags().String("password-file", "", "file with password for authorization (required)")
userFile := cmd.Flags().StringP("file", "f", "", "JSON file with user data, or - for stdin")

_ = cmd.MarkFlagRequired("address")
_ = cmd.MarkFlagRequired("password-file")
if addressEnv := os.Getenv("OSMANAGE_BACKEND_ADDRESS"); addressEnv != "" {
address = &addressEnv
} else {
_ = cmd.MarkFlagRequired("address")
}
if passwordFileEnv := os.Getenv("OSMANAGE_BACKEND_PASSWORD_FILE"); passwordFileEnv != "" {
passwordFile = &passwordFileEnv
} else {
_ = cmd.MarkFlagRequired("password-file")
}

cmd.RunE = func(cmd *cobra.Command, args []string) error {
logger.Info("=== CREATE USER ===")
Expand Down
32 changes: 26 additions & 6 deletions internal/manage/actions/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"reflect"
"regexp"
"strconv"
Expand Down Expand Up @@ -94,12 +95,31 @@ func Cmd() *cobra.Command {
postgresDatabase := cmd.Flags().String("postgres-database", "", "PostgreSQL database (required)")
postgresPasswordFile := cmd.Flags().String("postgres-password-file", "", "PostgreSQL password file (required)")

// Mark PostgreSQL flags as required
_ = cmd.MarkFlagRequired("postgres-host")
_ = cmd.MarkFlagRequired("postgres-port")
_ = cmd.MarkFlagRequired("postgres-user")
_ = cmd.MarkFlagRequired("postgres-database")
_ = cmd.MarkFlagRequired("postgres-password-file")
if postgresHostEnv := os.Getenv("OSMANAGE_POSTGRES_HOST"); postgresHostEnv != "" {
postgresHost = &postgresHostEnv
} else {
_ = cmd.MarkFlagRequired("postgres-host")
}
if postgresPortEnv := os.Getenv("OSMANAGE_POSTGRES_PORT"); postgresPortEnv != "" {
postgresPort = &postgresPortEnv
} else {
_ = cmd.MarkFlagRequired("postgres-port")
}
if postgresUserEnv := os.Getenv("OSMANAGE_POSTGRES_USER"); postgresUserEnv != "" {
postgresUser = &postgresUserEnv
} else {
_ = cmd.MarkFlagRequired("postgres-user")
}
if postgresDatabaseEnv := os.Getenv("OSMANAGE_POSTGRES_DATABASE"); postgresDatabaseEnv != "" {
postgresDatabase = &postgresDatabaseEnv
} else {
_ = cmd.MarkFlagRequired("postgres-database")
}
if postgresPasswordFileEnv := os.Getenv("OSMANAGE_POSTGRES_PASSWORD_FILE"); postgresPasswordFileEnv != "" {
postgresPasswordFile = &postgresPasswordFileEnv
} else {
_ = cmd.MarkFlagRequired("postgres-password-file")
}

// Query flags
fields := cmd.Flags().StringSlice("fields", nil, "only include the provided fields in output")
Expand Down
12 changes: 10 additions & 2 deletions internal/manage/actions/initialdata/initialdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ func Cmd() *cobra.Command {
superadminPasswordFile := cmd.Flags().String("superadmin-password-file", "", "file with superadmin password (required)")
dataFile := cmd.Flags().StringP("file", "f", "", "JSON file with initial data, or - for stdin")

_ = cmd.MarkFlagRequired("address")
_ = cmd.MarkFlagRequired("password-file")
if addressEnv := os.Getenv("OSMANAGE_BACKEND_ADDRESS"); addressEnv != "" {
address = &addressEnv
} else {
_ = cmd.MarkFlagRequired("address")
}
if passwordFileEnv := os.Getenv("OSMANAGE_BACKEND_PASSWORD_FILE"); passwordFileEnv != "" {
passwordFile = &passwordFileEnv
} else {
_ = cmd.MarkFlagRequired("password-file")
}
_ = cmd.MarkFlagRequired("superadmin-password-file")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
Expand Down
13 changes: 11 additions & 2 deletions internal/manage/actions/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"strings"
"time"

Expand Down Expand Up @@ -115,8 +116,16 @@ func createMigrationCmd(name, description string, withProgressTracking bool) *co
address := cmd.Flags().StringP("address", "a", "", "address of the OpenSlides backendManage service (required)")
passwordFile := cmd.Flags().String("password-file", "", "file with password for authorization (required)")

_ = cmd.MarkFlagRequired("address")
_ = cmd.MarkFlagRequired("password-file")
if addressEnv := os.Getenv("OSMANAGE_BACKEND_ADDRESS"); addressEnv != "" {
address = &addressEnv
} else {
_ = cmd.MarkFlagRequired("address")
}
if passwordFileEnv := os.Getenv("OSMANAGE_BACKEND_PASSWORD_FILE"); passwordFileEnv != "" {
passwordFile = &passwordFileEnv
} else {
_ = cmd.MarkFlagRequired("password-file")
}

var progressInterval *time.Duration
if withProgressTracking {
Expand Down
13 changes: 11 additions & 2 deletions internal/manage/actions/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package set
import (
"encoding/json"
"fmt"
"os"
"sort"
"strings"

Expand Down Expand Up @@ -62,8 +63,16 @@ func Cmd() *cobra.Command {
passwordFile := cmd.Flags().String("password-file", "", "file with password for authorization (required)")
payloadFile := cmd.Flags().StringP("file", "f", "", "JSON file with the payload, or - for stdin")

_ = cmd.MarkFlagRequired("address")
_ = cmd.MarkFlagRequired("password-file")
if addressEnv := os.Getenv("OSMANAGE_BACKEND_ADDRESS"); addressEnv != "" {
address = &addressEnv
} else {
_ = cmd.MarkFlagRequired("address")
}
if passwordFileEnv := os.Getenv("OSMANAGE_BACKEND_PASSWORD_FILE"); passwordFileEnv != "" {
passwordFile = &passwordFileEnv
} else {
_ = cmd.MarkFlagRequired("password-file")
}

cmd.RunE = func(cmd *cobra.Command, args []string) error {
logger.Info("=== SET ACTION ===")
Expand Down
13 changes: 11 additions & 2 deletions internal/manage/actions/setpassword/setpassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package setpassword
import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/OpenSlides/openslides-cli/internal/logger"
Expand Down Expand Up @@ -30,8 +31,16 @@ func Cmd() *cobra.Command {
password := cmd.Flags().StringP("password", "p", "", "new password of the user (required)")
userID := cmd.Flags().Int64P("user_id", "u", 0, "ID of the user account (required)")

_ = cmd.MarkFlagRequired("address")
_ = cmd.MarkFlagRequired("password-file")
if addressEnv := os.Getenv("OSMANAGE_BACKEND_ADDRESS"); addressEnv != "" {
address = &addressEnv
} else {
_ = cmd.MarkFlagRequired("address")
}
if passwordFileEnv := os.Getenv("OSMANAGE_BACKEND_PASSWORD_FILE"); passwordFileEnv != "" {
passwordFile = &passwordFileEnv
} else {
_ = cmd.MarkFlagRequired("password-file")
}
_ = cmd.MarkFlagRequired("user_id")
_ = cmd.MarkFlagRequired("password")

Expand Down
Loading