forked from juju/charm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharm.go
60 lines (53 loc) · 1.38 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
// Copyright 2011, 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package charm
import (
"errors"
"fmt"
"os"
"github.com/juju/loggo"
)
var logger = loggo.GetLogger("juju.charm")
// The Charm interface is implemented by any type that
// may be handled as a charm.
type Charm interface {
Meta() *Meta
Config() *Config
Metrics() *Metrics
Actions() *Actions
Revision() int
}
// ReadCharm reads a Charm from path, which can point to either a charm archive or a
// charm directory.
func ReadCharm(path string) (charm Charm, err error) {
info, err := os.Stat(path)
if err != nil {
return nil, err
}
if info.IsDir() {
charm, err = ReadCharmDir(path)
} else {
charm, err = ReadCharmArchive(path)
}
if err != nil {
return nil, err
}
return charm, nil
}
// InferRepository returns a charm repository inferred from the provided charm
// or bundle reference. Local references will use the provided path.
func InferRepository(ref *Reference, localRepoPath string) (repo Repository, err error) {
switch ref.Schema {
case "cs":
repo = Store
case "local":
if localRepoPath == "" {
return nil, errors.New("path to local repository not specified")
}
repo = &LocalRepository{Path: localRepoPath}
default:
// TODO fix this error message to reference bundles too?
return nil, fmt.Errorf("unknown schema for charm reference %q", ref)
}
return
}