mirror of
https://github.com/storytold/irsa-manager.git
synced 2026-10-18 07:33:15 +00:00
refactor oidcMeta/fix irsa controller
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package selfhosted
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
|
||||
type OIDCIssuerMeta interface {
|
||||
IssuerHostPath() string
|
||||
IssuerUrl() string
|
||||
}
|
||||
"github.com/kkb0318/irsa-manager/internal/issuer"
|
||||
)
|
||||
|
||||
type OIDCIdP interface {
|
||||
Create(ctx context.Context) error
|
||||
@@ -27,8 +26,7 @@ type OIDCIdPDiscovery interface {
|
||||
}
|
||||
|
||||
type OIDCIdPFactory interface {
|
||||
IssuerMeta() OIDCIssuerMeta
|
||||
IdP(i OIDCIssuerMeta) (OIDCIdP, error)
|
||||
IdP(i issuer.OIDCIssuerMeta) (OIDCIdP, error)
|
||||
IdPDiscovery() OIDCIdPDiscovery
|
||||
IdPDiscoveryContents(i OIDCIssuerMeta) OIDCIdPDiscoveryContents
|
||||
IdPDiscoveryContents(i issuer.OIDCIssuerMeta) OIDCIdPDiscoveryContents
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
awsclient "github.com/kkb0318/irsa-manager/internal/aws"
|
||||
"github.com/kkb0318/irsa-manager/internal/issuer"
|
||||
"github.com/kkb0318/irsa-manager/internal/selfhosted"
|
||||
)
|
||||
|
||||
@@ -32,11 +33,7 @@ func NewAwsS3IdpFactory(
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *AwsS3IdPFactory) IssuerMeta() selfhosted.OIDCIssuerMeta {
|
||||
return NewS3IssuerMeta(f.region, f.bucketName)
|
||||
}
|
||||
|
||||
func (f *AwsS3IdPFactory) IdP(i selfhosted.OIDCIssuerMeta) (selfhosted.OIDCIdP, error) {
|
||||
func (f *AwsS3IdPFactory) IdP(i issuer.OIDCIssuerMeta) (selfhosted.OIDCIdP, error) {
|
||||
return NewAwsIdP(f.awsClient, i)
|
||||
}
|
||||
|
||||
@@ -44,6 +41,6 @@ func (f *AwsS3IdPFactory) IdPDiscovery() selfhosted.OIDCIdPDiscovery {
|
||||
return NewS3IdPDiscovery(f.awsClient, f.region, f.bucketName)
|
||||
}
|
||||
|
||||
func (f *AwsS3IdPFactory) IdPDiscoveryContents(i selfhosted.OIDCIssuerMeta) selfhosted.OIDCIdPDiscoveryContents {
|
||||
func (f *AwsS3IdPFactory) IdPDiscoveryContents(i issuer.OIDCIssuerMeta) selfhosted.OIDCIdPDiscoveryContents {
|
||||
return NewIdPDiscoveryContents(f.jwk, i, f.jwksFileName)
|
||||
}
|
||||
|
||||
@@ -4,16 +4,16 @@ import (
|
||||
"context"
|
||||
|
||||
awsclient "github.com/kkb0318/irsa-manager/internal/aws"
|
||||
"github.com/kkb0318/irsa-manager/internal/selfhosted"
|
||||
"github.com/kkb0318/irsa-manager/internal/issuer"
|
||||
)
|
||||
|
||||
type AwsIdP struct {
|
||||
iamClient *awsclient.AwsIamClient
|
||||
stsClient *awsclient.AwsStsClient
|
||||
issuerMeta selfhosted.OIDCIssuerMeta
|
||||
issuerMeta issuer.OIDCIssuerMeta
|
||||
}
|
||||
|
||||
func NewAwsIdP(awsConfig awsclient.AwsClient, issuerMeta selfhosted.OIDCIssuerMeta) (*AwsIdP, error) {
|
||||
func NewAwsIdP(awsConfig awsclient.AwsClient, issuerMeta issuer.OIDCIssuerMeta) (*AwsIdP, error) {
|
||||
iamClient := awsConfig.IamClient()
|
||||
stsClient := awsConfig.StsClient()
|
||||
return &AwsIdP{iamClient, stsClient, issuerMeta}, nil
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/kkb0318/irsa-manager/internal/issuer"
|
||||
"github.com/kkb0318/irsa-manager/internal/selfhosted"
|
||||
)
|
||||
|
||||
type IdPDiscoveryContents struct {
|
||||
jwk *selfhosted.JWK
|
||||
issuerMeta selfhosted.OIDCIssuerMeta
|
||||
issuerMeta issuer.OIDCIssuerMeta
|
||||
jwksFileName string
|
||||
}
|
||||
|
||||
@@ -23,7 +24,7 @@ type oidcDiscoveryConfiguration struct {
|
||||
ClaimsSupported []string `json:"claims_supported"`
|
||||
}
|
||||
|
||||
func NewIdPDiscoveryContents(jwk *selfhosted.JWK, issuerMeta selfhosted.OIDCIssuerMeta, jwksFileName string) *IdPDiscoveryContents {
|
||||
func NewIdPDiscoveryContents(jwk *selfhosted.JWK, issuerMeta issuer.OIDCIssuerMeta, jwksFileName string) *IdPDiscoveryContents {
|
||||
return &IdPDiscoveryContents{jwk, issuerMeta, jwksFileName}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package oidc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type IssuerMeta interface {
|
||||
IssuerHostPath() string
|
||||
IssuerUrl() string
|
||||
}
|
||||
|
||||
type S3IssuerMeta struct {
|
||||
region string
|
||||
bucketName string
|
||||
}
|
||||
|
||||
func NewS3IssuerMeta(region, bucketName string) *S3IssuerMeta {
|
||||
return &S3IssuerMeta{region, bucketName}
|
||||
}
|
||||
|
||||
func (i *S3IssuerMeta) IssuerHostPath() string {
|
||||
return fmt.Sprintf("s3-%s.amazonaws.com/%s", i.region, i.bucketName)
|
||||
}
|
||||
|
||||
// IssuerUrl constructs the URL path for the OIDC issuer based on the provided AWS region and bucket name.
|
||||
// This utility function generates the expected host path for accessing the OIDC configuration stored in an S3 bucket.
|
||||
func (i *S3IssuerMeta) IssuerUrl() string {
|
||||
return fmt.Sprintf("https://%s", i.
|
||||
IssuerHostPath())
|
||||
}
|
||||
@@ -2,10 +2,11 @@ package selfhosted
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/kkb0318/irsa-manager/internal/issuer"
|
||||
)
|
||||
|
||||
func Execute(ctx context.Context, idpComponentsFactory OIDCIdPFactory, forceUpdate bool) error {
|
||||
issuerMeta := idpComponentsFactory.IssuerMeta()
|
||||
func Execute(ctx context.Context, idpComponentsFactory OIDCIdPFactory, issuerMeta issuer.OIDCIssuerMeta, forceUpdate bool) error {
|
||||
discovery := idpComponentsFactory.IdPDiscovery()
|
||||
discoveryContents := idpComponentsFactory.IdPDiscoveryContents(issuerMeta)
|
||||
idp, err := idpComponentsFactory.IdP(issuerMeta)
|
||||
@@ -27,8 +28,7 @@ func Execute(ctx context.Context, idpComponentsFactory OIDCIdPFactory, forceUpda
|
||||
return nil
|
||||
}
|
||||
|
||||
func Delete(ctx context.Context, factory OIDCIdPFactory) error {
|
||||
issuerMeta := factory.IssuerMeta()
|
||||
func Delete(ctx context.Context, factory OIDCIdPFactory, issuerMeta issuer.OIDCIssuerMeta) error {
|
||||
discovery := factory.IdPDiscovery()
|
||||
discoveryContents := factory.IdPDiscoveryContents(issuerMeta)
|
||||
idp, err := factory.IdP(issuerMeta)
|
||||
|
||||
Reference in New Issue
Block a user