From 53ed43d9043350c96fcb34a41b87075e89b5eca8 Mon Sep 17 00:00:00 2001 From: Peter Grzybowski Date: Thu, 7 Nov 2024 17:39:41 +0100 Subject: [PATCH] chore(deviceauth): moving tenantadm client to pkg Changelog: None Ticket: MEN-7715 Signed-off-by: Peter Grzybowski --- .../client => pkg}/tenant/client_tenantadm.go | 2 +- .../tenant/client_tenantadm_test.go | 2 +- .../tenant/mocks/ClientRunner.go | 34 +++++++++---------- .../client => pkg}/tenant/tenant.go | 2 +- .../deviceauth/api/http/api_devauth_test.go | 2 +- backend/services/deviceauth/cmd/commands.go | 2 +- .../services/deviceauth/cmd/commands_test.go | 4 +-- .../services/deviceauth/devauth/devauth.go | 18 +++++----- .../deviceauth/devauth/devauth_test.go | 4 +-- backend/services/deviceauth/main.go | 2 +- backend/services/deviceauth/server.go | 2 +- 11 files changed, 37 insertions(+), 37 deletions(-) rename backend/{services/deviceauth/client => pkg}/tenant/client_tenantadm.go (99%) rename backend/{services/deviceauth/client => pkg}/tenant/client_tenantadm_test.go (99%) rename backend/{services/deviceauth/client => pkg}/tenant/mocks/ClientRunner.go (84%) rename backend/{services/deviceauth/client => pkg}/tenant/tenant.go (97%) diff --git a/backend/services/deviceauth/client/tenant/client_tenantadm.go b/backend/pkg/tenant/client_tenantadm.go similarity index 99% rename from backend/services/deviceauth/client/tenant/client_tenantadm.go rename to backend/pkg/tenant/client_tenantadm.go index 5b6e4fec..f9fbd904 100644 --- a/backend/services/deviceauth/client/tenant/client_tenantadm.go +++ b/backend/pkg/tenant/client_tenantadm.go @@ -1,4 +1,4 @@ -// Copyright 2023 Northern.tech AS +// Copyright 2024 Northern.tech AS // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/services/deviceauth/client/tenant/client_tenantadm_test.go b/backend/pkg/tenant/client_tenantadm_test.go similarity index 99% rename from backend/services/deviceauth/client/tenant/client_tenantadm_test.go rename to backend/pkg/tenant/client_tenantadm_test.go index bc425b11..e32cbda2 100644 --- a/backend/services/deviceauth/client/tenant/client_tenantadm_test.go +++ b/backend/pkg/tenant/client_tenantadm_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Northern.tech AS +// Copyright 2024 Northern.tech AS // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/services/deviceauth/client/tenant/mocks/ClientRunner.go b/backend/pkg/tenant/mocks/ClientRunner.go similarity index 84% rename from backend/services/deviceauth/client/tenant/mocks/ClientRunner.go rename to backend/pkg/tenant/mocks/ClientRunner.go index 36e74571..8024ec1e 100644 --- a/backend/services/deviceauth/client/tenant/mocks/ClientRunner.go +++ b/backend/pkg/tenant/mocks/ClientRunner.go @@ -1,4 +1,4 @@ -// Copyright 2023 Northern.tech AS +// Copyright 2024 Northern.tech AS // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ package mocks import ( context "context" + tenant2 "github.com/mendersoftware/mender-server/pkg/tenant" - tenant "github.com/mendersoftware/mender-server/services/deviceauth/client/tenant" mock "github.com/stretchr/testify/mock" ) @@ -47,23 +47,23 @@ func (_m *ClientRunner) CheckHealth(ctx context.Context) error { } // GetTenant provides a mock function with given fields: ctx, tid -func (_m *ClientRunner) GetTenant(ctx context.Context, tid string) (*tenant.Tenant, error) { +func (_m *ClientRunner) GetTenant(ctx context.Context, tid string) (*tenant2.Tenant, error) { ret := _m.Called(ctx, tid) if len(ret) == 0 { panic("no return value specified for GetTenant") } - var r0 *tenant.Tenant + var r0 *tenant2.Tenant var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) (*tenant.Tenant, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) (*tenant2.Tenant, error)); ok { return rf(ctx, tid) } - if rf, ok := ret.Get(0).(func(context.Context, string) *tenant.Tenant); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) *tenant2.Tenant); ok { r0 = rf(ctx, tid) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*tenant.Tenant) + r0 = ret.Get(0).(*tenant2.Tenant) } } @@ -77,23 +77,23 @@ func (_m *ClientRunner) GetTenant(ctx context.Context, tid string) (*tenant.Tena } // GetTenantUsers provides a mock function with given fields: ctx, tenantID -func (_m *ClientRunner) GetTenantUsers(ctx context.Context, tenantID string) ([]tenant.User, error) { +func (_m *ClientRunner) GetTenantUsers(ctx context.Context, tenantID string) ([]tenant2.User, error) { ret := _m.Called(ctx, tenantID) if len(ret) == 0 { panic("no return value specified for GetTenantUsers") } - var r0 []tenant.User + var r0 []tenant2.User var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) ([]tenant.User, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) ([]tenant2.User, error)); ok { return rf(ctx, tenantID) } - if rf, ok := ret.Get(0).(func(context.Context, string) []tenant.User); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) []tenant2.User); ok { r0 = rf(ctx, tenantID) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]tenant.User) + r0 = ret.Get(0).([]tenant2.User) } } @@ -107,23 +107,23 @@ func (_m *ClientRunner) GetTenantUsers(ctx context.Context, tenantID string) ([] } // VerifyToken provides a mock function with given fields: ctx, token -func (_m *ClientRunner) VerifyToken(ctx context.Context, token string) (*tenant.Tenant, error) { +func (_m *ClientRunner) VerifyToken(ctx context.Context, token string) (*tenant2.Tenant, error) { ret := _m.Called(ctx, token) if len(ret) == 0 { panic("no return value specified for VerifyToken") } - var r0 *tenant.Tenant + var r0 *tenant2.Tenant var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) (*tenant.Tenant, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) (*tenant2.Tenant, error)); ok { return rf(ctx, token) } - if rf, ok := ret.Get(0).(func(context.Context, string) *tenant.Tenant); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) *tenant2.Tenant); ok { r0 = rf(ctx, token) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*tenant.Tenant) + r0 = ret.Get(0).(*tenant2.Tenant) } } diff --git a/backend/services/deviceauth/client/tenant/tenant.go b/backend/pkg/tenant/tenant.go similarity index 97% rename from backend/services/deviceauth/client/tenant/tenant.go rename to backend/pkg/tenant/tenant.go index a8a680cd..88b02309 100644 --- a/backend/services/deviceauth/client/tenant/tenant.go +++ b/backend/pkg/tenant/tenant.go @@ -1,4 +1,4 @@ -// Copyright 2023 Northern.tech AS +// Copyright 2024 Northern.tech AS // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/services/deviceauth/api/http/api_devauth_test.go b/backend/services/deviceauth/api/http/api_devauth_test.go index 4cc9bebd..0c8d3a51 100644 --- a/backend/services/deviceauth/api/http/api_devauth_test.go +++ b/backend/services/deviceauth/api/http/api_devauth_test.go @@ -35,10 +35,10 @@ import ( "github.com/mendersoftware/mender-server/pkg/requestid" "github.com/mendersoftware/mender-server/pkg/rest_utils" + "github.com/mendersoftware/mender-server/pkg/tenant" mt "github.com/mendersoftware/mender-server/pkg/testing" "github.com/mendersoftware/mender-server/services/deviceauth/cache" - "github.com/mendersoftware/mender-server/services/deviceauth/client/tenant" "github.com/mendersoftware/mender-server/services/deviceauth/devauth" "github.com/mendersoftware/mender-server/services/deviceauth/devauth/mocks" "github.com/mendersoftware/mender-server/services/deviceauth/jwt" diff --git a/backend/services/deviceauth/cmd/commands.go b/backend/services/deviceauth/cmd/commands.go index 0607c800..4a582ae2 100644 --- a/backend/services/deviceauth/cmd/commands.go +++ b/backend/services/deviceauth/cmd/commands.go @@ -25,10 +25,10 @@ import ( "github.com/mendersoftware/mender-server/pkg/log" "github.com/mendersoftware/mender-server/pkg/mongo/migrate" mstore "github.com/mendersoftware/mender-server/pkg/store" + "github.com/mendersoftware/mender-server/pkg/tenant" cinv "github.com/mendersoftware/mender-server/services/deviceauth/client/inventory" "github.com/mendersoftware/mender-server/services/deviceauth/client/orchestrator" - "github.com/mendersoftware/mender-server/services/deviceauth/client/tenant" dconfig "github.com/mendersoftware/mender-server/services/deviceauth/config" "github.com/mendersoftware/mender-server/services/deviceauth/model" "github.com/mendersoftware/mender-server/services/deviceauth/store" diff --git a/backend/services/deviceauth/cmd/commands_test.go b/backend/services/deviceauth/cmd/commands_test.go index 7214d3f8..b0aa3f0c 100644 --- a/backend/services/deviceauth/cmd/commands_test.go +++ b/backend/services/deviceauth/cmd/commands_test.go @@ -29,12 +29,12 @@ import ( "github.com/mendersoftware/mender-server/pkg/mongo/migrate" "github.com/mendersoftware/mender-server/pkg/mongo/oid" ctxstore "github.com/mendersoftware/mender-server/pkg/store" + "github.com/mendersoftware/mender-server/pkg/tenant" + mtenant "github.com/mendersoftware/mender-server/pkg/tenant/mocks" minv "github.com/mendersoftware/mender-server/services/deviceauth/client/inventory/mocks" "github.com/mendersoftware/mender-server/services/deviceauth/client/orchestrator" mwflows "github.com/mendersoftware/mender-server/services/deviceauth/client/orchestrator/mocks" - "github.com/mendersoftware/mender-server/services/deviceauth/client/tenant" - mtenant "github.com/mendersoftware/mender-server/services/deviceauth/client/tenant/mocks" "github.com/mendersoftware/mender-server/services/deviceauth/store" //dconfig "github.com/mendersoftware/mender-server/services/deviceauth/config" diff --git a/backend/services/deviceauth/devauth/devauth.go b/backend/services/deviceauth/devauth/devauth.go index a11f4be8..e2609962 100644 --- a/backend/services/deviceauth/devauth/devauth.go +++ b/backend/services/deviceauth/devauth/devauth.go @@ -30,12 +30,12 @@ import ( "github.com/mendersoftware/mender-server/pkg/plan" "github.com/mendersoftware/mender-server/pkg/ratelimits" "github.com/mendersoftware/mender-server/pkg/requestid" + tenant2 "github.com/mendersoftware/mender-server/pkg/tenant" "github.com/mendersoftware/mender-server/services/deviceauth/access" "github.com/mendersoftware/mender-server/services/deviceauth/cache" "github.com/mendersoftware/mender-server/services/deviceauth/client/inventory" "github.com/mendersoftware/mender-server/services/deviceauth/client/orchestrator" - "github.com/mendersoftware/mender-server/services/deviceauth/client/tenant" "github.com/mendersoftware/mender-server/services/deviceauth/jwt" "github.com/mendersoftware/mender-server/services/deviceauth/model" "github.com/mendersoftware/mender-server/services/deviceauth/store" @@ -118,7 +118,7 @@ type DevAuth struct { db store.DataStore invClient inventory.Client cOrch orchestrator.ClientRunner - cTenant tenant.ClientRunner + cTenant tenant2.ClientRunner jwt jwt.Handler jwtFallback jwt.Handler verifyTenant bool @@ -282,11 +282,11 @@ func (d *DevAuth) signToken(ctx context.Context) jwt.SignFunc { } } -func (d *DevAuth) doVerifyTenant(ctx context.Context, token string) (*tenant.Tenant, error) { +func (d *DevAuth) doVerifyTenant(ctx context.Context, token string) (*tenant2.Tenant, error) { t, err := d.cTenant.VerifyToken(ctx, token) if err != nil { - if tenant.IsErrTokenVerificationFailed(err) { + if tenant2.IsErrTokenVerificationFailed(err) { return nil, MakeErrDevAuthUnauthorized(err) } @@ -300,14 +300,14 @@ func (d *DevAuth) getTenantWithDefault( ctx context.Context, tenantToken, defaultToken string, -) (context.Context, *tenant.Tenant, error) { +) (context.Context, *tenant2.Tenant, error) { l := log.FromContext(ctx) if tenantToken == "" && defaultToken == "" { return nil, nil, MakeErrDevAuthUnauthorized(errors.New("tenant token missing")) } - var t *tenant.Tenant + var t *tenant2.Tenant var err error // try the provided token @@ -331,7 +331,7 @@ func (d *DevAuth) getTenantWithDefault( // none of the tokens worked if err != nil { - if tenant.IsErrTokenVerificationFailed(err) { + if tenant2.IsErrTokenVerificationFailed(err) { return ctx, nil, MakeErrDevAuthUnauthorized(err) } return ctx, nil, err @@ -348,7 +348,7 @@ func (d *DevAuth) getTenantWithDefault( func (d *DevAuth) SubmitAuthRequest(ctx context.Context, r *model.AuthReq) (string, error) { l := log.FromContext(ctx) - var tenant *tenant.Tenant + var tenant *tenant2.Tenant var err error if d.verifyTenant { @@ -1544,7 +1544,7 @@ func (d *DevAuth) WithJWTFallbackHandler(handler jwt.Handler) *DevAuth { // WithTenantVerification will force verification of tenant token with tenant // administrator when processing device authentication requests. Returns an // updated devauth. -func (d *DevAuth) WithTenantVerification(c tenant.ClientRunner) *DevAuth { +func (d *DevAuth) WithTenantVerification(c tenant2.ClientRunner) *DevAuth { d.cTenant = c d.verifyTenant = true return d diff --git a/backend/services/deviceauth/devauth/devauth_test.go b/backend/services/deviceauth/devauth/devauth_test.go index cad671bc..a62afd2e 100644 --- a/backend/services/deviceauth/devauth/devauth_test.go +++ b/backend/services/deviceauth/devauth/devauth_test.go @@ -28,6 +28,8 @@ import ( "github.com/mendersoftware/mender-server/pkg/identity" "github.com/mendersoftware/mender-server/pkg/mongo/oid" "github.com/mendersoftware/mender-server/pkg/ratelimits" + "github.com/mendersoftware/mender-server/pkg/tenant" + mtenant "github.com/mendersoftware/mender-server/pkg/tenant/mocks" "github.com/pkg/errors" @@ -36,8 +38,6 @@ import ( minv "github.com/mendersoftware/mender-server/services/deviceauth/client/inventory/mocks" "github.com/mendersoftware/mender-server/services/deviceauth/client/orchestrator" morchestrator "github.com/mendersoftware/mender-server/services/deviceauth/client/orchestrator/mocks" - "github.com/mendersoftware/mender-server/services/deviceauth/client/tenant" - mtenant "github.com/mendersoftware/mender-server/services/deviceauth/client/tenant/mocks" "github.com/mendersoftware/mender-server/services/deviceauth/jwt" mjwt "github.com/mendersoftware/mender-server/services/deviceauth/jwt/mocks" "github.com/mendersoftware/mender-server/services/deviceauth/model" diff --git a/backend/services/deviceauth/main.go b/backend/services/deviceauth/main.go index 8551e218..ffbfda09 100644 --- a/backend/services/deviceauth/main.go +++ b/backend/services/deviceauth/main.go @@ -26,11 +26,11 @@ import ( "github.com/mendersoftware/mender-server/pkg/config" "github.com/mendersoftware/mender-server/pkg/log" + "github.com/mendersoftware/mender-server/pkg/tenant" "github.com/mendersoftware/mender-server/pkg/version" cinv "github.com/mendersoftware/mender-server/services/deviceauth/client/inventory" "github.com/mendersoftware/mender-server/services/deviceauth/client/orchestrator" - "github.com/mendersoftware/mender-server/services/deviceauth/client/tenant" "github.com/mendersoftware/mender-server/services/deviceauth/cmd" dconfig "github.com/mendersoftware/mender-server/services/deviceauth/config" "github.com/mendersoftware/mender-server/services/deviceauth/store/mongo" diff --git a/backend/services/deviceauth/server.go b/backend/services/deviceauth/server.go index 3383d576..b1aabb0d 100644 --- a/backend/services/deviceauth/server.go +++ b/backend/services/deviceauth/server.go @@ -23,11 +23,11 @@ import ( "github.com/mendersoftware/mender-server/pkg/config" "github.com/mendersoftware/mender-server/pkg/log" + "github.com/mendersoftware/mender-server/pkg/tenant" api_http "github.com/mendersoftware/mender-server/services/deviceauth/api/http" "github.com/mendersoftware/mender-server/services/deviceauth/cache" "github.com/mendersoftware/mender-server/services/deviceauth/client/orchestrator" - "github.com/mendersoftware/mender-server/services/deviceauth/client/tenant" dconfig "github.com/mendersoftware/mender-server/services/deviceauth/config" "github.com/mendersoftware/mender-server/services/deviceauth/devauth" "github.com/mendersoftware/mender-server/services/deviceauth/jwt"