mirror of
https://github.com/storytold/irsa-manager.git
synced 2026-10-09 00:09:43 +00:00
factory rafactoring
This commit is contained in:
@@ -70,13 +70,23 @@ func reconcileSelfhosted(ctx context.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
factory, err := newOIDCIdpFactory(ctx, jwk)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = selfhosted.Execute(ctx, factory)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOIDCIdpFactory(ctx context.Context, jwk *selfhosted.JWK) (selfhosted.OIDCIdPFactory, error) {
|
||||||
// get from CRs
|
// get from CRs
|
||||||
region := "ap-northeast-1"
|
region := "ap-northeast-1"
|
||||||
bucketName := "my-bucket-name"
|
bucketName := "my-bucket-name"
|
||||||
jwksFileName := "keys.json"
|
jwksFileName := "keys.json"
|
||||||
var factory selfhosted.OIDCIdPFactory
|
factory, err := oidc.NewAwsS3IdpFactory(
|
||||||
|
|
||||||
factory, err = oidc.NewAwsS3IdpFactory(
|
|
||||||
ctx,
|
ctx,
|
||||||
region,
|
region,
|
||||||
bucketName,
|
bucketName,
|
||||||
@@ -84,28 +94,9 @@ func reconcileSelfhosted(ctx context.Context) error {
|
|||||||
jwksFileName,
|
jwksFileName,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
issuerMeta := factory.IssuerMeta()
|
return factory, nil
|
||||||
discovery := factory.IdPDiscovery()
|
|
||||||
discoveryContents := factory.IdPDiscoveryContents(issuerMeta)
|
|
||||||
idp, err := factory.IdP(issuerMeta)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = discovery.CreateStorage(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = discovery.Upload(ctx, discoveryContents)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = idp.Create(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupWithManager sets up the controller with the Manager.
|
// SetupWithManager sets up the controller with the Manager.
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package selfhosted
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
func Execute(ctx context.Context, factory OIDCIdPFactory) error {
|
||||||
|
issuerMeta := factory.IssuerMeta()
|
||||||
|
discovery := factory.IdPDiscovery()
|
||||||
|
discoveryContents := factory.IdPDiscoveryContents(issuerMeta)
|
||||||
|
idp, err := factory.IdP(issuerMeta)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = discovery.CreateStorage(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = discovery.Upload(ctx, discoveryContents)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = idp.Create(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user