Skip to content

Commit

Permalink
Remove dependencies on controller-runtime and k8s packages
Browse files Browse the repository at this point in the history
Signed-off-by: Dipti Pai <[email protected]>
  • Loading branch information
dipti-pai committed Aug 22, 2024
1 parent bb129d6 commit a2f84e1
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 26 deletions.
4 changes: 0 additions & 4 deletions auth/constants.go → auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ limitations under the License.
*/

package auth

const (
ProviderAzure = "azure"
)
4 changes: 2 additions & 2 deletions auth/azure/token_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
. "github.com/onsi/gomega"
"k8s.io/utils/pointer"
)

func TestGetProviderToken(t *testing.T) {
Expand Down Expand Up @@ -67,7 +66,8 @@ func TestGetProviderToken(t *testing.T) {
g := NewWithT(t)
provider := NewProvider(tt.opts...)
provider.credential = tt.tokenCred
ctx := context.WithValue(context.TODO(), "scope", pointer.String(""))
str := ""
ctx := context.WithValue(context.TODO(), "scope", &str)
token, err := provider.GetToken(ctx)

if tt.wantErr != nil {
Expand Down
1 change: 0 additions & 1 deletion auth/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.12.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0
github.com/onsi/gomega v1.33.1
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
)

require (
Expand Down
2 changes: 0 additions & 2 deletions auth/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,3 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak=
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
7 changes: 5 additions & 2 deletions git/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import (
"fmt"
"time"

"github.com/fluxcd/pkg/auth"
"github.com/fluxcd/pkg/auth/azure"
)

const (
ProviderAzure = "azure"
)

// Credentials contains authentication data needed in order to access a Git
// repository.
type Credentials struct {
Expand All @@ -39,7 +42,7 @@ func GetCredentials(ctx context.Context, url string, providerOpts *ProviderOptio
expiresOn time.Time
)
switch providerOpts.Name {
case auth.ProviderAzure:
case ProviderAzure:
opts := providerOpts.AzureOpts
if providerOpts.AzureOpts == nil {
opts = []azure.ProviderOptFunc{
Expand Down
9 changes: 4 additions & 5 deletions git/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
"github.com/fluxcd/pkg/auth"
"github.com/fluxcd/pkg/auth/azure"
. "github.com/onsi/gomega"
"k8s.io/utils/pointer"
)

func TestGetCredentials(t *testing.T) {
Expand All @@ -41,7 +39,7 @@ func TestGetCredentials(t *testing.T) {
name: "get credentials from azure",
url: "https://dev.azure.com/foo/bar/_git/baz",
provider: &ProviderOptions{
Name: auth.ProviderAzure,
Name: ProviderAzure,
AzureOpts: []azure.ProviderOptFunc{
azure.WithCredential(&azure.FakeTokenCredential{
Token: "ado-token",
Expand All @@ -59,7 +57,7 @@ func TestGetCredentials(t *testing.T) {
name: "get credentials from azure without scope",
url: "https://dev.azure.com/foo/bar/_git/baz",
provider: &ProviderOptions{
Name: auth.ProviderAzure,
Name: ProviderAzure,
AzureOpts: []azure.ProviderOptFunc{
azure.WithCredential(&azure.FakeTokenCredential{
Token: "ado-token",
Expand All @@ -85,7 +83,8 @@ func TestGetCredentials(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)
ctx := context.WithValue(context.TODO(), "scope", pointer.String(""))
str := ""
ctx := context.WithValue(context.TODO(), "scope", &str)
creds, expiry, err := GetCredentials(ctx, tt.url, tt.provider)

if tt.wantCredentials != nil {
Expand Down
2 changes: 1 addition & 1 deletion git/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/fluxcd/pkg/auth v0.0.0-00010101000000-000000000000
github.com/fluxcd/pkg/cache v0.0.3
github.com/onsi/gomega v1.34.1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
)

require (
Expand Down Expand Up @@ -76,6 +75,7 @@ require (
k8s.io/client-go v0.31.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.17.3 // indirect
sigs.k8s.io/kustomize/kyaml v0.17.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions git/gogit/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
"github.com/go-git/go-git/v5/storage"
"github.com/go-git/go-git/v5/storage/filesystem"
"github.com/go-git/go-git/v5/storage/memory"
"sigs.k8s.io/controller-runtime/pkg/log"
"github.com/go-logr/logr"
)

func init() {
Expand Down Expand Up @@ -257,8 +257,8 @@ func (g *Client) Clone(ctx context.Context, url string, cfg repository.CloneConf
err error
)

log := log.FromContext(ctx)
if g.authOpts != nil && g.authOpts.ProviderOpts != nil && g.authOpts.BearerToken == "" {
log := logr.FromContextOrDiscard(ctx)
if g.authOpts.Cache != nil {
cachedCreds, exists, err := getObjectFromCache(g.authOpts.Cache, url)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions git/gogit/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ require (
github.com/fluxcd/pkg/version v0.4.0
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.12.0
github.com/go-logr/logr v1.4.2
github.com/onsi/gomega v1.34.1
golang.org/x/crypto v0.26.0
sigs.k8s.io/controller-runtime v0.19.0
)

require (
Expand All @@ -50,7 +50,6 @@ require (
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
Expand Down
2 changes: 0 additions & 2 deletions git/gogit/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,6 @@ k8s.io/kubectl v0.31.0 h1:kANwAAPVY02r4U4jARP/C+Q1sssCcN/1p9Nk+7BQKVg=
k8s.io/kubectl v0.31.0/go.mod h1:pB47hhFypGsaHAPjlwrNbvhXgmuAr01ZBvAIIUaI8d4=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q=
sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/kustomize/api v0.17.3 h1:6GCuHSsxq7fN5yhF2XrC+AAr8gxQwhexgHflOAD/JJU=
Expand Down
2 changes: 1 addition & 1 deletion git/internal/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ require (
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.20.0 // indirect
Expand All @@ -118,7 +119,6 @@ require (
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/controller-runtime v0.19.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.17.3 // indirect
sigs.k8s.io/kustomize/kyaml v0.17.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions git/internal/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,6 @@ k8s.io/kubectl v0.31.0 h1:kANwAAPVY02r4U4jARP/C+Q1sssCcN/1p9Nk+7BQKVg=
k8s.io/kubectl v0.31.0/go.mod h1:pB47hhFypGsaHAPjlwrNbvhXgmuAr01ZBvAIIUaI8d4=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q=
sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/kustomize/api v0.17.3 h1:6GCuHSsxq7fN5yhF2XrC+AAr8gxQwhexgHflOAD/JJU=
Expand Down

0 comments on commit a2f84e1

Please sign in to comment.