Skip to content

Commit

Permalink
fix unused error for staticcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Feb 15, 2024
1 parent a8856fc commit c1808eb
Showing 1 changed file with 76 additions and 73 deletions.
149 changes: 76 additions & 73 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,93 +20,96 @@ import (
)

type AppConfig struct {

Check failure on line 22 in main.go

View workflow job for this annotation

GitHub Actions / audit

exported type AppConfig should have comment or be unexported
APIURL string
HTTPHeaders string
User string
Password string
OTP string
NewCLI bool
APIURL string
HTTPHeaders string
User string
Password string
OTP string
NewCLI bool
}

func loadAppConfig() AppConfig {
newCLI := os.Getenv("NEW_CLI") == "true"

if err := godotenv.Load(); err != nil {
log.Printf("Warning: Failed to load .env file: %v", err)
}

return AppConfig{
APIURL: os.Getenv("PM_API_URL"),
HTTPHeaders: os.Getenv("PM_HTTP_HEADERS"),
User: os.Getenv("PM_USER"),
Password: os.Getenv("PM_PASS"),
OTP: os.Getenv("PM_OTP"),
NewCLI: newCLI,
}
newCLI := os.Getenv("NEW_CLI") == "true"

if err := godotenv.Load(); err != nil {
log.Printf("Warning: Failed to load .env file: %v", err)
}

return AppConfig{
APIURL: os.Getenv("PM_API_URL"),
HTTPHeaders: os.Getenv("PM_HTTP_HEADERS"),
User: os.Getenv("PM_USER"),
Password: os.Getenv("PM_PASS"),
OTP: os.Getenv("PM_OTP"),
NewCLI: newCLI,
}
}

func initializeProxmoxClient(config AppConfig, insecure bool, proxyURL string, taskTimeout int) (*proxmox.Client, error) {
tlsconf := &tls.Config{InsecureSkipVerify: insecure}
if !insecure {
tlsconf = nil
}
client, err := proxmox.NewClient(config.APIURL, nil, config.HTTPHeaders, tlsconf, proxyURL, taskTimeout)
if err != nil {
return nil, err
}
if userRequiresAPIToken(config.User) {
client.SetAPIToken(config.User, config.Password)
_, err := client.GetVersion()
if err != nil {
return nil, err
}
} else {
err = client.Login(config.User, config.Password, config.OTP)
if err != nil {
return nil, err
}
}
return client, nil
tlsconf := &tls.Config{InsecureSkipVerify: insecure}
if !insecure {
tlsconf = nil
}

client, err := proxmox.NewClient(config.APIURL, nil, config.HTTPHeaders, tlsconf, proxyURL, taskTimeout)
if err != nil {
return nil, err
}

if userRequiresAPIToken(config.User) {
client.SetAPIToken(config.User, config.Password)
_, err := client.GetVersion()
if err != nil {
return nil, err
}
} else {
err = client.Login(config.User, config.Password, config.OTP)
if err != nil {
return nil, err
}
}

return client, nil
}

func main() {

config := loadAppConfig()

if config.NewCLI {
err := cli.Execute()
if err != nil {
failError(err)
}
os.Exit(0)
}

// Command-line flags
insecure := flag.Bool("insecure", false, "TLS insecure mode")
proxmox.Debug = flag.Bool("debug", false, "debug mode")
fConfigFile := flag.String("file", "", "file to get the config from")
taskTimeout := flag.Int("timeout", 300, "API task timeout in seconds")
proxyURL := flag.String("proxy", "", "proxy URL to connect to")
fvmid := flag.Int("vmid", -1, "custom VMID (instead of auto)")
flag.Parse()

// Initialize Proxmox client
config := loadAppConfig()

if config.NewCLI {
err := cli.Execute()
if err != nil {
failError(err)
}
os.Exit(0)
}

// Command-line flags
insecure := flag.Bool("insecure", false, "TLS insecure mode")
proxmox.Debug = flag.Bool("debug", false, "debug mode")
fConfigFile := flag.String("file", "", "file to get the config from")
taskTimeout := flag.Int("timeout", 300, "API task timeout in seconds")
proxyURL := flag.String("proxy", "", "proxy URL to connect to")
fvmid := flag.Int("vmid", -1, "custom VMID (instead of auto)")
flag.Parse()

// Initialize Proxmox client
c, err := initializeProxmoxClient(config, *insecure, *proxyURL, *taskTimeout)
if err != nil {
log.Fatalf("Failed to initialize Proxmox client: %v", err)
}

vmid := *fvmid
if vmid < 0 {
if len(flag.Args()) > 1 {
vmid, err = strconv.Atoi(flag.Args()[1])
if err != nil {
vmid := *fvmid
if vmid < 0 {
if len(flag.Args()) > 1 {
vmid, err = strconv.Atoi(flag.Args()[1])
if err != nil {
vmid = 0
}
} else if len(flag.Args()) == 0 || (flag.Args()[0] == "idstatus") {
vmid = 0
}
}
} else if len(flag.Args()) == 0 || (flag.Args()[0] == "idstatus") {
vmid = 0
}
}

var jbody interface{}
var vmr *proxmox.VmRef
Expand Down

0 comments on commit c1808eb

Please sign in to comment.