-
Notifications
You must be signed in to change notification settings - Fork 20
/
repository.go
78 lines (64 loc) · 1.65 KB
/
repository.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
70
71
72
73
74
75
76
77
78
package tosca_v2_0
import (
"sync"
urlpkg "github.com/tliron/kutil/url"
"github.com/tliron/puccini/tosca"
)
//
// Repository
//
// [TOSCA-v2.0] @ ?
// [TOSCA-Simple-Profile-YAML-v1.3] @ 3.6.6
// [TOSCA-Simple-Profile-YAML-v1.2] @ 3.6.6
// [TOSCA-Simple-Profile-YAML-v1.1] @ 3.5.5
// [TOSCA-Simple-Profile-YAML-v1.0] @ 3.5.5
//
type Repository struct {
*Entity `name:"repository"`
Name string `namespace:""`
Description *string `read:"description"`
URL *string `read:"url" require:""`
Credential *Value `read:"credential,Value"` // tosca:Credential
url urlpkg.URL
urlProblemReported bool
lock sync.Mutex
}
func NewRepository(context *tosca.Context) *Repository {
return &Repository{
Entity: NewEntity(context),
Name: context.Name,
}
}
// tosca.Reader signature
func ReadRepository(context *tosca.Context) tosca.EntityPtr {
self := NewRepository(context)
context.ValidateUnsupportedFields(context.ReadFields(self))
return self
}
// parser.Renderable interface
func (self *Repository) Render() {
logRender.Debugf("repository: %s", self.Name)
if self.Credential != nil {
self.Credential.RenderDataType("tosca:Credential")
}
}
func (self *Repository) GetURL() urlpkg.URL {
self.lock.Lock()
defer self.lock.Unlock()
if (self.url == nil) && (self.URL != nil) {
origin := self.Context.URL.Origin()
var err error
if self.url, err = urlpkg.NewURL(*self.URL, origin.Context()); err != nil {
// Avoid reporting more than once
if !self.urlProblemReported {
self.Context.ReportError(err)
self.urlProblemReported = true
}
}
}
return nil
}
//
// Repositories
//
type Repositories []*Repository