Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: stylecheck #918

Merged
merged 12 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ linters:
- paralleltest # TODO
- protogetter # TODO
- revive # TODO
- stylecheck # TODO
- tagliatelle # TODO
- testpackage # TODO

Expand Down
33 changes: 16 additions & 17 deletions libs/common/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
// to avoid ambiguity please read: https://wiki.helpwave.de/doc/keycloak-jedzCcERwF

var (
DEFAULT_OAUTH_ISSUER_URL = "https://accounts.helpwave.de/realms/helpwave"

DEFAULT_OAUTH_CLIENT_ID = "helpwave-services"
DefaultOAuthIssuerURL = "https://accounts.helpwave.de/realms/helpwave"
DefaultOAuthClientID = "helpwave-services"
onlyFakeAuthEnabled bool
insecureFakeTokenEnable = false
oauthConfig *oauth2.Config
Expand All @@ -40,22 +39,22 @@ type (
organizationIDKey struct{}
)

func GetOAuthIssuerUrl() string {
issuerUrl := hwutil.GetEnvOr("OAUTH_ISSUER_URL", DEFAULT_OAUTH_ISSUER_URL)
if issuerUrl != DEFAULT_OAUTH_ISSUER_URL {
func GetOAuthIssuerURL() string {
issuerURL := hwutil.GetEnvOr("OAUTH_ISSUER_URL", DefaultOAuthIssuerURL)
if issuerURL != DefaultOAuthIssuerURL {
zlog.Warn().
Str("OAUTH_ISSUER_URL", issuerUrl).
Str("OAUTH_ISSUER_URL", issuerURL).
Msg("using custom OAuth issuer url")
}
return issuerUrl
return issuerURL
}

func GetOAuthClientId() string {
clientId := hwutil.GetEnvOr("OAUTH_CLIENT_ID", DEFAULT_OAUTH_CLIENT_ID)
if clientId != DEFAULT_OAUTH_CLIENT_ID {
zlog.Warn().Str("OAUTH_CLIENT_ID", clientId).Msg("using custom OAuth client id")
func GetOAuthClientID() string {
clientID := hwutil.GetEnvOr("OAUTH_CLIENT_ID", DefaultOAuthClientID)
if clientID != DefaultOAuthClientID {
zlog.Warn().Str("OAUTH_CLIENT_ID", clientID).Msg("using custom OAuth client id")
}
return clientId
return clientID
}

func IsOnlyFakeAuthEnabled() bool {
Expand Down Expand Up @@ -109,7 +108,7 @@ type IDTokenClaims struct {
}

type OrganizationTokenClaim struct {
Id string `json:"id" validate:"required,uuid"`
ID string `json:"id" validate:"required,uuid"`
Name string `json:"name" validate:"required"`
}

Expand Down Expand Up @@ -156,7 +155,7 @@ func VerifyFakeToken(ctx context.Context, token string) (*IDTokenClaims, *time.T
}

claims := IDTokenClaims{}
if err := hwutil.ParseValidJson(plainToken, &claims); err != nil {
if err := hwutil.ParseValidJSON(plainToken, &claims); err != nil {
return nil, nil, fmt.Errorf("VerifyFakeToken: cant parse json: %w", err)
}

Expand Down Expand Up @@ -267,13 +266,13 @@ func SetupAuth(ctx context.Context, fakeOnly bool, passedInsecureFakeTokenEnable

insecureFakeTokenEnable = passedInsecureFakeTokenEnable

provider, err := oidc.NewProvider(context.Background(), GetOAuthIssuerUrl())
provider, err := oidc.NewProvider(context.Background(), GetOAuthIssuerURL())
if err != nil {
log.Fatal().Err(err).Send()
}

oauthConfig = &oauth2.Config{
ClientID: GetOAuthClientId(),
ClientID: GetOAuthClientID(),
Endpoint: provider.Endpoint(),
}

Expand Down
10 changes: 5 additions & 5 deletions libs/common/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestIDTokenClaims_AsExpected(t *testing.T) {
Name: "Test User",
PreferredUsername: "testuser",
Organization: &OrganizationTokenClaim{
Id: "6759b6d7-a864-800c-a2e9-a780a83ec767",
ID: "6759b6d7-a864-800c-a2e9-a780a83ec767",
Name: "Example Org",
},
},
Expand All @@ -33,7 +33,7 @@ func TestIDTokenClaims_AsExpected(t *testing.T) {
Name: "Test User",
PreferredUsername: "testuser",
Organization: &OrganizationTokenClaim{
Id: "6759b6d7-a864-800c-a2e9-a780a83ec767",
ID: "6759b6d7-a864-800c-a2e9-a780a83ec767",
Name: "Example Org",
},
},
Expand All @@ -47,7 +47,7 @@ func TestIDTokenClaims_AsExpected(t *testing.T) {
Name: "Test User",
PreferredUsername: "testuser",
Organization: &OrganizationTokenClaim{
Id: "6759b6d7-a864-800c-a2e9-a780a83ec767",
ID: "6759b6d7-a864-800c-a2e9-a780a83ec767",
Name: "Example Org",
},
},
Expand All @@ -71,7 +71,7 @@ func TestIDTokenClaims_AsExpected(t *testing.T) {
Name: "Test User",
PreferredUsername: "testuser",
Organization: &OrganizationTokenClaim{
Id: "asdasd",
ID: "asdasd",
Name: "Example Org",
},
},
Expand All @@ -85,7 +85,7 @@ func TestIDTokenClaims_AsExpected(t *testing.T) {
Name: "Test User",
PreferredUsername: "testuser",
Organization: &OrganizationTokenClaim{
Id: "",
ID: "",
Name: "",
},
},
Expand Down
4 changes: 2 additions & 2 deletions libs/common/dapr.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func MustNewDaprGRPCClient() *daprc.GRPCClient {
}

// PrepCtxForSvcToSvcCall returns a context that can be used with Dapr specific service to service gRPC calls
func PrepCtxForSvcToSvcCall(ctx context.Context, targetDaprAppId string) (context.Context, context.CancelFunc, error) {
func PrepCtxForSvcToSvcCall(ctx context.Context, targetDaprAppID string) (context.Context, context.CancelFunc, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return nil, nil, status.Errorf(codes.Internal, "No incoming metadata in context")
Expand All @@ -72,7 +72,7 @@ func PrepCtxForSvcToSvcCall(ctx context.Context, targetDaprAppId string) (contex

timeout := time.Second * 3
ctx, cancel := context.WithTimeout(outgoingCtx, timeout)
ctx = metadata.AppendToOutgoingContext(ctx, "dapr-app-id", targetDaprAppId)
ctx = metadata.AppendToOutgoingContext(ctx, "dapr-app-id", targetDaprAppID)

return ctx, cancel, nil
}
8 changes: 4 additions & 4 deletions libs/common/hwgrpc/organization_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func StreamOrganizationInterceptor(
return next(req, stream)
}

var ErrOrganizationIdMissing = errors.New("organization.id missing in id token")
var ErrOrganizationIDMissing = errors.New("organization.id missing in id token")

// organizationInterceptor parses and injects the organization id of the OIDC claims into the current context
// This is a separate function to allow endpoints to not fail when an organization id is not provided
Expand All @@ -62,12 +62,12 @@ func organizationInterceptor(ctx context.Context) (context.Context, error) {
return nil, err
}

if len(claims.Organization.Id) == 0 {
return nil, ErrOrganizationIdMissing
if len(claims.Organization.ID) == 0 {
return nil, ErrOrganizationIDMissing
}

// parse organizationID
organizationID, err := uuid.Parse(claims.Organization.Id)
organizationID, err := uuid.Parse(claims.Organization.ID)
if err != nil {
return nil, status.Errorf(codes.Internal, "invalid organizationID")
}
Expand Down
8 changes: 4 additions & 4 deletions libs/common/test/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ func AuthenticatedUserClaim(userID string) map[string]interface{} {
// AuthenticatedUserMetadata gives you a ready-to use grpc metadata object
func AuthenticatedUserMetadata(userID string) metadata.MD {
claims := AuthenticatedUserClaim(userID)
claimsJson, err := json.Marshal(claims)
claimsJSON, err := json.Marshal(claims)
if err != nil {
log.Fatal(err)
}
fakeToken := base64.StdEncoding.EncodeToString(claimsJson)
fakeToken := base64.StdEncoding.EncodeToString(claimsJSON)

return metadata.New(map[string]string{
"Authorization": "Bearer " + fakeToken,
})
}

func AuthenticatedUserContext(ctx context.Context, userId string) context.Context {
md := AuthenticatedUserMetadata(userId)
func AuthenticatedUserContext(ctx context.Context, userID string) context.Context {
md := AuthenticatedUserMetadata(userID)
if existing, existed := metadata.FromOutgoingContext(ctx); existed {
md = metadata.Join(md, existing)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# decaying_lru
# decayinglru

A module, which allows a service to leverage a redis-powered [LRU](https://en.wikipedia.org/wiki/Least_Recently_Used) which decays.
Such a data structure is, for example, needed for `recently-used` tracking.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"time"

"decaying_lru"
"decayinglru"
)

func must(err error) {
Expand All @@ -22,7 +22,7 @@ const (

func main() {
ctx := context.Background()
lru := decaying_lru.Setup(ctx, "example", size, time.Second, inverseP)
lru := decayinglru.Setup(ctx, "example", size, time.Second, inverseP)

must(lru.AddItemForUser(ctx, "test", "1", "abc"))
must(lru.AddItemForUser(ctx, "test", "1", "def"))
Expand Down
2 changes: 1 addition & 1 deletion libs/decaying_lru/go.mod → libs/decaying-lru/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module decaying_lru
module decayinglru

go 1.23

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion libs/decaying_lru/lru.go → libs/decaying-lru/lru.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package decaying_lru
package decayinglru

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package decaying_lru
package decayinglru

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commonPerm
package commonperm

import "hwauthz"

Expand All @@ -7,13 +7,13 @@ import "hwauthz"
// For example for tests, or if the type is only used once or so
type GenericObject struct {
Typ hwauthz.ObjectType
Id string
ID_ string
}

func (s GenericObject) Type() hwauthz.ObjectType {
return s.Typ
}

func (s GenericObject) ID() string {
return s.Id
return s.ID_
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commonPerm
package commonperm

import (
"common/auth"
Expand Down
6 changes: 3 additions & 3 deletions libs/hwauthz/spicedb/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

const (
migrationResourceType = "spice_schema_migrations/migration"
migrationResourceId = "current"
migrationResourceID = "current"
migrationRelation = "version"
migrationSubjectType = "spice_schema_migrations/version"
)
Expand All @@ -34,7 +34,7 @@ func GetCurrentVersion(ctx context.Context, client *authzed.Client) int {
stream, err := client.ReadRelationships(ctx, &v1.ReadRelationshipsRequest{
RelationshipFilter: &v1.RelationshipFilter{
ResourceType: migrationResourceType,
OptionalResourceId: migrationResourceId,
OptionalResourceId: migrationResourceID,
OptionalRelation: migrationRelation,
},
OptionalLimit: 0,
Expand Down Expand Up @@ -113,7 +113,7 @@ func relationshipOfVersion(version int) *v1.Relationship {
return &v1.Relationship{
Resource: &v1.ObjectReference{
ObjectType: migrationResourceType,
ObjectId: migrationResourceId,
ObjectId: migrationResourceID,
},
Relation: migrationRelation,
Subject: &v1.SubjectReference{
Expand Down
8 changes: 4 additions & 4 deletions libs/hwauthz/spicedb/spicedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func fullyConsistent() *v1.Consistency {
}
}

func SetupSpiceDbByEnv() *authzed.Client {
func SetupSpiceDBByEnv() *authzed.Client {
endpoint := hwutil.MustGetEnv("ZED_ENDPOINT")
token := hwutil.MustGetEnv("ZED_TOKEN")
return SetupSpiceDb(endpoint, token)
return SetupSpiceDB(endpoint, token)
}

func SetupSpiceDb(endpoint, token string) *authzed.Client {
func SetupSpiceDB(endpoint, token string) *authzed.Client {
log := zlog.Logger // global logger

client, err := authzed.NewClient(
Expand Down Expand Up @@ -76,7 +76,7 @@ type SpiceDBAuthZ struct {

// NewSpiceDBAuthZ constructs a new SpiceDBAuthZ instance
func NewSpiceDBAuthZ() *SpiceDBAuthZ {
client := SetupSpiceDbByEnv()
client := SetupSpiceDBByEnv()
return &SpiceDBAuthZ{client: client}
}

Expand Down
Loading
Loading