This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
named_entity.go
56 lines (51 loc) · 1.55 KB
/
named_entity.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
package transformers
import (
"github.com/flyteorg/flyteadmin/pkg/repositories/models"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
)
func CreateNamedEntityModel(request *admin.NamedEntityUpdateRequest) models.NamedEntity {
stateInt := int32(request.Metadata.State)
return models.NamedEntity{
NamedEntityKey: models.NamedEntityKey{
ResourceType: request.ResourceType,
Project: request.Id.Project,
Domain: request.Id.Domain,
Name: request.Id.Name,
},
NamedEntityMetadataFields: models.NamedEntityMetadataFields{
Description: request.Metadata.Description,
State: &stateInt,
},
}
}
func FromNamedEntityMetadataFields(metadata models.NamedEntityMetadataFields) admin.NamedEntityMetadata {
return admin.NamedEntityMetadata{
Description: metadata.Description,
}
}
func FromNamedEntityModel(model models.NamedEntity) admin.NamedEntity {
var entityState int32
if model.State != nil {
entityState = *model.State
}
return admin.NamedEntity{
ResourceType: model.ResourceType,
Id: &admin.NamedEntityIdentifier{
Project: model.Project,
Domain: model.Domain,
Name: model.Name,
},
Metadata: &admin.NamedEntityMetadata{
Description: model.Description,
State: admin.NamedEntityState(entityState),
},
}
}
func FromNamedEntityModels(models []models.NamedEntity) []*admin.NamedEntity {
namedEntities := make([]*admin.NamedEntity, len(models))
for idx, model := range models {
namedEntity := FromNamedEntityModel(model)
namedEntities[idx] = &namedEntity
}
return namedEntities
}