-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(userprefs): update documentation and list extensions endpoint (#…
…1456) Signed-off-by: Laurentiu Niculae <[email protected]>
- Loading branch information
1 parent
970997f
commit 2b8479f
Showing
11 changed files
with
182 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package extensions | ||
|
||
import ( | ||
distext "github.com/opencontainers/distribution-spec/specs-go/v1/extensions" | ||
|
||
"zotregistry.io/zot/pkg/api/config" | ||
"zotregistry.io/zot/pkg/api/constants" | ||
) | ||
|
||
func GetExtensions(config *config.Config) distext.ExtensionList { | ||
extensionList := distext.ExtensionList{} | ||
|
||
endpoints := []string{} | ||
extensions := []distext.Extension{} | ||
|
||
if config.Extensions != nil && config.Extensions.Search != nil { | ||
if IsBuiltWithSearchExtension() { | ||
endpoints = append(endpoints, constants.FullSearchPrefix) | ||
} | ||
|
||
if IsBuiltWithUserPrefsExtension() { | ||
endpoints = append(endpoints, constants.FullUserPreferencesPrefix) | ||
} | ||
} | ||
|
||
if IsBuiltWithMGMTExtension() && config.Extensions != nil && config.Extensions.Mgmt != nil { | ||
endpoints = append(endpoints, constants.FullMgmtPrefix) | ||
} | ||
|
||
if len(endpoints) > 0 { | ||
extensions = append(extensions, distext.Extension{ | ||
Name: "_zot", | ||
URL: "https://github.com/project-zot/zot/blob/" + config.ReleaseTag + "/pkg/extensions/_zot.md", | ||
Description: "zot registry extensions", | ||
Endpoints: endpoints, | ||
}) | ||
} | ||
|
||
extensionList.Extensions = extensions | ||
|
||
return extensionList | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//go:build !search && !mgmt && !userprefs | ||
|
||
package extensions_test | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"testing" | ||
|
||
distext "github.com/opencontainers/distribution-spec/specs-go/v1/extensions" | ||
. "github.com/smartystreets/goconvey/convey" | ||
"gopkg.in/resty.v1" | ||
|
||
"zotregistry.io/zot/pkg/api" | ||
"zotregistry.io/zot/pkg/api/config" | ||
"zotregistry.io/zot/pkg/api/constants" | ||
extconf "zotregistry.io/zot/pkg/extensions/config" | ||
"zotregistry.io/zot/pkg/test" | ||
) | ||
|
||
func TestGetExensionsDisabled(t *testing.T) { | ||
Convey("start zot server with extensions but no extensions built", t, func(c C) { | ||
conf := config.New() | ||
port := test.GetFreePort() | ||
baseURL := test.GetBaseURL(port) | ||
|
||
conf.HTTP.Port = port | ||
|
||
defaultVal := true | ||
|
||
searchConfig := &extconf.SearchConfig{ | ||
BaseConfig: extconf.BaseConfig{Enable: &defaultVal}, | ||
} | ||
|
||
mgmtConfg := &extconf.MgmtConfig{ | ||
BaseConfig: extconf.BaseConfig{Enable: &defaultVal}, | ||
} | ||
|
||
conf.Extensions = &extconf.ExtensionConfig{ | ||
Search: searchConfig, | ||
Mgmt: mgmtConfg, | ||
} | ||
|
||
logFile, err := os.CreateTemp("", "zot-log*.txt") | ||
So(err, ShouldBeNil) | ||
conf.Log.Output = logFile.Name() | ||
defer os.Remove(logFile.Name()) // clean up | ||
|
||
ctlr := makeController(conf, t.TempDir(), "") | ||
|
||
cm := test.NewControllerManager(ctlr) | ||
cm.StartAndWait(port) | ||
defer cm.StopServer() | ||
|
||
var extensionList distext.ExtensionList | ||
|
||
resp, err := resty.R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix) | ||
So(err, ShouldBeNil) | ||
So(resp, ShouldNotBeNil) | ||
So(resp.StatusCode(), ShouldEqual, 200) | ||
err = json.Unmarshal(resp.Body(), &extensionList) | ||
So(err, ShouldBeNil) | ||
So(len(extensionList.Extensions), ShouldEqual, 0) | ||
}) | ||
} | ||
|
||
func makeController(conf *config.Config, dir string, copyTestDataDest string) *api.Controller { | ||
ctlr := api.NewController(conf) | ||
|
||
if copyTestDataDest != "" { | ||
test.CopyTestFiles(copyTestDataDest, dir) | ||
} | ||
ctlr.Config.Storage.RootDirectory = dir | ||
|
||
return ctlr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# `userprefs` | ||
|
||
`userprefs` component provides an endpoint for adding user preferences for repos. It is available only to authentificated users. Unauthentificated users will be denied access. | ||
|
||
| Supported queries | Input | Output | Description | | ||
| --- | --- | --- | --- | | ||
| [Toggle repo star](#toggle-repo-star) | None | None | Sets the repo starred property to true if it is false, and to false if it is true | | ||
| [Toggle repo bookmark](#toggle-repo-bookmark) | None | None | Sets the repo bookmarked property to true if it is false, and to false if it is true | | ||
|
||
## General usage | ||
The userprefs endpoint accepts as a query parameter what `action` to perform and then all other required parameters for the specified action. | ||
|
||
## Toggle repo star | ||
| Action | Parameter | Parameter Type | Parameter Description | | ||
| --- | --- | --- | --- | | ||
| toggleStar | repo | string | The repo name which should be starred | | ||
|
||
A request to togle a star on a repo would look like this: | ||
``` | ||
(PUT) http://localhost:8080/v2/_zot/ext/userprefs?action=toggleStar&repo=repoName | ||
``` | ||
|
||
## Toggle repo bookmark | ||
| Action | Parameter | Parameter Type | Parameter Description | | ||
| --- | --- | --- | --- | | ||
| toggleBookmark | repo | string | The repo name which should be bookmarked | | ||
|
||
A request to togle a bookmark on a repo would look like this: | ||
``` | ||
(PUT) http://localhost:8080/v2/_zot/ext/userprefs?action=toggleBookmark&repo=repoName | ||
``` |