-
Notifications
You must be signed in to change notification settings - Fork 85
/
converter.go
59 lines (51 loc) · 1.78 KB
/
converter.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
package onetimetoken
import (
"time"
"github.com/kyma-incubator/compass/components/director/internal/model"
"github.com/kyma-incubator/compass/components/director/pkg/graphql"
)
type converter struct {
legacyConnectorURL string
}
// NewConverter missing godoc
func NewConverter(legacyConnectorURL string) *converter {
return &converter{legacyConnectorURL}
}
// ToGraphQLForRuntime missing godoc
func (c converter) ToGraphQLForRuntime(model model.OneTimeToken) graphql.OneTimeTokenForRuntime {
return graphql.OneTimeTokenForRuntime{
TokenWithURL: graphql.TokenWithURL{
Token: model.Token,
ConnectorURL: model.ConnectorURL,
Used: model.Used,
ExpiresAt: timeToTimestampPtr(model.ExpiresAt),
CreatedAt: timeToTimestampPtr(model.CreatedAt),
UsedAt: timeToTimestampPtr(model.UsedAt),
Type: graphql.OneTimeTokenType(model.Type),
},
}
}
// ToGraphQLForApplication missing godoc
func (c converter) ToGraphQLForApplication(model model.OneTimeToken) (graphql.OneTimeTokenForApplication, error) {
urlWithToken, err := legacyConnectorURLWithToken(c.legacyConnectorURL, model.Token)
if err != nil {
return graphql.OneTimeTokenForApplication{}, err
}
return graphql.OneTimeTokenForApplication{
TokenWithURL: graphql.TokenWithURL{
Token: model.Token,
ConnectorURL: model.ConnectorURL,
Used: model.Used,
ExpiresAt: timeToTimestampPtr(model.ExpiresAt),
CreatedAt: timeToTimestampPtr(model.CreatedAt),
UsedAt: timeToTimestampPtr(model.UsedAt),
Type: graphql.OneTimeTokenType(model.Type),
ScenarioGroups: model.ScenarioGroups,
},
LegacyConnectorURL: urlWithToken,
}, nil
}
func timeToTimestampPtr(time time.Time) *graphql.Timestamp {
t := graphql.Timestamp(time)
return &t
}