Skip to content

Commit

Permalink
Remove unused token/impersonation from accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Oct 8, 2024
1 parent c1a09b7 commit 177a83c
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 46 deletions.
3 changes: 1 addition & 2 deletions api/alerting/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
certclientfake "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned/fake"
alertModels "github.com/equinor/radix-api/api/alerting/models"
"github.com/equinor/radix-api/models"
radixmodels "github.com/equinor/radix-common/models"
operatoralert "github.com/equinor/radix-operator/pkg/apis/alert"
"github.com/equinor/radix-operator/pkg/apis/kube"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
Expand All @@ -34,7 +33,7 @@ func (s *HandlerTestSuite) SetupTest() {
kedaClient := kedafake.NewSimpleClientset()
secretProviderClient := secretproviderfake.NewSimpleClientset()
certClient := certclientfake.NewSimpleClientset()
s.accounts = models.NewAccounts(kubeClient, radixClient, kedaClient, secretProviderClient, nil, certClient, kubeClient, radixClient, kedaClient, secretProviderClient, nil, certClient, "", radixmodels.Impersonation{})
s.accounts = models.NewAccounts(kubeClient, radixClient, kedaClient, secretProviderClient, nil, certClient, kubeClient, radixClient, kedaClient, secretProviderClient, nil, certClient)
}

func TestHandlerTestSuite(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions api/environments/environment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/equinor/radix-api/api/utils"
authnmock "github.com/equinor/radix-api/api/utils/token/mock"
"github.com/equinor/radix-api/models"
radixmodels "github.com/equinor/radix-common/models"
radixhttp "github.com/equinor/radix-common/net/http"
radixutils "github.com/equinor/radix-common/utils"
"github.com/equinor/radix-common/utils/numbers"
Expand Down Expand Up @@ -2709,7 +2708,7 @@ func initHandler(client kubernetes.Interface,
secretproviderclient secretsstorevclient.Interface,
certClient certclient.Interface,
handlerConfig ...EnvironmentHandlerOptions) EnvironmentHandler {
accounts := models.NewAccounts(client, radixclient, kedaClient, secretproviderclient, nil, certClient, client, radixclient, kedaClient, secretproviderclient, nil, certClient, "", radixmodels.Impersonation{})
accounts := models.NewAccounts(client, radixclient, kedaClient, secretproviderclient, nil, certClient, client, radixclient, kedaClient, secretproviderclient, nil, certClient)
options := []EnvironmentHandlerOptions{WithAccounts(accounts)}
options = append(options, handlerConfig...)
return Init(options...)
Expand Down
3 changes: 1 addition & 2 deletions api/jobs/job_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
deploymentModels "github.com/equinor/radix-api/api/deployments/models"
jobModels "github.com/equinor/radix-api/api/jobs/models"
"github.com/equinor/radix-api/models"
radixmodels "github.com/equinor/radix-common/models"
radixutils "github.com/equinor/radix-common/utils"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/equinor/radix-operator/pkg/apis/utils"
Expand Down Expand Up @@ -75,7 +74,7 @@ func (s *JobHandlerTestSuite) SetupTest() {

func (s *JobHandlerTestSuite) setupTest() {
s.kubeClient, s.radixClient, s.kedaClient, s.secretProviderClient, s.certClient = s.getUtils()
accounts := models.NewAccounts(s.kubeClient, s.radixClient, s.kedaClient, s.secretProviderClient, nil, s.certClient, s.kubeClient, s.radixClient, s.kedaClient, s.secretProviderClient, nil, s.certClient, "", radixmodels.Impersonation{})
accounts := models.NewAccounts(s.kubeClient, s.radixClient, s.kedaClient, s.secretProviderClient, nil, s.certClient, s.kubeClient, s.radixClient, s.kedaClient, s.secretProviderClient, nil, s.certClient)
s.accounts = accounts
}

Expand Down
2 changes: 1 addition & 1 deletion api/middleware/auth/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type ctxUserKey struct{}
type ctxImpersonationKey struct{}

func CreateAuthenticationMiddleware(validator token.ValidatorInterface) negroni.HandlerFunc {
func NewAuthenticationMiddleware(validator token.ValidatorInterface) negroni.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
ctx := r.Context()
logger := log.Ctx(ctx)
Expand Down
2 changes: 1 addition & 1 deletion api/middleware/cors/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/rs/zerolog/log"
)

func CreateMiddleware(clusterName, radixDNSZone string) *cors.Cors {
func NewMiddleware(clusterName, radixDNSZone string) *cors.Cors {

corsOptions := cors.Options{
AllowedOrigins: []string{
Expand Down
6 changes: 3 additions & 3 deletions api/middleware/logger/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/urfave/negroni/v3"
)

func CreateZerologRequestLoggerMiddleware() negroni.HandlerFunc {
func NewZerologResponseLoggerMiddleware() negroni.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
m := httpsnoop.CaptureMetrics(next, w, r)

Expand All @@ -35,15 +35,15 @@ func CreateZerologRequestLoggerMiddleware() negroni.HandlerFunc {
}
}

func CreateZerologRequestIdMiddleware() negroni.HandlerFunc {
func NewZerologRequestIdMiddleware() negroni.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
logger := log.Ctx(r.Context()).With().Str("request_id", xid.New().String()).Logger()
r = r.WithContext(logger.WithContext(r.Context()))

next(w, r)
}
}
func CreateZerologRequestDetailsMiddleware() negroni.HandlerFunc {
func NewZerologRequestDetailsMiddleware() negroni.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
remoteIp, _, _ := net.SplitHostPort(r.RemoteAddr)
logger := log.Ctx(r.Context()).With().
Expand Down
2 changes: 1 addition & 1 deletion api/middleware/recovery/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/urfave/negroni/v3"
)

func CreateMiddleware() *negroni.Recovery {
func NewMiddleware() *negroni.Recovery {
rec := negroni.NewRecovery()
rec.PrintStack = false
rec.Logger = &log.Logger
Expand Down
12 changes: 6 additions & 6 deletions api/router/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func NewAPIHandler(clusterName string, validator token.ValidatorInterface, radix
serveMux.Handle("/api/", createApiRouter(kubeUtil, controllers))

n := negroni.New(
recovery.CreateMiddleware(),
logger.CreateZerologRequestIdMiddleware(),
cors.CreateMiddleware(clusterName, radixDNSZone),
logger.CreateZerologRequestDetailsMiddleware(),
auth.CreateAuthenticationMiddleware(validator),
logger.CreateZerologRequestLoggerMiddleware(),
recovery.NewMiddleware(),
logger.NewZerologRequestIdMiddleware(),
cors.NewMiddleware(clusterName, radixDNSZone),
logger.NewZerologRequestDetailsMiddleware(),
auth.NewAuthenticationMiddleware(validator),
logger.NewZerologResponseLoggerMiddleware(),
)
n.UseHandler(serveMux)

Expand Down
8 changes: 4 additions & 4 deletions api/router/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func NewMetricsHandler() http.Handler {
serveMux.Handle("GET /metrics", promhttp.Handler())

n := negroni.New(
recovery.CreateMiddleware(),
logger.CreateZerologRequestIdMiddleware(),
logger.CreateZerologRequestDetailsMiddleware(),
logger.CreateZerologRequestLoggerMiddleware(),
recovery.NewMiddleware(),
logger.NewZerologRequestIdMiddleware(),
logger.NewZerologRequestDetailsMiddleware(),
logger.NewZerologResponseLoggerMiddleware(),
)
n.UseHandler(serveMux)

Expand Down
16 changes: 1 addition & 15 deletions api/utils/radix_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,7 @@ func (handler *RadixMiddleware) handleAuthorization(w http.ResponseWriter, r *ht
inClusterClient, inClusterRadixClient, inClusterKedaClient, inClusterSecretProviderClient, inClusterTektonClient, inClusterCertManagerClient := handler.kubeUtil.GetServerKubernetesClient(restOptions...)
outClusterClient, outClusterRadixClient, outClusterKedaClient, outClusterSecretProviderClient, outClusterTektonClient, outClusterCertManagerClient := handler.kubeUtil.GetUserKubernetesClient(token, impersonation, restOptions...)

accounts := models.NewAccounts(
inClusterClient,
inClusterRadixClient,
inClusterKedaClient,
inClusterSecretProviderClient,
inClusterTektonClient,
inClusterCertManagerClient,
outClusterClient,
outClusterRadixClient,
outClusterKedaClient,
outClusterSecretProviderClient,
outClusterTektonClient,
outClusterCertManagerClient,
token,
impersonation)
accounts := models.NewAccounts(inClusterClient, inClusterRadixClient, inClusterKedaClient, inClusterSecretProviderClient, inClusterTektonClient, inClusterCertManagerClient, outClusterClient, outClusterRadixClient, outClusterKedaClient, outClusterSecretProviderClient, outClusterTektonClient, outClusterCertManagerClient)

// Check if registration of application exists for application-specific requests
if appName, exists := mux.Vars(r)["appName"]; exists {
Expand Down
10 changes: 1 addition & 9 deletions models/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import (
tektonclient "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"

certclient "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned"
radixmodels "github.com/equinor/radix-common/models"
radixclient "github.com/equinor/radix-operator/pkg/client/clientset/versioned"
"k8s.io/client-go/kubernetes"
secretProviderClient "sigs.k8s.io/secrets-store-csi-driver/pkg/client/clientset/versioned"
)

// NewAccounts creates a new Accounts struct
func NewAccounts(
inClusterClient kubernetes.Interface, inClusterRadixClient radixclient.Interface, inClusterKedaClient kedav2.Interface, inClusterSecretProviderClient secretProviderClient.Interface, inClusterTektonClient tektonclient.Interface, inClusterCertManagerClient certclient.Interface,
outClusterClient kubernetes.Interface, outClusterRadixClient radixclient.Interface, outClusterKedaClient kedav2.Interface, outClusterSecretProviderClient secretProviderClient.Interface, outClusterTektonClient tektonclient.Interface, outClusterCertManagerClient certclient.Interface,
token string, impersonation radixmodels.Impersonation) Accounts {
func NewAccounts(inClusterClient kubernetes.Interface, inClusterRadixClient radixclient.Interface, inClusterKedaClient kedav2.Interface, inClusterSecretProviderClient secretProviderClient.Interface, inClusterTektonClient tektonclient.Interface, inClusterCertManagerClient certclient.Interface, outClusterClient kubernetes.Interface, outClusterRadixClient radixclient.Interface, outClusterKedaClient kedav2.Interface, outClusterSecretProviderClient secretProviderClient.Interface, outClusterTektonClient tektonclient.Interface, outClusterCertManagerClient certclient.Interface) Accounts {

return Accounts{
UserAccount: Account{
Expand All @@ -34,8 +30,6 @@ func NewAccounts(
TektonClient: inClusterTektonClient,
CertManagerClient: inClusterCertManagerClient,
},
token: token,
impersonation: impersonation,
}
}

Expand All @@ -54,6 +48,4 @@ func NewServiceAccount(inClusterClient kubernetes.Interface, inClusterRadixClien
type Accounts struct {
UserAccount Account
ServiceAccount Account
token string
impersonation radixmodels.Impersonation
}

0 comments on commit 177a83c

Please sign in to comment.