Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
uses: openmfp/gha/.github/workflows/pipeline-golang-module.yml@main
uses: platform-mesh/.github/.github/workflows/pipeline-golang-module.yml@main
secrets: inherit
with:
useLocalCoverageConfig: true
Expand Down
4 changes: 2 additions & 2 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packages:
OpenFGAServiceClient:
config:
structname: OpenFGAServiceClient
github.com/openmfp/golang-commons/fga/store:
github.com/platform-mesh/golang-commons/fga/store:
config:
dir: fga/store/mocks
pkgname: mocks
Expand All @@ -18,7 +18,7 @@ packages:
FGAStoreHelper:
config:
structname: FGAStoreHelper
github.com/openmfp/golang-commons/policy_services:
github.com/platform-mesh/golang-commons/policy_services:
config:
dir: fga/policy_services/mocks
pkgname: mocks
Expand Down
9 changes: 0 additions & 9 deletions .reuse/dep5

This file was deleted.

2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Default code owners
* @openmfp/frame
* @platform-mesh/frame @platform-mesh/tsc
go.mod
go.sum
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Overview

# Contributing to openMFP
# Contributing to Platform Mesh
We want to make contributing to this project as easy and transparent as possible.

## Our development process
Expand All @@ -26,5 +26,5 @@ We use GitHub issues to track bugs. Please ensure your description is
clear and includes sufficient instructions to reproduce the issue.

## License
By contributing to openMFP, you agree that your contributions will be licensed
By contributing to Platform Mesh, you agree that your contributions will be licensed
under its [Apache-2.0 license](LICENSE).
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# openMFP - golang-commons
![Build Status](https://github.com/openmfp/golang-commons/actions/workflows/pipeline.yml/badge.svg)
****# Platform Mesh - golang-commons
![Build Status](https://github.com/platform-mesh/golang-commons/actions/workflows/pipeline.yml/badge.svg)
[![REUSE status](
https://api.reuse.software/badge/github.com/openmfp/golang-commons)](https://api.reuse.software/info/github.com/openmfp/golang-commons)
https://api.reuse.software/badge/github.com/platform-mesh/golang-commons)](https://api.reuse.software/info/github.com/platform-mesh/golang-commons)
## Description

golang-commons contains golang library packages to be reused across microservices and operators/controllers. The scope includes, but is not limited to:
Expand All @@ -12,13 +12,12 @@ golang-commons contains golang library packages to be reused across microservice
- Logging
- [Controllers](./controller/README.md)


## Getting started

Add the dependency to your go module based project like so:

```
go get github.com/openmfp/golang-commons
go get github.com/platform-mesh/golang-commons
```

## Releasing
Expand All @@ -41,12 +40,12 @@ P.S. If you have golang installed, it automatically installs the mockery binary

## Contributing

Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file in this repository for instructions on how to contribute to openMFP.
Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file in this repository for instructions on how to contribute to Platform Mesh.

## Code of Conduct

Please refer to the [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) file in this repository informations on the expected Code of Conduct for contributing to openMFP.
Please refer to the [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) file in this repository informations on the expected Code of Conduct for contributing to Platform Mesh.

## Licensing

Copyright 2024 SAP SE or an SAP affiliate company and openMFP contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/openmfp/golang-commons).
Copyright 2024 SAP SE or an SAP affiliate company and Platform Mesh contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/platform-mesh/golang-commons).
9 changes: 9 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version = 1
SPDX-PackageName = "golang-commons"
SPDX-PackageDownloadLocation = "https://github.com/platform-mesh/golang-commons"

[[annotations]]
path = "**"
precedence = "aggregate"
SPDX-FileCopyrightText = "2025 SAP SE or an SAP affiliate company and Platform Mesh contributors and golang-commons contributors."
SPDX-License-Identifier = "Apache-2.0"
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/openmfp/golang-commons/context/keys"
"github.com/openmfp/golang-commons/traces"
"github.com/platform-mesh/golang-commons/context/keys"
"github.com/platform-mesh/golang-commons/traces"
)

func SetConfigInContext(ctx context.Context, config any) context.Context {
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"

"github.com/openmfp/golang-commons/config"
"github.com/platform-mesh/golang-commons/config"
)

func TestSetConfigInContext(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"context"
"time"

"github.com/openmfp/golang-commons/config"
"github.com/openmfp/golang-commons/logger"
"github.com/platform-mesh/golang-commons/config"
"github.com/platform-mesh/golang-commons/logger"
)

// Can be used in StartContext to have a sane default timeout
Expand Down
2 changes: 1 addition & 1 deletion context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/openmfp/golang-commons/logger"
"github.com/platform-mesh/golang-commons/logger"
)

type TestConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion context/keys/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package keys

import "github.com/openmfp/golang-commons/jwt"
import "github.com/platform-mesh/golang-commons/jwt"

type ContextKey string

Expand Down
2 changes: 1 addition & 1 deletion context/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/getsentry/sentry-go"

"github.com/openmfp/golang-commons/logger"
"github.com/platform-mesh/golang-commons/logger"
)

// Recover can be used as deferred function to catch panics
Expand Down
2 changes: 1 addition & 1 deletion context/sentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

testlogger "github.com/openmfp/golang-commons/logger/testlogger"
testlogger "github.com/platform-mesh/golang-commons/logger/testlogger"
)

func TestRecover(t *testing.T) {
Expand Down
7 changes: 3 additions & 4 deletions context/service_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/go-jose/go-jose/v4"

"github.com/openmfp/golang-commons/context/keys"
"github.com/openmfp/golang-commons/jwt"
"github.com/openmfp/golang-commons/logger"
"github.com/platform-mesh/golang-commons/context/keys"
"github.com/platform-mesh/golang-commons/jwt"
"github.com/platform-mesh/golang-commons/logger"
)

type ContextKey string
Expand Down Expand Up @@ -104,4 +104,3 @@ func HasUserIDInContext(ctx context.Context) bool {
_, ok := ctx.Value(keys.UserIDCtxKey).(string)
return ok
}

59 changes: 29 additions & 30 deletions context/service_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/golang-jwt/jwt/v5"
"github.com/stretchr/testify/assert"

openmfpctx "github.com/openmfp/golang-commons/context"
"github.com/openmfp/golang-commons/context/keys"
openmfpjwt "github.com/openmfp/golang-commons/jwt"
pmcontext "github.com/platform-mesh/golang-commons/context"
"github.com/platform-mesh/golang-commons/context/keys"
pmjwt "github.com/platform-mesh/golang-commons/jwt"
)

type astruct struct{}
Expand All @@ -22,9 +22,9 @@ func TestAddSpiffeToContext(t *testing.T) {
t.Parallel()

ctx := context.Background()
ctx = openmfpctx.AddSpiffeToContext(ctx, "spiffe")
ctx = pmcontext.AddSpiffeToContext(ctx, "spiffe")

spiffe, err := openmfpctx.GetSpiffeFromContext(ctx)
spiffe, err := pmcontext.GetSpiffeFromContext(ctx)
assert.Nil(t, err)
assert.Equal(t, "spiffe", spiffe)
}
Expand All @@ -33,20 +33,20 @@ func TestWrongSpiffeToContext(t *testing.T) {
t.Parallel()

ctx := context.Background()
key := openmfpctx.ContextKey(openmfpjwt.SpiffeCtxKey)
key := pmcontext.ContextKey(pmjwt.SpiffeCtxKey)
ctx = context.WithValue(ctx, key, astruct{})

_, err := openmfpctx.GetSpiffeFromContext(ctx)
_, err := pmcontext.GetSpiffeFromContext(ctx)
assert.Error(t, err, "someone stored a wrong value in the [spiffe] key with type [context.astruct], expected [string]")
}

func TestAddTenantToContext(t *testing.T) {
t.Parallel()

ctx := context.Background()
ctx = openmfpctx.AddTenantToContext(ctx, "tenant")
ctx = pmcontext.AddTenantToContext(ctx, "tenant")

tenant, err := openmfpctx.GetTenantFromContext(ctx)
tenant, err := pmcontext.GetTenantFromContext(ctx)
assert.Nil(t, err)
assert.Equal(t, "tenant", tenant)
}
Expand All @@ -55,10 +55,10 @@ func TestAddTenantToContextNegative(t *testing.T) {
t.Parallel()

ctx := context.Background()
key := openmfpctx.ContextKey(openmfpjwt.TenantIdCtxKey)
key := pmcontext.ContextKey(pmjwt.TenantIdCtxKey)
ctx = context.WithValue(ctx, key, astruct{})

_, err := openmfpctx.GetTenantFromContext(ctx)
_, err := pmcontext.GetTenantFromContext(ctx)
assert.Error(t, err, "someone stored a wrong value in the [tenant] key with type [context.astruct], expected [string]")
}

Expand Down Expand Up @@ -95,7 +95,7 @@ func TestAddAndGetAuthHeaderToContext(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
ctx := context.WithValue(context.Background(), keys.AuthHeaderCtxKey, test.authHeader)

val, err := openmfpctx.GetAuthHeaderFromContext(ctx)
val, err := pmcontext.GetAuthHeaderFromContext(ctx)
if test.expectError {
assert.Error(t, err)
return
Expand All @@ -117,9 +117,9 @@ func TestAddWebTokenToContext(t *testing.T) {
tokenString, err := generateJWT(issuer)
assert.NoError(t, err)

ctx = openmfpctx.AddWebTokenToContext(ctx, tokenString, signatureAlgorithms)
ctx = pmcontext.AddWebTokenToContext(ctx, tokenString, signatureAlgorithms)

token, err := openmfpctx.GetWebTokenFromContext(ctx)
token, err := pmcontext.GetWebTokenFromContext(ctx)
assert.Nil(t, err)
assert.Equal(t, issuer, token.Issuer)
}
Expand All @@ -130,7 +130,7 @@ func TestAddWebTokenToContextNegative(t *testing.T) {
ctx := context.Background()
ctx = context.WithValue(ctx, keys.WebTokenCtxKey, nil)

_, err := openmfpctx.GetWebTokenFromContext(ctx)
_, err := pmcontext.GetWebTokenFromContext(ctx)
assert.ErrorContains(t, err, "someone stored a wrong value in the [webToken] key with type [<nil>], expected [jwt.WebToken]")
}

Expand All @@ -140,7 +140,7 @@ func TestAddWebTokenToContextWrongToken(t *testing.T) {
initialContext := context.Background()
tokenString := "not-a-token"

ctx := openmfpctx.AddWebTokenToContext(initialContext, tokenString, signatureAlgorithms)
ctx := pmcontext.AddWebTokenToContext(initialContext, tokenString, signatureAlgorithms)

assert.Equal(t, initialContext, ctx)
}
Expand All @@ -164,9 +164,9 @@ func TestAddIsTechnicalIssuerToContext(t *testing.T) {
t.Parallel()

ctx := context.Background()
ctx = openmfpctx.AddIsTechnicalIssuerToContext(ctx)
ctx = pmcontext.AddIsTechnicalIssuerToContext(ctx)

isTechnicalIssuer := openmfpctx.GetIsTechnicalIssuerFromContext(ctx)
isTechnicalIssuer := pmcontext.GetIsTechnicalIssuerFromContext(ctx)
assert.True(t, isTechnicalIssuer)
}

Expand All @@ -175,17 +175,17 @@ func TestAddIsTechnicalIssuerToContextNegative(t *testing.T) {

ctx := context.Background()

isTechnicalIssuer := openmfpctx.GetIsTechnicalIssuerFromContext(ctx)
isTechnicalIssuer := pmcontext.GetIsTechnicalIssuerFromContext(ctx)
assert.False(t, isTechnicalIssuer)
}

func TestHasTenantInContext(t *testing.T) {
t.Parallel()

ctx := context.Background()
ctx = openmfpctx.AddTenantToContext(ctx, "tenant")
ctx = pmcontext.AddTenantToContext(ctx, "tenant")

hasTenant := openmfpctx.HasTenantInContext(ctx)
hasTenant := pmcontext.HasTenantInContext(ctx)
assert.True(t, hasTenant)
}

Expand All @@ -194,17 +194,17 @@ func TestHasTenantInContextNegative(t *testing.T) {

ctx := context.Background()

hasTenant := openmfpctx.HasTenantInContext(ctx)
hasTenant := pmcontext.HasTenantInContext(ctx)
assert.False(t, hasTenant)
}

func TestAddUserIDToContextAndGetUserIDFromContext(t *testing.T) {
baseCtx := context.Background()
userID := "testUser123"

ctxWithUserID := openmfpctx.AddUserIDToContext(baseCtx, userID)
ctxWithUserID := pmcontext.AddUserIDToContext(baseCtx, userID)

retrievedUserID, err := openmfpctx.GetUserIDFromContext(ctxWithUserID)
retrievedUserID, err := pmcontext.GetUserIDFromContext(ctxWithUserID)
assert.NoError(t, err, "Expected no error when retrieving userID")
assert.Equal(t, userID, retrievedUserID, "Retrieved userID should match the added value")
}
Expand All @@ -214,7 +214,7 @@ func TestGetUserIDFromContextWrongType(t *testing.T) {

ctxWithWrongType := context.WithValue(baseCtx, keys.UserIDCtxKey, 123)

retrievedUserID, err := openmfpctx.GetUserIDFromContext(ctxWithWrongType)
retrievedUserID, err := pmcontext.GetUserIDFromContext(ctxWithWrongType)
assert.Error(t, err, "Expected an error when retrieving userID with the wrong type")
expectedErrorMsg := fmt.Sprintf("someone stored a wrong value in the [%s] key with type [%T], expected [string]", keys.UserIDCtxKey, ctxWithWrongType.Value(keys.UserIDCtxKey))
assert.Equal(t, expectedErrorMsg, err.Error(), "Error message should match the expected message")
Expand All @@ -224,12 +224,11 @@ func TestGetUserIDFromContextWrongType(t *testing.T) {
func TestHasUserIDInContext(t *testing.T) {
baseCtx := context.Background()

assert.False(t, openmfpctx.HasUserIDInContext(baseCtx), "Expected false when userID is not set in context")
assert.False(t, pmcontext.HasUserIDInContext(baseCtx), "Expected false when userID is not set in context")

ctxWithUserID := openmfpctx.AddUserIDToContext(baseCtx, "user123")
assert.True(t, openmfpctx.HasUserIDInContext(ctxWithUserID), "Expected true when a valid userID is set in context")
ctxWithUserID := pmcontext.AddUserIDToContext(baseCtx, "user123")
assert.True(t, pmcontext.HasUserIDInContext(ctxWithUserID), "Expected true when a valid userID is set in context")

ctxWithWrongType := context.WithValue(baseCtx, keys.UserIDCtxKey, 456)
assert.False(t, openmfpctx.HasUserIDInContext(ctxWithWrongType), "Expected false when the value stored is of the wrong type")
assert.False(t, pmcontext.HasUserIDInContext(ctxWithWrongType), "Expected false when the value stored is of the wrong type")
}

4 changes: 2 additions & 2 deletions controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Features of the `lifecycle` package:
func (l *LifecycleManager) SetupWithManager(mgr ctrl.Manager, maxReconciles int, reconcilerName string, instance RuntimeObject, debugLabelValue string, r reconcile.Reconciler, log *logger.Logger, eventPredicates ...predicate.Predicate) error
```

The **debugLabelValue** parameter enables filtering of the resources based on a `debug.openmfp.io` label. If the label has the value passed in **debugLabelValue**, the resource will be reconciled in the `Process` function of the subroutine and all other resources will be skipped. If the value is empty string, all resources will be reconciled. This could be useful in debuging situations.
The **debugLabelValue** parameter enables filtering of the resources based on a `debug.platform-mesh.io` label. If the label has the value passed in **debugLabelValue**, the resource will be reconciled in the `Process` function of the subroutine and all other resources will be skipped. If the value is empty string, all resources will be reconciled. This could be useful in debuging situations.

```yaml
apiVersion: myorg.com/v1alpha1
Expand All @@ -137,5 +137,5 @@ metadata:
name: resource1
namespace: mynamespace
labels:
debug.openmfp.io: test
debug.platform-mesh.io: test
```
Loading