forked from kyma-incubator/compass
/
ias_type.go
69 lines (57 loc) · 1.99 KB
/
ias_type.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package provisioning
import (
"time"
"github.com/kyma-incubator/compass/components/kyma-environment-broker/internal"
kebError "github.com/kyma-incubator/compass/components/kyma-environment-broker/internal/error"
"github.com/kyma-incubator/compass/components/kyma-environment-broker/internal/ias"
"github.com/sirupsen/logrus"
)
const (
setIASTypeTimeout = 10 * time.Minute
)
type IASType struct {
bundleBuilder ias.BundleBuilder
disabled bool
}
func NewIASType(builder ias.BundleBuilder, disabled bool) *IASType {
return &IASType{
bundleBuilder: builder,
disabled: disabled,
}
}
func (s *IASType) Disabled() bool {
return s.disabled
}
func (s *IASType) ConfigureType(operation internal.ProvisioningOperation, runtimeURL string, log logrus.FieldLogger) (time.Duration, error) {
if s.disabled {
return 0, nil
}
spb := s.bundleBuilder.NewBundle(operation.InstanceID)
err := spb.FetchServiceProviderData()
if err != nil {
return s.handleError(operation, err, log, "fetching ServiceProvider data failed")
}
log.Infof("Configure SSO Type for ServiceProvider with RuntimeURL: %s", runtimeURL)
err = spb.ConfigureServiceProviderType(runtimeURL)
if err != nil {
return s.handleError(operation, err, log, "setting SSO Type failed")
}
return 0, nil
}
func (s *IASType) handleError(operation internal.ProvisioningOperation, err error, log logrus.FieldLogger, msg string) (time.Duration, error) {
log.Errorf("%s: %s", msg, err)
switch {
case kebError.IsTemporaryError(err):
if time.Since(operation.UpdatedAt) > setIASTypeTimeout {
log.Errorf("setting IAS type has reached timeout: %s", err)
// operation will be marked as a success, RuntimeURL will not be set in IAS ServiceProvider application
return 0, nil
}
log.Errorf("setting IAS type cannot be realized", err)
return 10 * time.Second, nil
default:
log.Errorf("setting IAS type failed: %s", err)
// operation will be marked as a success, RuntimeURL will not be set in IAS ServiceProvider application
return 0, nil
}
}