Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecated stacks filtering to registry-library #232

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions registry-library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ Supported devfile media types can be found in the latest version of [library.go]
HTTPTimeout: &customTimeout
}
```
7. Filter *only deprecated* Devfiles based on the [lifecycle process for the devfiles project](https://github.com/devfile/registry/blob/main/LIFECYCLE.md)
```go
options := registryLibrary.RegistryOptions{
Filter: registryLibrary.RegistryFilter{
Deprecated: registryLibrary.DeprecatedFilterTrue,
},
}
```
8. Filter *only non deprecated* Devfiles based on the [lifecycle process for the devfiles project](https://github.com/devfile/registry/blob/main/LIFECYCLE.md)
```go
options := registryLibrary.RegistryOptions{
Filter: registryLibrary.RegistryFilter{
Deprecated: registryLibrary.DeprecatedFilterFalse,
},
}
```

#### Download the starter project

Expand Down
31 changes: 22 additions & 9 deletions registry-library/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ const (
DevfilePNGLogoMediaType = "image/png"
DevfileArchiveMediaType = "application/x-tar"

OwnersFile = "OWNERS"
registryLibrary = "registry-library" //constant to indicate that function is called by the library
httpRequestResponseTimeout = 30 * time.Second // httpRequestTimeout configures timeout of all HTTP requests
OwnersFile = "OWNERS"
registryLibrary = "registry-library" //constant to indicate that function is called by the library
httpRequestResponseTimeout = 30 * time.Second // httpRequestTimeout configures timeout of all HTTP requests
DeprecatedFilterTrue DeprecatedFilter = "true"
DeprecatedFilterFalse DeprecatedFilter = "false"
)

var (
Expand All @@ -65,6 +67,9 @@ type Registry struct {
err error
}

// DeprecatedFilter to manage the deprecated filter values
type DeprecatedFilter string

// TelemetryData structure to pass in client telemetry information
// The User and Locale fields should be passed in by clients if telemetry opt-in is enabled
// the generic Client name will be passed in regardless of opt-in/out choice. The value
Expand Down Expand Up @@ -103,6 +108,10 @@ type RegistryFilter struct {
// only major version and minor version are required. e.g. 2.1, 2.2 ect. service version should not be provided.
// will only be applied if `NewIndexSchema=true`
MaxSchemaVersion string
// Deprecated is set to filter devfile index for stacks having the "Deprecated" tag inside their default set of tags
// or not. the only acceptable values are "true"/"false". in case the value is "true" it will only include only
// deprecated stacks, if is "false" only non deprecated. will only be applied if `NewIndexSchema=true`
michael-valdron marked this conversation as resolved.
Show resolved Hide resolved
Deprecated DeprecatedFilter
}

// GetRegistryIndex returns the list of index schema structured stacks and/or samples from a specified devfile registry.
Expand Down Expand Up @@ -152,13 +161,17 @@ func GetRegistryIndex(registryURL string, options RegistryOptions, devfileTypes
q.Add("arch", arch)
}
}

if options.NewIndexSchema && (options.Filter.MaxSchemaVersion != "" || options.Filter.MinSchemaVersion != "") {
if options.Filter.MinSchemaVersion != "" {
q.Add("minSchemaVersion", options.Filter.MinSchemaVersion)
if options.NewIndexSchema {
if options.Filter.MaxSchemaVersion != "" || options.Filter.MinSchemaVersion != "" {
if options.Filter.MinSchemaVersion != "" {
q.Add("minSchemaVersion", options.Filter.MinSchemaVersion)
}
if options.Filter.MaxSchemaVersion != "" {
q.Add("maxSchemaVersion", options.Filter.MaxSchemaVersion)
}
}
if options.Filter.MaxSchemaVersion != "" {
q.Add("maxSchemaVersion", options.Filter.MaxSchemaVersion)
if options.Filter.Deprecated == DeprecatedFilterTrue || options.Filter.Deprecated == DeprecatedFilterFalse {
q.Add("deprecated", string(options.Filter.Deprecated))
}
}
urlObj.RawQuery = q.Encode()
Expand Down
41 changes: 41 additions & 0 deletions registry-library/library/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ var (
},
}

deprecatedFilteredIndex = []indexSchema.Schema{
{
Name: "deprecatedindex1",
Tags: []string{"Deprecated, arm64"},
},
}

nonDeprecatedFilteredIndex = []indexSchema.Schema{
{
Name: "deprecatedindex2",
},
}

schemaVersionFilteredIndex = []indexSchema.Schema{
{
Name: "indexSchema2.1",
Expand Down Expand Up @@ -206,6 +219,10 @@ func setUpIndexHandle(indexUrl *url.URL) []indexSchema.Schema {

if strings.Contains(indexUrl.String(), "arch=amd64&arch=arm64") {
data = archFilteredIndex
} else if strings.Contains(indexUrl.String(), "deprecated=true") {
data = deprecatedFilteredIndex
} else if strings.Contains(indexUrl.String(), "deprecated=false") {
data = nonDeprecatedFilteredIndex
} else if strings.Contains(indexUrl.String(), "maxSchemaVersion=2.2") && strings.Contains(indexUrl.String(), "minSchemaVersion=2.1") {
data = schemaVersionFilteredIndex
} else if indexUrl.Path == "/index/sample" {
Expand Down Expand Up @@ -315,6 +332,30 @@ func TestGetRegistryIndex(t *testing.T) {
devfileTypes: []indexSchema.DevfileType{indexSchema.StackDevfileType},
wantSchemas: schemaVersionFilteredIndex,
},
{
name: "Get Deprecated Filtered Index",
url: "http://" + serverIP,
options: RegistryOptions{
NewIndexSchema: true,
Filter: RegistryFilter{
Deprecated: DeprecatedFilterTrue,
},
},
devfileTypes: []indexSchema.DevfileType{indexSchema.StackDevfileType},
wantSchemas: deprecatedFilteredIndex,
},
{
name: "Get Non Deprecated Filtered Index",
url: "http://" + serverIP,
options: RegistryOptions{
NewIndexSchema: true,
Filter: RegistryFilter{
Deprecated: DeprecatedFilterFalse,
},
},
devfileTypes: []indexSchema.DevfileType{indexSchema.StackDevfileType},
wantSchemas: nonDeprecatedFilteredIndex,
},
{
name: "Get Arch Filtered Index",
url: "http://" + serverIP,
Expand Down
Loading