Added seed code for caas-helm.
[ta/caas-helm.git] / src / chart-repo-handler / pkg / chartutil / load.go
1 // Copyright 2019 Nokia
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // tonyaw: refer to "kubernetes/helm/pkg/chartutil/load.go"
16 package chartutil
17
18 import (
19         "k8s.io/helm/pkg/proto/hapi/chart"
20
21         // tonyaw:
22         helm_chartutil "k8s.io/helm/pkg/chartutil"
23         "github.com/ncw/swift"
24 )
25
26 // Load takes a string name, tries to resolve it to a file or directory, and then loads it.
27 //
28 // This is the preferred way to load a chart. It will discover the chart encoding
29 // and hand off to the appropriate chart reader.
30 //
31 // If a .helmignore file is present, the directory loader will skip loading any files
32 // matching it. But .helmignore is not evaluated when reading out of an archive.
33 func Load(c *swift.Connection, container, name string) (*chart.Chart, error) {
34         // tonyaw.TBD: ignore dir case for now.
35         // fi, err := os.Stat(name)
36         // if err != nil {
37         //      return nil, err
38         // }
39         // if fi.IsDir() {
40         //      return LoadDir(name)
41         // }
42         return LoadFile(c, container, name)
43 }
44
45
46 // LoadFile loads from an archive file.
47 func LoadFile(c *swift.Connection, container, name string) (*chart.Chart, error) {
48         // tonyaw.TBD: ignore dir case for now.
49         // if fi, err := os.Stat(name); err != nil {
50         //      return nil, err
51         // } else if fi.IsDir() {
52         //      return nil, errors.New("cannot load a directory")
53         // }
54
55         object, _, err := c.ObjectOpen(container, name, false, nil)
56         if err != nil {
57                 return nil, err
58         }
59         defer object.Close()
60
61         return helm_chartutil.LoadArchive(object)
62 }
63
64
65 // LoadDir loads from a directory.
66 //
67 // This loads charts only from directories.
68 // tonyaw.TBD: do we still need "LoadDir" for swift?
69 func LoadDir(dir string) (*chart.Chart, error) {
70         return nil, nil
71 }