force update if the selfhosted process ends midway

This commit is contained in:
kkb0318
2024-04-17 20:58:48 +09:00
parent f7208963ae
commit 78e97f2858
7 changed files with 83 additions and 44 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ type OIDCIdPDiscoveryContents interface {
type OIDCIdPDiscovery interface {
CreateStorage(ctx context.Context) error
Upload(ctx context.Context, o OIDCIdPDiscoveryContents) error
Upload(ctx context.Context, o OIDCIdPDiscoveryContents, forceUpdate bool) error
Delete(ctx context.Context, o OIDCIdPDiscoveryContents) error
}
@@ -32,30 +32,32 @@ func (s *S3IdPDiscovery) CreateStorage(ctx context.Context) error {
// Upload uploads the OIDC provider's discovery configuration and JSON Web Key Set (JWKS) to the specified AWS S3 bucket.
// This method is responsible for uploading the necessary OIDC configuration files to S3, making them accessible for OIDC clients.
func (s *S3IdPDiscovery) Upload(ctx context.Context, o selfhosted.OIDCIdPDiscoveryContents) error {
func (s *S3IdPDiscovery) Upload(ctx context.Context, o selfhosted.OIDCIdPDiscoveryContents, forceUpdate bool) error {
discovery, err := o.Discovery()
if err != nil {
return nil
}
err = s.s3Client.CreateObjectPublic(ctx,
CONFIGURATION_PATH,
discovery,
)
if err != nil {
return fmt.Errorf("unable to upload discovery document, %w", err)
}
// Uplaod JWK
jwk, err := o.JWK()
if err != nil {
return nil
}
err = s.s3Client.CreateObjectPublic(ctx,
o.JWKsFileName(),
jwk,
)
inputs := []client.ObjectInput{
{
Key: CONFIGURATION_PATH,
Body: discovery,
},
{
Key: o.JWKsFileName(),
Body: jwk,
},
}
if forceUpdate {
err = s.s3Client.PutObjectsPublic(ctx, inputs)
} else {
err = s.s3Client.CreateObjectsPublic(ctx, inputs)
}
if err != nil {
return fmt.Errorf("unable to upload JWK, %w", err)
return fmt.Errorf("unable to upload object, %w", err)
}
return nil
}
+2 -2
View File
@@ -2,7 +2,7 @@ package selfhosted
import "context"
func Execute(ctx context.Context, factory OIDCIdPFactory) error {
func Execute(ctx context.Context, factory OIDCIdPFactory, forceUpdate bool) error {
issuerMeta := factory.IssuerMeta()
discovery := factory.IdPDiscovery()
discoveryContents := factory.IdPDiscoveryContents(issuerMeta)
@@ -14,7 +14,7 @@ func Execute(ctx context.Context, factory OIDCIdPFactory) error {
if err != nil {
return err
}
err = discovery.Upload(ctx, discoveryContents)
err = discovery.Upload(ctx, discoveryContents, forceUpdate)
if err != nil {
return err
}