Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
chart-server
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruce Flynn
chart-server
Commits
19ea4701
Commit
19ea4701
authored
6 years ago
by
Bruce Flynn
Browse files
Options
Downloads
Patches
Plain Diff
use gorilla
parent
192c5a45
Branches
main
No related tags found
No related merge requests found
Pipeline
#4100
passed with stage
in 1 minute and 20 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Gopkg.lock
+19
-1
19 additions, 1 deletion
Gopkg.lock
Gopkg.toml
+4
-0
4 additions, 0 deletions
Gopkg.toml
main.go
+28
-26
28 additions, 26 deletions
main.go
with
51 additions
and
27 deletions
Gopkg.lock
+
19
−
1
View file @
19ea4701
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
name = "github.com/gorilla/context"
packages = ["."]
revision = "08b5f424b9271eedf6f9f0ce86cb9396ed337a42"
version = "v1.1.1"
[[projects]]
name = "github.com/gorilla/handlers"
packages = ["."]
revision = "7e0847f9db758cdebd26c149d0ae9d5d0b9c98ce"
version = "v1.4.0"
[[projects]]
name = "github.com/gorilla/mux"
packages = ["."]
revision = "e3702bed27f0d39777b0b37b664b6280e8ef8fbf"
version = "v1.6.2"
[[projects]]
name = "github.com/pkg/errors"
packages = ["."]
...
...
@@ -16,6 +34,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "
6a5cb0d32267ee88743a8972ec6d5c53e95e1e90a4711815b803c569c22340b
6"
inputs-digest = "
f6087c0b85729f6281d53f35c3d177780a29d49c74ea6dfde0a7ad376af7e25
6"
solver-name = "gps-cdcl"
solver-version = 1
This diff is collapsed.
Click to expand it.
Gopkg.toml
+
4
−
0
View file @
19ea4701
...
...
@@ -36,3 +36,7 @@
[prune]
go-tests
=
true
unused-packages
=
true
[[constraint]]
name
=
"github.com/gorilla/mux"
version
=
"1.6.2"
This diff is collapsed.
Click to expand it.
main.go
+
28
−
26
View file @
19ea4701
...
...
@@ -9,15 +9,12 @@ import (
"os/exec"
"path"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/spf13/pflag"
)
func
httpError
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
msg
string
,
code
int
)
{
log
.
Printf
(
"HttpError[%d %s]: %s"
,
code
,
msg
,
r
.
URL
)
http
.
Error
(
w
,
msg
,
code
)
}
func
httpFail
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
msg
string
,
err
error
)
{
log
.
Printf
(
"InternalServerError: %s: %s: %s"
,
msg
,
err
,
r
.
URL
)
http
.
Error
(
w
,
msg
,
http
.
StatusInternalServerError
)
...
...
@@ -38,12 +35,12 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
st
,
err
:=
os
.
Stat
(
p
)
// got an error and the file exists... something interesting perhaps?
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
httpError
(
w
,
r
,
"InternalServerError"
,
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
"InternalServerError"
,
http
.
StatusInternalServerError
)
return
}
// got a stat result, file must exist
if
st
!=
nil
{
httpError
(
w
,
r
,
"File exists"
,
http
.
StatusForbidden
)
http
.
Error
(
w
,
"File exists"
,
http
.
StatusForbidden
)
return
}
...
...
@@ -80,6 +77,20 @@ helm repo add <name> %s
</pre>
</code>
</p>
<h3>API</h3>
<dl>
<dt>GET /index.yaml</dt>
<dd>Get chart index file used by Helm</dd>
<dt>GET /<version>-<version>.tgz</dt>
<dd>Get a Heml chart package</dd>
<dt>GET /status</dt>
<dd>Health check that simply returns <code>OK!</code></dd>
</dl>
</div>
`
,
url
)))
}
...
...
@@ -88,7 +99,7 @@ func handleGetFile(w http.ResponseWriter, r *http.Request) {
p
:=
path
.
Join
(
dir
,
r
.
URL
.
Path
)
st
,
err
:=
os
.
Stat
(
p
)
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
||
st
!=
nil
&&
st
.
IsDir
()
{
httpError
(
w
,
r
,
"Not Found"
,
http
.
StatusNotFound
)
http
.
Error
(
w
,
"Not Found"
,
http
.
StatusNotFound
)
return
}
f
,
err
:=
os
.
Open
(
p
)
...
...
@@ -102,21 +113,6 @@ func handleGetFile(w http.ResponseWriter, r *http.Request) {
}
}
func
handle
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
switch
r
.
Method
{
case
"PUT"
:
handleUpload
(
w
,
r
)
case
"GET"
:
if
r
.
URL
.
Path
==
"/"
{
handleGetHome
(
w
,
r
)
}
else
{
handleGetFile
(
w
,
r
)
}
default
:
httpError
(
w
,
r
,
"Bad Request"
,
http
.
StatusBadRequest
)
}
}
func
handleStatus
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusOK
)
w
.
Write
([]
byte
(
"OK!
\n
"
))
...
...
@@ -173,9 +169,15 @@ Options can also be specified as environment variables $CHART_SVR_<name>
dir
=
path
.
Join
(
p
,
dir
)
}
http
.
HandleFunc
(
"/status"
,
handleStatus
)
http
.
HandleFunc
(
"/"
,
handle
)
r
:=
mux
.
NewRouter
()
r
.
HandleFunc
(
"/status"
,
handleStatus
)
.
Methods
(
"GET"
)
// Limit to only index.yaml and chart (.tgz) files
r
.
HandleFunc
(
`/{filename:(?:index.yaml|.*-.*.tgz)}`
,
handleGetFile
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
`/{chart:.*-.*\.tgz}`
,
handleUpload
)
.
Methods
(
"PUT"
)
r
.
HandleFunc
(
"/"
,
handleGetHome
)
h
:=
handlers
.
CombinedLoggingHandler
(
os
.
Stdout
,
handlers
.
CORS
()(
r
))
log
.
Printf
(
"serving charts from %s on %s"
,
dir
,
host
)
log
.
Fatal
(
http
.
ListenAndServe
(
host
,
nil
))
log
.
Fatal
(
http
.
ListenAndServe
(
host
,
h
))
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment