Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: theopenlane/utils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.4.4
Choose a base ref
...
head repository: theopenlane/utils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.4.5
Choose a head ref
  • 5 commits
  • 25 files changed
  • 3 contributors

Commits on Mar 20, 2025

  1. fix(deps): update module github.com/redis/go-redis/v9 to v9.7.3 (#65)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 20, 2025
    Copy the full SHA
    a51b91c View commit details
  2. chore(deps): update slsa-framework/slsa-github-generator action to v2…

    ….1.0 (#62)
    
    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 20, 2025
    Copy the full SHA
    4a12baa View commit details

Commits on Mar 21, 2025

  1. Feat bumpgo (#66)

    * some upgrades
    
    * some upgrades
    
    * Update .buildkite/pipeline.yaml
    
    Co-authored-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
    Signed-off-by: Matt Anderson <42154938+matoszz@users.noreply.github.com>
    
    ---------
    
    Signed-off-by: Matt Anderson <42154938+matoszz@users.noreply.github.com>
    Co-authored-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
    matoszz and golanglemonade authored Mar 21, 2025
    Copy the full SHA
    eff0eb9 View commit details

Commits on Mar 28, 2025

  1. deps: golangci linter v2 (#69)

    * deps: golangci linter v2
    
    Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
    
    * bk pipeline
    
    Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
    
    * linter
    
    Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
    
    * bk pipeline
    
    Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
    
    ---------
    
    Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
    golanglemonade authored Mar 28, 2025
    Copy the full SHA
    7673c88 View commit details
  2. fix(deps): update module github.com/rs/zerolog to v1.34.0 (#68)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 28, 2025
    Copy the full SHA
    143e74a View commit details
10 changes: 5 additions & 5 deletions .buildkite/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -10,16 +10,16 @@ steps:
key: "lint"
plugins:
- docker#v5.12.0:
image: "registry.hub.docker.com/golangci/golangci-lint:v1.63.4"
command: ["golangci-lint", "run", "-v", "--timeout", "10m", "--config", ".golangci.yaml", "--concurrency", "0"]
image: "registry.hub.docker.com/golangci/golangci-lint:v2.0.2"
command: ["golangci-lint", "run", "-v", "--config", ".golangci.yaml", "--concurrency", "0"]
environment:
- "GOTOOLCHAIN=auto"
- label: ":golang: go test"
key: "go_test"
cancel_on_build_failing: true
plugins:
- docker#v5.12.0:
image: golang:1.23.5
image: golang:1.24.1
always-pull: true
command: ["go", "test", "-coverprofile=coverage.out", "./..."]
artifact_paths: ["coverage.out"]
@@ -35,7 +35,7 @@ steps:
download: "coverage.out"
step: "go_test"
- docker#v5.12.0:
image: "sonarsource/sonar-scanner-cli:11"
image: "sonarsource/sonar-scanner-cli:11.2"
environment:
- "SONAR_TOKEN"
- "SONAR_HOST_URL=$SONAR_HOST"
@@ -52,7 +52,7 @@ steps:
download: coverage.out
step: "go_test"
- docker#v5.12.0:
image: "sonarsource/sonar-scanner-cli:11"
image: "sonarsource/sonar-scanner-cli:11.2"
environment:
- "SONAR_TOKEN"
- "SONAR_HOST_URL=$SONAR_HOST"
2 changes: 1 addition & 1 deletion .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ jobs:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To add assets to a release.
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.0.0
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.1.0
with:
base64-subjects: "${{ needs.release.outputs.hashes }}"
upload-assets: true # upload to a new release
57 changes: 32 additions & 25 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
version: "2"
run:
timeout: 10m
allow-serial-runners: true
linters-settings:
goimports:
local-prefixes: github.com/theopenlane/utils
gofumpt:
extra-rules: true
gosec:
exclude-generated: true
revive:
ignore-generated-header: true
linters:
enable:
- bodyclose
- errcheck
- err113
- gocritic
- gocyclo
- err113
- gofmt
- goimports
- mnd
- gosimple
- govet
- gosec
- ineffassign
- misspell
- mnd
- noctx
- revive
- staticcheck
- stylecheck
- typecheck
- unused
- whitespace
- wsl
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- totp/testing/*
- third_party$
- builtin$
- examples$
issues:
fix: true
exclude-use-default: true
exclude-dirs:
- totp/testing/*
exclude-files:
formatters:
enable:
- gofmt
- goimports
settings:
gofumpt:
extra-rules: true
goimports:
local-prefixes:
- github.com/theopenlane/utils
exclusions:
generated: lax
paths:
- totp/testing/*
- third_party$
- builtin$
- examples$
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -10,10 +10,10 @@ repos:
- id: trailing-whitespace
- id: detect-private-key
- repo: https://github.com/google/yamlfmt
rev: v0.15.0
rev: v0.16.0
hooks:
- id: yamlfmt
- repo: https://github.com/crate-ci/typos
rev: v1.29.4
rev: v1.30.2
hooks:
- id: typos
Empty file removed .trivyignore
Empty file.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
<div align="center">

[![Build status](https://badge.buildkite.com/a3a38b934ca2bb7fc771e19bc5a986a1452fa2962e4e1c63bf.svg?branch=main)](https://buildkite.com/theopenlane/utils)
[![Go Reference](https://pkg.go.dev/badge/github.com/theopenlane/utils.svg)](https://pkg.go.dev/github.com/theopenlane/utils)
[![Go Report Card](https://goreportcard.com/badge/github.com/theopenlane/utils)](https://goreportcard.com/report/github.com/theopenlane/utils)
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache2.0-brightgreen.svg)](https://opensource.org/licenses/Apache-2.0)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=theopenlane_utils&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=theopenlane_util
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=theopenlane_utils&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=theopenlane_util)

</div>

# utils

Utilities for working within the openlane ecosystem
Utilities for working within the openlane ecosystem, high level overview of packages:

- cache: redis client interface
- cli: cli helper utilities for printing rows, tables
- contextx: The contextx package provides helper functions for managing context values, particularly for request-scoped data. It uses generics to simplify the handling of context keys.
- dumper: The dumper package is a utility for dumping HTTP request contents, useful for debugging and logging purposes.
- envparse: struct default parsing utility
- gravatar: create sweet robot avatars based on your email
- keygen: The keygen package provides utilities for generating and validating keys. It includes a key generator that can generate keys of any length and a key validator that can validate keys of any length.
- keyring: package keyring allows for quick and easy access to the system keyring service
- marionette: The marionette package is a task manager with scheduling, backoff, and future scheduling capabilities. It is designed as a temporary solution until an external state management system is implemented.
- passwd: The passwd package provides cryptographic utilities for handling passwords.
- rout: rout is a semi-centralized method of handling and surfacing user facing errors
- slack: very minimal slack functions for sending messages
- slice: a nice big juicy slice of functions for working with slices
- sqlite: sqlite client interface
- testutils: test utilities!
- ulids: The ulids package is a lightweight wrapper around the github.com/oklog/ulid package. It provides common functionality such as checking if a ULID is null or zero and includes a process-global, cryptographically random, monotonic, and thread-safe ULID generation mechanism.

## Contributing

See the [contributing](.github/CONTRIBUTING.md) guide for more information.
6 changes: 3 additions & 3 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -10,14 +10,14 @@ tasks:
go:lint:
desc: runs golangci-lint, the most annoying opinionated linter ever
cmds:
- golangci-lint run --config=.golangci.yaml --verbose --fast --fix
- golangci-lint run --config=.golangci.yaml --verbose --fix

go:lint:ci:
desc: runs golangci-lint, the most annoying opinionated linter ever, for CI
## do not use --fast or --fix in CI
## do not use --fix in CI
cmds:
- golangci-lint run --config=.golangci.yaml --verbose

go:fmt:
desc: format all go code
cmds:
2 changes: 2 additions & 0 deletions dumper/doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// Package dumper is a utility package for dumping http request contents
package dumper

// The dumper package is a utility for dumping HTTP request contents, useful for debugging and logging purposes.
12 changes: 6 additions & 6 deletions envparse/parse.go
Original file line number Diff line number Diff line change
@@ -19,8 +19,8 @@ type Config struct {
Skipper string
}

// varInfo maintains information about the configuration variable
type varInfo struct {
// VarInfo maintains information about the configuration variable
type VarInfo struct {
FieldName string
FullPath string
Key string
@@ -29,7 +29,7 @@ type varInfo struct {
}

// GatherEnvInfo gathers information about the specified struct, including defaults and environment variable names.
func (c Config) GatherEnvInfo(prefix string, spec interface{}) ([]varInfo, error) {
func (c Config) GatherEnvInfo(prefix string, spec interface{}) ([]VarInfo, error) {
s := reflect.ValueOf(spec)

// Ensure the specification is a pointer to a struct
@@ -45,7 +45,7 @@ func (c Config) GatherEnvInfo(prefix string, spec interface{}) ([]varInfo, error
typeOfSpec := s.Type()

// Create a slice to hold the information about the configuration variables
var infos []varInfo
var infos []VarInfo

// Iterate over the struct fields
for i := range s.NumField() {
@@ -76,7 +76,7 @@ func (c Config) GatherEnvInfo(prefix string, spec interface{}) ([]varInfo, error
continue
}

info := varInfo{
info := VarInfo{
FieldName: fieldName,
FullPath: ftype.Name,
Type: ftype.Type,
@@ -88,7 +88,7 @@ func (c Config) GatherEnvInfo(prefix string, spec interface{}) ([]varInfo, error

if prefix != "" {
info.Key = fmt.Sprintf("%s_%s", prefix, info.Key)
info.FullPath = fmt.Sprintf("%s.%s", strcase.LowerCamelCase(strings.Replace(prefix, "_", ".", -1)), info.FieldName) // nolint: gocritic
info.FullPath = fmt.Sprintf("%s.%s", strcase.LowerCamelCase(strings.ReplaceAll(prefix, "_", ".")), info.FieldName) // nolint: gocritic
}

info.Key = strings.ToUpper(info.Key)
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/theopenlane/utils

go 1.23.5
go 1.24.1

require (
entgo.io/ent v0.14.4
@@ -11,8 +11,8 @@ require (
github.com/oklog/ulid/v2 v2.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/ory/dockertest v3.3.5+incompatible
github.com/redis/go-redis/v9 v9.7.1
github.com/rs/zerolog v1.33.0
github.com/redis/go-redis/v9 v9.7.3
github.com/rs/zerolog v1.34.0
github.com/stoewer/go-strcase v1.3.0
github.com/stretchr/testify v1.10.0
github.com/theopenlane/echox v0.2.1
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -77,14 +77,14 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.7.1 h1:4LhKRCIduqXqtvCUlaq9c8bdHOkICjDMrr1+Zb3osAc=
github.com/redis/go-redis/v9 v9.7.1/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
github.com/redis/go-redis/v9 v9.7.3 h1:YpPyAayJV+XErNsatSElgRZZVCwXX9QzkKYNvO7x0wM=
github.com/redis/go-redis/v9 v9.7.3/go.mod h1:bGUrSggJ9X9GUmZpZNEOQKaANxSGgOEBRltRTZHSvrA=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
1 change: 1 addition & 0 deletions gravatar/gravatar.go
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ var (
baseURL, _ = url.Parse("https://www.gravatar.com")
)

// New returns a Gravatar image URL for the given email address
func New(email string, opts *Options) string {
if opts == nil {
opts = &Options{Size: defaultSize, DefaultImage: defaultImage, Rating: defaultRating}
12 changes: 6 additions & 6 deletions keygen/keygen_test.go
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ func TestAlpha(t *testing.T) {

// Test creating different random strings at different lengths
for i := 0; i < 10000; i++ {
len := rand.Intn(512) + 1 //nolint:gosec
alpha := keygen.Alpha(len)
require.Len(t, alpha, len)
length := rand.Intn(512) + 1 //nolint:gosec
alpha := keygen.Alpha(length)
require.Len(t, alpha, length)
require.Regexp(t, regexp.MustCompile(`[a-zA-Z]+`), alpha)
}

@@ -44,9 +44,9 @@ func TestAlphaNumeric(t *testing.T) {

// Test creating different random strings at different lengths
for i := 0; i < 10000; i++ {
len := rand.Intn(512) + 1 //nolint:gosec
alpha := keygen.AlphaNumeric(len)
require.Len(t, alpha, len)
length := rand.Intn(512) + 1 //nolint:gosec
alpha := keygen.AlphaNumeric(length)
require.Len(t, alpha, length)
require.Regexp(t, regexp.MustCompile(`[a-zA-Z0-9]+`), alpha)
}

3 changes: 2 additions & 1 deletion keyring/keyring.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,8 @@ import (
)

var (
ErrNoResultsFound error = errors.New("no results found")
// ErrNoResultsFound is returned when no results are found in the keyring
ErrNoResultsFound = errors.New("no results found")
)

// QueryKeyring queries the keyring for the first item with the given service and account
10 changes: 5 additions & 5 deletions marionette/config_test.go
Original file line number Diff line number Diff line change
@@ -5,17 +5,17 @@ import (

"github.com/stretchr/testify/require"

. "github.com/theopenlane/utils/marionette"
"github.com/theopenlane/utils/marionette"
)

func TestConfig(t *testing.T) {
testCases := []struct {
conf Config
conf marionette.Config
err error
}{
{Config{}, ErrNoWorkers},
{Config{Workers: 4}, ErrNoServerName},
{Config{Workers: 4, ServerName: "marionette"}, nil},
{marionette.Config{}, marionette.ErrNoWorkers},
{marionette.Config{Workers: 4}, marionette.ErrNoServerName},
{marionette.Config{Workers: 4, ServerName: "marionette"}, nil},
}

for i, tc := range testCases {
2 changes: 1 addition & 1 deletion marionette/error.go
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ func Errorw(err error) *Error {

// Errorf returns a pointer to a new `Error` struct with the specified error message formatted as a string and arguments
func Errorf(format string, a ...any) *Error {
return &Error{err: fmt.Errorf(format, a...)} // nolint: goerr113
return &Error{err: fmt.Errorf(format, a...)} // nolint:err113
}

// Error implements the error interface and gives a high level message about failures
Loading