/
ias_deregistration.go
49 lines (40 loc) · 1.62 KB
/
ias_deregistration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package deprovisioning
import (
"fmt"
"time"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/ias"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/process"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/storage"
"github.com/sirupsen/logrus"
)
type IASDeregistrationStep struct {
operationManager *process.OperationManager
bundleBuilder ias.BundleBuilder
}
func NewIASDeregistrationStep(os storage.Operations, bundleBuilder ias.BundleBuilder) *IASDeregistrationStep {
return &IASDeregistrationStep{
operationManager: process.NewOperationManager(os),
bundleBuilder: bundleBuilder,
}
}
func (s *IASDeregistrationStep) Name() string {
return "IAS_Deregistration"
}
func (s *IASDeregistrationStep) Run(operation internal.Operation, log logrus.FieldLogger) (internal.Operation, time.Duration, error) {
for spID := range ias.ServiceProviderInputs {
spb, err := s.bundleBuilder.NewBundle(operation.InstanceID, spID)
if err != nil {
log.Errorf("%s: %s", "Failed to create ServiceProvider Bundle", err)
return operation, 0, nil
}
log.Infof("Removing ServiceProvider %q from IAS", spb.ServiceProviderName())
err = spb.DeleteServiceProvider()
if err != nil {
msg := fmt.Sprintf("cannot delete ServiceProvider %s", spb.ServiceProviderName())
log.Errorf("%s: %s", msg, err)
return s.operationManager.RetryOperationWithoutFail(operation, s.Name(), msg, 5*time.Second, 5*time.Minute, log)
}
}
return operation, 0, nil
}