github.com/darkowlzz/helm@v2.5.1-0.20171213183701-6707fe0468d4+incompatible/pkg/helm/helmpath/helmhome.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 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 16 package helmpath 17 18 import ( 19 "fmt" 20 "os" 21 "path/filepath" 22 ) 23 24 // Home describes the location of a CLI configuration. 25 // 26 // This helper builds paths relative to a Helm Home directory. 27 type Home string 28 29 // String returns Home as a string. 30 // 31 // Implements fmt.Stringer. 32 func (h Home) String() string { 33 return os.ExpandEnv(string(h)) 34 } 35 36 // Path returns Home with elements appended. 37 func (h Home) Path(elem ...string) string { 38 p := []string{h.String()} 39 p = append(p, elem...) 40 return filepath.Join(p...) 41 } 42 43 // Repository returns the path to the local repository. 44 func (h Home) Repository() string { 45 return h.Path("repository") 46 } 47 48 // RepositoryFile returns the path to the repositories.yaml file. 49 func (h Home) RepositoryFile() string { 50 return h.Path("repository", "repositories.yaml") 51 } 52 53 // Cache returns the path to the local cache. 54 func (h Home) Cache() string { 55 return h.Path("repository", "cache") 56 } 57 58 // CacheIndex returns the path to an index for the given named repository. 59 func (h Home) CacheIndex(name string) string { 60 target := fmt.Sprintf("%s-index.yaml", name) 61 return h.Path("repository", "cache", target) 62 } 63 64 // Starters returns the path to the Helm starter packs. 65 func (h Home) Starters() string { 66 return h.Path("starters") 67 } 68 69 // LocalRepository returns the location to the local repo. 70 // 71 // The local repo is the one used by 'helm serve' 72 // 73 // If additional path elements are passed, they are appended to the returned path. 74 func (h Home) LocalRepository(elem ...string) string { 75 p := []string{"repository", "local"} 76 p = append(p, elem...) 77 return h.Path(p...) 78 } 79 80 // Plugins returns the path to the plugins directory. 81 func (h Home) Plugins() string { 82 return h.Path("plugins") 83 } 84 85 // Archive returns the path to download chart archives. 86 func (h Home) Archive() string { 87 return h.Path("cache", "archive") 88 } 89 90 // TLSCaCert returns the path to fetch the CA certificate. 91 func (h Home) TLSCaCert() string { 92 return h.Path("ca.pem") 93 } 94 95 // TLSCert returns the path to fetch the client certificate. 96 func (h Home) TLSCert() string { 97 return h.Path("cert.pem") 98 } 99 100 // TLSKey returns the path to fetch the client public key. 101 func (h Home) TLSKey() string { 102 return h.Path("key.pem") 103 }