-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharm.go
86 lines (70 loc) · 1.92 KB
/
charm.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
79
80
81
82
83
84
85
86
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state
import (
"net/url"
"github.com/juju/charm"
)
// charmDoc represents the internal state of a charm in MongoDB.
type charmDoc struct {
URL *charm.URL `bson:"_id"`
Meta *charm.Meta
Config *charm.Config
Actions *charm.Actions
BundleURL *url.URL
BundleSha256 string
PendingUpload bool
Placeholder bool
}
// Charm represents the state of a charm in the environment.
type Charm struct {
st *State
doc charmDoc
}
func newCharm(st *State, cdoc *charmDoc) (*Charm, error) {
return &Charm{st: st, doc: *cdoc}, nil
}
func (c *Charm) String() string {
return c.doc.URL.String()
}
// URL returns the URL that identifies the charm.
func (c *Charm) URL() *charm.URL {
clone := *c.doc.URL
return &clone
}
// Revision returns the monotonically increasing charm
// revision number.
func (c *Charm) Revision() int {
return c.doc.URL.Revision
}
// Meta returns the metadata of the charm.
func (c *Charm) Meta() *charm.Meta {
return c.doc.Meta
}
// Config returns the configuration of the charm.
func (c *Charm) Config() *charm.Config {
return c.doc.Config
}
// Actions returns the actions definition of the charm.
func (c *Charm) Actions() *charm.Actions {
return c.doc.Actions
}
// BundleURL returns the url to the charm bundle in
// the provider storage.
func (c *Charm) BundleURL() *url.URL {
return c.doc.BundleURL
}
// BundleSha256 returns the SHA256 digest of the charm bundle bytes.
func (c *Charm) BundleSha256() string {
return c.doc.BundleSha256
}
// IsUploaded returns whether the charm has been uploaded to the
// provider storage.
func (c *Charm) IsUploaded() bool {
return !c.doc.PendingUpload
}
// IsPlaceholder returns whether the charm record is just a placeholder
// rather than representing a deployed charm.
func (c *Charm) IsPlaceholder() bool {
return c.doc.Placeholder
}