Skip to content

Commit

Permalink
Enforce linting, fix suggestions (#102)
Browse files Browse the repository at this point in the history
* Capture gofmt errors, add golint

* Resolve linting violations
  • Loading branch information
broamski authored Apr 7, 2023
1 parent 4af6c7a commit 633e932
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ coverage:
lint:
go vet ${PACKAGES}
gofmt -d -l ${GOFILES}
test -z $(shell gofmt -d -l ${GOFILES})
GO111MODULE=off \
go get -u golang.org/x/lint/golint
golint -set_exit_status ${PACKAGES}

build:
CGO_ENABLED=0 go build ${GO_LDFLAGS} -o daytona cmd/daytona/main.go
Expand Down
12 changes: 6 additions & 6 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ func EnsureAuthenticated(client *api.Client, config cfg.Config) bool {
// If it didn't find one, attempt to read token from disk.
log.Info().Msg("Checking for an existing, valid vault token")

if err := checkToken(client); err == nil {
err := checkToken(client)
if err == nil {
log.Info().Msg("Found an existing, valid token via VAULT_TOKEN")
return true
} else {
log.Info().Msgf("Couldn't use VAULT_TOKEN, attempting file token instead: %s", err)
}
log.Info().Msgf("Couldn't use VAULT_TOKEN, attempting file token instead: %s", err)

if err := checkFileToken(client, config.TokenPath); err == nil {
err = checkFileToken(client, config.TokenPath)
if err == nil {
log.Info().Str("tokenPath", config.TokenPath).Msg("Found an existing token at token path, setting as client token")
return true
} else {
log.Info().Err(err).Str("tokenPath", config.TokenPath).Msg("File token failed, trying to re-authenticate")
}
log.Info().Err(err).Str("tokenPath", config.TokenPath).Msg("File token failed, trying to re-authenticate")

bo := backoff.NewExponentialBackOff()
bo.MaxInterval = time.Second * 15
Expand Down
2 changes: 2 additions & 0 deletions pkg/auth/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package auth

import (
Expand All @@ -27,6 +28,7 @@ import (
// AzureService is an external service that vault can authenticate request against
type AzureService struct{}

// Auth is used to authenticate to the service
func (a *AzureService) Auth(client *api.Client, config cfg.Config) (string, error) {
metadata, err := a.getMetadata()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/auth/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package auth

import (
Expand Down
2 changes: 2 additions & 0 deletions pkg/auth/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package auth

import (
Expand All @@ -29,6 +30,7 @@ import (
)

var (
// ErrInferRoleClaims is returns when the authenticator fails to infer a role name
ErrInferRoleClaims = errors.New("could not parse service-account name / role name from claims")
)

Expand Down
1 change: 1 addition & 0 deletions pkg/daytona/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/hashicorp/vault/api"
)

// Option defines how an option should be applied
type Option interface {
Apply(s *SecretUnmarshler)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/daytona/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,30 @@ func NewSecretUnmarshler(opts ...Option) (*SecretUnmarshler, error) {
// (DATA EXAMPLE #1) Consider the design of the following secret path: secret/application, that contains
// several sub-keys:
//
// API_KEY - the data being stored in the data key 'value'
// DB_PASSWORD - the data being stored in the data key 'value'
// API_KEY - the data being stored in the data key 'value'
// DB_PASSWORD - the data being stored in the data key 'value'
//
// (DATA EXAMPLE #2) Consider the design of the following secret path: secret/application/configs, that contains
// several data keys
//
// api_key
// db_password
// api_key
// db_password
//
// A field tagged with 'vault_path_key' implies that the apex is a top-level secret path,
// and the value provided by 'vault_path_key' is the suffix key in the path. The full final path will
// be a combination of the apex and the path key. e.g. Using the example #1 above, an apex of secret/application
// with a 'vault_path_key' of DB_PASSWORD, will attempt to read the data stored in secret/application/DB_PASSSWORD.
// By default a data key of 'value' is used. The data key can be customized via the tag `vault_path_data_key`
//
// Field string `vault_path_key:"DB_PASSWORD"`
// Field string `vault_path_key:"DB_PASSWORD" vault_path_data_key:"password"` // data key override
// Field string `vault_path_key:"DB_PASSWORD"`
// Field string `vault_path_key:"DB_PASSWORD" vault_path_data_key:"password"` // data key override
//
// A field tagged with 'vault_data_key' implies that the apex is a full, final secret path
// and the value provided by 'vault_data_key' is the name of the data key. e.g. an apex of secret/application/configs
// with a 'vault_data_key' of db_password, will attempt to read the data stored in secret/application/configs, referncing
// the db_password data key.
//
// Field string `vault_data_key:"db_password"`
// Field string `vault_data_key:"db_password"`
func (su SecretUnmarshler) Unmarshal(ctx context.Context, apex string, v interface{}) error {
val := reflect.ValueOf(v)
if val.Kind() != reflect.Ptr {
Expand Down
1 change: 1 addition & 0 deletions pkg/helpers/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
)

// WriteFile is a convenience method for writing data to a filesystem
func WriteFile(path string, data []byte, perm fs.FileMode) error {
dir, _ := filepath.Split(path)
err := os.MkdirAll(dir, os.ModePerm)
Expand Down
2 changes: 2 additions & 0 deletions pkg/helpers/testhelpers/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package testhelpers

import "github.com/hashicorp/vault/api"

// GetTestClient returns a vault api client configured to the
// supplied url. This is intented to be used in tests
func GetTestClient(url string) (*api.Client, error) {
vaultConfig := api.DefaultConfig()
vaultConfig.Address = url
Expand Down
3 changes: 3 additions & 0 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"github.com/rs/zerolog/log"
)

// EnvLevel defines the envionrment variable name to use
// to determine the log level
const EnvLevel = "LOG_LEVEL"

// Config holds configuration items for the logger
type Config struct {
Structured bool
Level string
Expand Down
6 changes: 3 additions & 3 deletions pkg/pki/pki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@ func testHandler() http.Handler {
if strings.HasSuffix(r.URL.Path, "correct-role") {
decoder := json.NewDecoder(r.Body)
tstr := struct {
Alt_names string `json:"alt_names"`
Common_name string `json:"common_name"`
AltNames string `json:"alt_names"`
CommonName string `json:"common_name"`
}{}
_ = decoder.Decode(&tstr)
if len(strings.Split(tstr.Alt_names, ",")) > 1 {
if len(strings.Split(tstr.AltNames, ",")) > 1 {
fmt.Fprint(w, testPkiIssueResponseMultipleDomain)
} else {
fmt.Fprint(w, testPkiIssueResponseSingleDomain)
Expand Down
3 changes: 1 addition & 2 deletions pkg/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,8 @@ func (sd *SecretDefinition) copyValue(secretData map[string]interface{}, key str
sd.secrets[key] = secretValue
sd.Unlock()
return nil
} else {
return err
}
return err
}
return nil
}
Expand Down

0 comments on commit 633e932

Please sign in to comment.