Merge branch 'master' into master

This commit is contained in:
Roman Vynar 2018-07-04 16:47:07 +03:00 committed by GitHub
commit 4047019a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 8 deletions

View File

@ -1,5 +1,10 @@
## Changelog
### Unreleased
* When using MySQL for event storage, do not leak connections.
* Last events were not shown when viewing a repo of non-default namespace.
### 0.6
* Add MySQL along with sqlite3 support as a registry events storage.

View File

@ -144,13 +144,13 @@ func (e *EventListener) GetEvents(repository string) []EventRow {
e.logger.Error("Error selecting from table: ", err)
return events
}
defer rows.Close()
for rows.Next() {
var row EventRow
rows.Scan(&row.ID, &row.Action, &row.Repository, &row.Tag, &row.IP, &row.User, &row.Created)
events = append(events, row)
}
rows.Close()
return events
}
@ -171,9 +171,11 @@ func (e *EventListener) getDababaseHandler() (*sql.DB, error) {
if e.databaseDriver == "mysql" {
schema = strings.Replace(schema, "AUTOINCREMENT", "AUTO_INCREMENT", 1)
if _, err := db.Query("SELECT * FROM events LIMIT 1"); err != nil {
rows, err := db.Query("SELECT * FROM events LIMIT 1")
if err != nil {
firstRun = true
}
rows.Close()
}
// Create table on first run.

13
main.go
View File

@ -133,6 +133,17 @@ func main() {
}
return res
})
view.AddGlobal("url_encoded_path", func(m interface{}) string {
return url.PathEscape(m.(string))
})
view.AddGlobal("url_decoded_path", func(m interface{}) string {
res, err := url.PathUnescape(m.(string))
if err != nil {
return m.(string)
}
return res
})
e := echo.New()
e.Renderer = &template{View: view}
@ -206,7 +217,7 @@ func (a *apiClient) viewTags(c echo.Context) error {
data.Set("repo", repo)
data.Set("tags", tags)
data.Set("deleteAllowed", deleteAllowed)
data.Set("events", a.eventListener.GetEvents(repo))
data.Set("events", a.eventListener.GetEvents(repoPath))
return c.Render(http.StatusOK, "tags.html", data)
}

View File

@ -69,7 +69,7 @@ func NewClient(url string, verifyTLS bool, username, password string) *Client {
c.logger.Warn("No token auth service discovered from ", c.url)
return nil
}
} else if strings.HasPrefix(authHeader, "Basic") {
} else if strings.HasPrefix(strings.ToLower(authHeader), strings.ToLower("Basic")) {
c.request = c.request.SetBasicAuth(c.username, c.password)
c.logger.Info("It was discovered the registry is configured with HTTP basic auth.")
}

View File

@ -25,12 +25,16 @@
{{block body()}}
<div style="float: right">
<select id="namespace" class="form-control input-sm" style="height: 36px">
<option value="" disabled>-- Namespace --</option>
{{range namespace := namespaces}}
<option value="{{ namespace }}">{{ namespace }}</option>
{{end}}
</select>
</div>
<div style="float: right">
<ol class="breadcrumb">
<li class="active">Namespace</li>
</ol>
</div>
<ol class="breadcrumb">
<li><a href="{{ base_path }}/">Home</a></li>
@ -46,7 +50,7 @@
<tbody>
{{range repo := repos}}
<tr>
<td><a href="{{ base_path }}/{{ namespace }}/{{ repo }}">{{ repo }}</a></td>
<td><a href="{{ base_path }}/{{ namespace }}/{{ repo|url_encoded_path }}">{{ repo }}</a></td>
<td>{{ tagCounts[namespace+"/"+repo] }}</td>
</tr>
{{end}}

View File

@ -8,7 +8,7 @@
{{if namespace != "library"}}
<li><a href="{{ base_path }}/{{ namespace }}">{{ namespace }}</a></li>
{{end}}
<li><a href="{{ base_path }}/{{ namespace }}/{{ repo }}">{{ repo }}</a></li>
<li><a href="{{ base_path }}/{{ namespace }}/{{ repo|url_decoded_path }}">{{ repo }}</a></li>
<li class="active">{{ tag }}</li>
</ol>
<table class="table table-striped table-bordered">

View File

@ -33,7 +33,7 @@
{{if namespace != "library"}}
<li><a href="{{ base_path }}/{{ namespace }}">{{ namespace }}</a></li>
{{end}}
<li class="active">{{ repo }}</li>
<li class="active">{{ repo |url_decoded_path }}</li>
</ol>
<table id="datatable" class="table table-striped table-bordered">