Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
685e730b
Commit
685e730b
authored
Jan 09, 2017
by
Anton Galitsyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create repo.Getter interface
parent
8a1d43ec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
10 deletions
+21
-10
chart_downloader.go
cmd/helm/downloader/chart_downloader.go
+8
-9
chartrepo.go
pkg/repo/chartrepo.go
+13
-1
No files found.
cmd/helm/downloader/chart_downloader.go
View file @
685e730b
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"net/http"
"net/url"
"net/url"
"os"
"os"
"path/filepath"
"path/filepath"
...
@@ -76,12 +75,12 @@ type ChartDownloader struct {
...
@@ -76,12 +75,12 @@ type ChartDownloader struct {
// Returns a string path to the location where the file was downloaded and a verification
// Returns a string path to the location where the file was downloaded and a verification
// (if provenance was verified), or an error if something bad happened.
// (if provenance was verified), or an error if something bad happened.
func
(
c
*
ChartDownloader
)
DownloadTo
(
ref
,
version
,
dest
string
)
(
string
,
*
provenance
.
Verification
,
error
)
{
func
(
c
*
ChartDownloader
)
DownloadTo
(
ref
,
version
,
dest
string
)
(
string
,
*
provenance
.
Verification
,
error
)
{
u
,
client
,
err
:=
c
.
ResolveChartVersion
(
ref
,
version
)
u
,
r
,
err
:=
c
.
ResolveChartVersion
(
ref
,
version
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
data
,
err
:=
download
(
u
.
String
(),
client
)
data
,
err
:=
download
(
u
.
String
(),
r
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
...
@@ -95,7 +94,7 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
...
@@ -95,7 +94,7 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
// If provenance is requested, verify it.
// If provenance is requested, verify it.
ver
:=
&
provenance
.
Verification
{}
ver
:=
&
provenance
.
Verification
{}
if
c
.
Verify
>
VerifyNever
{
if
c
.
Verify
>
VerifyNever
{
body
,
err
:=
download
(
u
.
String
()
+
".prov"
,
client
)
body
,
err
:=
download
(
u
.
String
()
+
".prov"
,
r
)
if
err
!=
nil
{
if
err
!=
nil
{
if
c
.
Verify
==
VerifyAlways
{
if
c
.
Verify
==
VerifyAlways
{
return
destfile
,
ver
,
fmt
.
Errorf
(
"Failed to fetch provenance %q"
,
u
.
String
()
+
".prov"
)
return
destfile
,
ver
,
fmt
.
Errorf
(
"Failed to fetch provenance %q"
,
u
.
String
()
+
".prov"
)
...
@@ -131,7 +130,7 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
...
@@ -131,7 +130,7 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
// * If version is non-empty, this will return the URL for that version
// * If version is non-empty, this will return the URL for that version
// * If version is empty, this will return the URL for the latest version
// * If version is empty, this will return the URL for the latest version
// * If no version can be found, an error is returned
// * If no version can be found, an error is returned
func
(
c
*
ChartDownloader
)
ResolveChartVersion
(
ref
,
version
string
)
(
*
url
.
URL
,
*
http
.
Client
,
error
)
{
func
(
c
*
ChartDownloader
)
ResolveChartVersion
(
ref
,
version
string
)
(
*
url
.
URL
,
*
repo
.
ChartRepository
,
error
)
{
u
,
err
:=
url
.
Parse
(
ref
)
u
,
err
:=
url
.
Parse
(
ref
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"invalid chart URL format: %s"
,
ref
)
return
nil
,
nil
,
fmt
.
Errorf
(
"invalid chart URL format: %s"
,
ref
)
...
@@ -199,7 +198,7 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, *h
...
@@ -199,7 +198,7 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, *h
return
nil
,
nil
,
fmt
.
Errorf
(
"invalid chart URL format: %s"
,
ref
)
return
nil
,
nil
,
fmt
.
Errorf
(
"invalid chart URL format: %s"
,
ref
)
}
}
return
u
,
r
.
Client
,
nil
return
u
,
r
,
nil
}
}
// VerifyChart takes a path to a chart archive and a keyring, and verifies the chart.
// VerifyChart takes a path to a chart archive and a keyring, and verifies the chart.
...
@@ -228,11 +227,11 @@ func VerifyChart(path string, keyring string) (*provenance.Verification, error)
...
@@ -228,11 +227,11 @@ func VerifyChart(path string, keyring string) (*provenance.Verification, error)
return
sig
.
Verify
(
path
,
provfile
)
return
sig
.
Verify
(
path
,
provfile
)
}
}
// download performs a
HTTP Get using specified client
and returns the body.
// download performs a
Get from repo.Getter
and returns the body.
func
download
(
href
string
,
client
*
http
.
Client
)
(
*
bytes
.
Buffer
,
error
)
{
func
download
(
href
string
,
r
repo
.
Getter
)
(
*
bytes
.
Buffer
,
error
)
{
buf
:=
bytes
.
NewBuffer
(
nil
)
buf
:=
bytes
.
NewBuffer
(
nil
)
resp
,
err
:=
client
.
Get
(
href
)
resp
,
err
:=
r
.
Get
(
href
)
if
err
!=
nil
{
if
err
!=
nil
{
return
buf
,
err
return
buf
,
err
}
}
...
...
pkg/repo/chartrepo.go
View file @
685e730b
...
@@ -50,6 +50,10 @@ type ChartRepository struct {
...
@@ -50,6 +50,10 @@ type ChartRepository struct {
Client
*
http
.
Client
Client
*
http
.
Client
}
}
type
Getter
interface
{
Get
(
url
string
)
(
*
http
.
Response
,
error
)
}
// NewChartRepository constructs ChartRepository
// NewChartRepository constructs ChartRepository
func
NewChartRepository
(
cfg
*
ChartRepositoryConfig
)
(
*
ChartRepository
,
error
)
{
func
NewChartRepository
(
cfg
*
ChartRepositoryConfig
)
(
*
ChartRepository
,
error
)
{
var
client
*
http
.
Client
var
client
*
http
.
Client
...
@@ -82,6 +86,14 @@ func NewChartRepository(cfg *ChartRepositoryConfig) (*ChartRepository, error) {
...
@@ -82,6 +86,14 @@ func NewChartRepository(cfg *ChartRepositoryConfig) (*ChartRepository, error) {
},
nil
},
nil
}
}
func
(
r
*
ChartRepository
)
Get
(
url
string
)
(
*
http
.
Response
,
error
)
{
resp
,
err
:=
r
.
Client
.
Get
(
url
)
if
err
!=
nil
{
return
nil
,
err
}
return
resp
,
nil
}
// Load loads a directory of charts as if it were a repository.
// Load loads a directory of charts as if it were a repository.
//
//
// It requires the presence of an index.yaml file in the directory.
// It requires the presence of an index.yaml file in the directory.
...
@@ -119,7 +131,7 @@ func (r *ChartRepository) DownloadIndexFile() error {
...
@@ -119,7 +131,7 @@ func (r *ChartRepository) DownloadIndexFile() error {
var
indexURL
string
var
indexURL
string
indexURL
=
strings
.
TrimSuffix
(
r
.
Config
.
URL
,
"/"
)
+
"/index.yaml"
indexURL
=
strings
.
TrimSuffix
(
r
.
Config
.
URL
,
"/"
)
+
"/index.yaml"
resp
,
err
:=
r
.
Client
.
Get
(
indexURL
)
resp
,
err
:=
r
.
Get
(
indexURL
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment