/
charm.go
99 lines (82 loc) · 2.44 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
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
// Package charm is is a wrapper for the parts of
// github.com/juju/charm/v8 used by the charmstore. This version maintains
// the url parsing bahaviour expected by the charmstore.
package charm
import (
"io"
stdurl "net/url"
"github.com/juju/charm/v8"
)
// Copied constants.
const (
ScopeGlobal = charm.ScopeGlobal
)
// Alias all necessary types
type Actions = charm.Actions
type ApplicationSpec = charm.ApplicationSpec
type Bundle = charm.Bundle
type BundleArchive = charm.BundleArchive
type BundleData = charm.BundleData
type Charm = charm.Charm
type CharmArchive = charm.CharmArchive
type CharmDir = charm.CharmDir
type Config = charm.Config
type MachineSpec = charm.MachineSpec
type Meta = charm.Meta
type Metric = charm.Metric
type Metrics = charm.Metrics
type Relation = charm.Relation
type URL = charm.URL
type UnitPlacement = charm.UnitPlacement
type VerificationError = charm.VerificationError
// Unmodified functions
func ReadBundle(path string) (Bundle, error) {
return charm.ReadBundle(path)
}
func ReadBundleArchive(path string) (*BundleArchive, error) {
return charm.ReadBundleArchive(path)
}
func ReadBundleArchiveBytes(data []byte) (*BundleArchive, error) {
return charm.ReadBundleArchiveBytes(data)
}
func ReadBundleArchiveFromReader(r io.ReaderAt, size int64) (*BundleArchive, error) {
return charm.ReadBundleArchiveFromReader(r, size)
}
func ReadCharmArchiveBytes(data []byte) (*CharmArchive, error) {
return charm.ReadCharmArchiveBytes(data)
}
func ReadCharmArchiveFromReader(r io.ReaderAt, size int64) (*CharmArchive, error) {
return charm.ReadCharmArchiveFromReader(r, size)
}
func ReadCharmDir(path string) (*CharmDir, error) {
return charm.ReadCharmDir(path)
}
func ReadMeta(r io.Reader) (*Meta, error) {
return charm.ReadMeta(r)
}
func ParsePlacement(p string) (*UnitPlacement, error) {
return charm.ParsePlacement(p)
}
// MustParseURL parses the given URL, it panics is the URL cannot be
// parsed.
func MustParseURL(s string) *URL {
u, err := ParseURL(s)
if err != nil {
panic(err)
}
return u
}
// ParseURL parses the given string as
func ParseURL(s string) (*URL, error) {
if u, err := stdurl.Parse(s); err == nil {
// Ignore any actual error parsing the URL, the library parse
// function will report those.
if u.Scheme == "" {
// If there is no other scheme then assume "cs"
s = "cs:" + s
}
}
return charm.ParseURL(s)
}