featurebase/ctl/keygen.go
Travis Turner aa17b8d725
Enable linter: stylecheck (#2317)
* Enable linter: stylecheck

This enabled the stylecheck linter, but excludes some staticchecks for
now. The following are ignored because they will take a bit of time to
address, but the intention is to address them and remove them from the
exclusion list.

ST1000: at least one file in a package should have a package comment
ST1003: golang naming standards
ST1008: error should be returned as the last argument
ST1016: methods on the same type should have the same receiver name
ST1020: comment on exported function

* Address ST1015

For some reason this failed in CI but not locally. I can't figure out
why that check isn't happening locally. This just moves the switch
statements around so that the `default` is the first (or last) item.

* Adjust error string in test to match case-adjusted error

* Remove TestCloseTimeout
2023-03-14 08:45:18 -05:00

34 lines
801 B
Go

// Copyright 2022 Molecula Corp. (DBA FeatureBase).
// SPDX-License-Identifier: Apache-2.0
package ctl
import (
"context"
"fmt"
"io"
"os"
"github.com/featurebasedb/featurebase/v3/logger"
"github.com/gorilla/securecookie"
)
// KeygenCommand represents a command for generating a cryptographic key.
type KeygenCommand struct {
stdout io.Writer
logDest logger.Logger
KeyLength int
}
// NewKeygen returns a new instance of Keygen.
func NewKeygenCommand(logdest logger.Logger) *KeygenCommand {
return &KeygenCommand{
stdout: os.Stdout,
logDest: logdest,
}
}
// Run keygen to obtain key to use for authentication .
func (kg *KeygenCommand) Run(_ context.Context) error {
fmt.Fprintf(kg.stdout, "secret-key = \"%+x\"\n", securecookie.GenerateRandomKey(kg.KeyLength))
return nil
}