Skip to content

Commit

Permalink
feat(userprefs): update documentation and list extensions endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
  • Loading branch information
laurentiuNiculae committed May 17, 2023
1 parent 2be5459 commit a9d16eb
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 46 deletions.
1 change: 1 addition & 0 deletions pkg/extensions/_zot.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Component | Endpoint | Description
--- | --- | ---
[`search`](search/search.md) | `/v2/_zot/ext/search` | efficient and enhanced registry search capabilities using graphQL backend
[`mgmt`](mgmt.md) | `/v2/_zot/ext/mgmt` | config management
[`userPrefs`](userprefs.md) | `/v2/_zot/ext/userprefs` | config management


# References
Expand Down
40 changes: 0 additions & 40 deletions pkg/extensions/extension_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

gqlHandler "github.com/99designs/gqlgen/graphql/handler"
"github.com/gorilla/mux"
distext "github.com/opencontainers/distribution-spec/specs-go/v1/extensions"

"zotregistry.io/zot/pkg/api/config"
"zotregistry.io/zot/pkg/api/constants"
Expand Down Expand Up @@ -199,42 +198,3 @@ func SearchACHeadersHandler() mux.MiddlewareFunc {
})
}
}

func getExtension(name, url, description string, endpoints []string) distext.Extension {
return distext.Extension{
Name: name,
URL: url,
Description: description,
Endpoints: endpoints,
}
}

func GetExtensions(config *config.Config) distext.ExtensionList {
extensionList := distext.ExtensionList{}

extensions := make([]distext.Extension, 0)

if config.Extensions != nil && config.Extensions.Search != nil {
endpoints := []string{constants.FullSearchPrefix}
searchExt := getExtension("_zot",
"https://github.com/project-zot/zot/blob/"+config.ReleaseTag+"/pkg/extensions/_zot.md",
"zot registry extensions",
endpoints)

extensions = append(extensions, searchExt)
}

if config.Extensions != nil && config.Extensions.Mgmt != nil {
endpoints := []string{constants.FullMgmtPrefix}
mgmtExt := getExtension("_zot",
"https://github.com/project-zot/zot/blob/"+config.ReleaseTag+"/pkg/extensions/_zot.md",
"zot registry extensions",
endpoints)

extensions = append(extensions, mgmtExt)
}

extensionList.Extensions = extensions

return extensionList
}
6 changes: 0 additions & 6 deletions pkg/extensions/extension_search_disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package extensions

import (
"github.com/gorilla/mux"
distext "github.com/opencontainers/distribution-spec/specs-go/v1/extensions"

"zotregistry.io/zot/pkg/api/config"
"zotregistry.io/zot/pkg/log"
Expand Down Expand Up @@ -37,8 +36,3 @@ func SetupSearchRoutes(config *config.Config, router *mux.Router, storeControlle
log.Warn().Msg("skipping setting up search routes because given zot binary doesn't include this feature," +
"please build a binary that does so")
}

// GetExtensions...
func GetExtensions(config *config.Config) distext.ExtensionList {
return distext.ExtensionList{}
}
53 changes: 53 additions & 0 deletions pkg/extensions/get_extensions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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{}

extensions := make([]distext.Extension, 0)

if config.Extensions != nil && config.Extensions.Search != nil {
endpoints := []string{constants.FullSearchPrefix}
searchExt := distext.Extension{
Name: "_zot",
URL: "https://github.com/project-zot/zot/blob/" + config.ReleaseTag + "/pkg/extensions/_zot.md",
Description: "zot registry extensions",
Endpoints: endpoints,
}

extensions = append(extensions, searchExt)

endpoints = []string{constants.FullUserPreferencesPrefix}

userPrefsExt := distext.Extension{
Name: "_zot",
URL: "https://github.com/project-zot/zot/blob/" + config.ReleaseTag + "/pkg/extensions/_zot.md",
Description: "zot registry extensions",
Endpoints: endpoints,
}

extensions = append(extensions, userPrefsExt)
}

if config.Extensions != nil && config.Extensions.Mgmt != nil {
endpoints := []string{constants.FullMgmtPrefix}
mgmtExt := distext.Extension{
Name: "_zot",
URL: "https://github.com/project-zot/zot/blob/" + config.ReleaseTag + "/pkg/extensions/_zot.md",
Description: "zot registry extensions",
Endpoints: endpoints,
}

extensions = append(extensions, mgmtExt)
}

extensionList.Extensions = extensions

return extensionList
}
31 changes: 31 additions & 0 deletions pkg/extensions/userprefs.md
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
```

0 comments on commit a9d16eb

Please sign in to comment.