Skip to content

Commit 723fa9c

Browse files
authored
Merge pull request devfile#99 from kim-tsao/doc_updates
Update Registry Library docs
2 parents 22fa97d + c0d2b10 commit 723fa9c

File tree

2 files changed

+92
-48
lines changed

2 files changed

+92
-48
lines changed

registry-library/README.md

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,96 @@
11
# Devfile registry library
22

33
## Overview
4-
Devfile registry library is used for interacting with devfile registry, consumers can use devfile registry library to list stacks and/or samples of devfile registry, download the stack devfile and the whole stack from devfile registry.
4+
The Devfile registry library is used to interact with the devfile registry to perform the following actions:
5+
6+
* List the indices of stacks and/or samples from a single registry or across multiple registries
7+
* Download a stack with specific media types or all supported media types
8+
* Send telemetry to the Devfile Registry service
9+
* Filter stacks based on architectures
510

611
## What's included
7-
`./library`: package `library` which contains devfile registry library constants, variables and functions, documentations can be found [here](https://pkg.go.dev/github.com/devfile/registry-support/registry-library/library)
12+
`./library`: package `library` which contains devfile registry library constants, variables and functions. Documentation can be found [here](https://pkg.go.dev/github.com/devfile/registry-support/registry-library/library)
813

9-
`./build.sh`: build script to build `registry` binary to interact with devfile registry
14+
`./build.sh`: build script to build the `registry-library` binary to interact with devfile registry
1015

11-
`./registry`: `registry` binary to interact with devfile registry
16+
`./registry-library`: `registry-library` binary to interact with devfile registry
1217

1318
## How to use it
14-
1. Import devfile registry library
15-
```go
16-
import (
17-
registryLibrary "github.com/devfile/registry-support/registry-library/library"
18-
)
19-
```
20-
2. Invoke devfile registry library
21-
22-
a. Get the index of devfile registry for various devfile types
23-
```go
24-
registryIndex, err := registryLibrary.GetRegistryIndex(registryURL, options, StackDevfileType)
25-
if err != nil {
26-
return err
27-
}
19+
1. Import the devfile registry library and index schema
20+
```go
21+
import (
22+
registryLibrary "github.com/devfile/registry-support/registry-library/library"
23+
indexSchema "github.com/devfile/registry-support/index/generator/schema"
24+
)
25+
```
26+
27+
### List the indices of stacks and/or samples
28+
1. Get the index for stack devfile types from a single registry
29+
30+
```go
31+
registryURL := "https://registry.devfile.io"
32+
options := registryLibrary.RegistryOptions{} //leave empty if telemetry and architecture types are not relevant
33+
registryIndex, err := registryLibrary.GetRegistryIndex(registryURL, options, indexSchema.StackDevfileType)
34+
if err != nil {
35+
return err
36+
}
2837
```
29-
b. Get the indices of multiple devfile registries for various devfile types
38+
2. Get the index for all devfile types from a single registry
3039
```go
31-
registryList := GetMultipleRegistryIndices(registryURLs, options, StackDevfileType)
40+
devfileTypes := []indexSchema.DevfileType{indexSchema.StackDevfileType, indexSchema.SampleDevfileType}
41+
registryIndex, err := registryLibrary.GetRegistryIndex(registryURL, options, devfileTypes...)
42+
if err != nil {
43+
return err
44+
}
3245
```
33-
c. Download the stack devfile from devfile registry
46+
47+
3. Get the indices for various devfile stacks from multiple devfile registries
3448
```go
35-
err := registryLibrary.PullStackByMediaTypesFromRegistry(registry, stack, registryLibrary.DevfileMediaTypeList, destDir, options)
36-
if err != nil {
37-
return err
38-
}
49+
registryList := GetMultipleRegistryIndices(registryURLs, options, indexSchema.StackDevfileType)
3950
```
40-
d. Download the whole stack from devfile registry
51+
#### Download the stack
52+
Supported devfile media types can be found in the latest version of [library.go](https://github.com/devfile/registry-support/blob/main/registry-library/library/library.go)
53+
1. Download a stack devfile with a given media type from the devfile registry
4154
```go
42-
err := registryLibrary.PullStackFromRegistry(registry, stack, destDir, options)
55+
stack := "java-springboot"
56+
destDir := "."
57+
err := registryLibrary.PullStackByMediaTypesFromRegistry(registryURL, stack, registryLibrary.DevfileMediaTypeList, destDir, options)
4358
if err != nil {
44-
return err
45-
}
59+
return err
60+
}
4661
```
47-
e. Specify Options
62+
2. Download a stack with all supported media types from the devfile registry
4863
```go
49-
options := RegistryOptions{
50-
User: user,
51-
SkipTLSVerify: skipTLSVerify,
52-
Filter: RegistryFilter{
64+
err := registryLibrary.PullStackFromRegistry(registryURL, stack, destDir, options)
65+
if err != nil {
66+
return err
67+
}
68+
```
69+
70+
#### Specify Registry Options
71+
1. Test a pre-prod registry installed with self-signed certificates
72+
```go
73+
options := registryLibrary.RegistryOptions{
74+
SkipTLSVerify: "true",
75+
}
76+
```
77+
2. Filter Devfiles based on a set of architectures found in [header.go](https://github.com/devfile/api/blob/main/pkg/devfile/header.go)
78+
```go
79+
architectures := []string{"amd64", "arm64"}
80+
options := registryLibrary.RegistryOptions{
81+
Filter: registryLibrary.RegistryFilter{
5382
Architectures: architectures,
5483
},
5584
}
5685
```
86+
3. Send Telemetry data to the Devfile Registry
87+
```go
88+
options := registryLibrary.RegistryOptions{
89+
Telemetry: registryLibrary.TelemetryData{
90+
User: "user-name" //this can be a generated UUID
91+
Locale: "en_US" // set the OS or browser locale
92+
Client: "client-name" //the name of the client
93+
}
94+
}
95+
96+

registry-library/library/library.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ import (
3939
)
4040

4141
const (
42-
// Devfile media types
43-
DevfileConfigMediaType = "application/vnd.devfileio.devfile.config.v2+json"
42+
// Supported Devfile media types
4443
DevfileMediaType = "application/vnd.devfileio.devfile.layer.v1"
4544
DevfileVSXMediaType = "application/vnd.devfileio.vsx.layer.v1.tar"
4645
DevfileSVGLogoMediaType = "image/svg+xml"
@@ -63,28 +62,33 @@ type Registry struct {
6362
}
6463

6564
//TelemetryData structure to pass in client telemetry information
65+
// The User and Locale fields should be passed in by clients if telemetry opt-in is enabled
66+
// the generic Client name will be passed in regardless of opt-in/out choice. The value
67+
// will be assigned to the UserId field for opt-outs
6668
type TelemetryData struct {
67-
// The User and Locale fields will be passed in by the clients if telemetry opt-in is enabled
68-
User string
69+
// User is a generated UUID or generic client name
70+
User string
71+
// Locale is the OS or browser locale
6972
Locale string
70-
// the generic client name will be passed in regardless of opt-in/out choice. The value
71-
// will be assigned to the UserId field for opt-outs
73+
//Client is a generic name that describes the client
7274
Client string
7375
}
7476

7577
type RegistryOptions struct {
78+
// SkipTLSVerify is false by default which is the recommended setting for a devfile registry deployed in production. SkipTLSVerify should only be set to true
79+
// if you are testing a devfile registry that is set up with self-signed certificates in a pre-production environment.
7680
SkipTLSVerify bool
77-
Telemetry TelemetryData
78-
Filter RegistryFilter
81+
// Telemetry allows clients to send telemetry data to the community Devfile Registry
82+
Telemetry TelemetryData
83+
// Filter allows clients to specify which architectures they want to filter their devfiles on
84+
Filter RegistryFilter
7985
}
8086

8187
type RegistryFilter struct {
8288
Architectures []string
8389
}
8490

85-
// GetRegistryIndex returns the list of stacks and/or samples, more specifically
86-
// it gets the stacks and/or samples content of the index of the specified registry
87-
// for listing the stacks and/or samples
91+
// GetRegistryIndex returns the list of index schema structured stacks and/or samples from a specified devfile registry.
8892
func GetRegistryIndex(registryURL string, options RegistryOptions, devfileTypes ...indexSchema.DevfileType) ([]indexSchema.Schema, error) {
8993
var registryIndex []indexSchema.Schema
9094

@@ -162,7 +166,7 @@ func GetRegistryIndex(registryURL string, options RegistryOptions, devfileTypes
162166
return registryIndex, nil
163167
}
164168

165-
// GetMultipleRegistryIndices returns returns the list of stacks and/or samples of multiple registries
169+
// GetMultipleRegistryIndices returns the list of stacks and/or samples from multiple registries
166170
func GetMultipleRegistryIndices(registryURLs []string, options RegistryOptions, devfileTypes ...indexSchema.DevfileType) []Registry {
167171
registryList := make([]Registry, len(registryURLs))
168172
registryContentsChannel := make(chan []indexSchema.Schema)
@@ -210,7 +214,7 @@ func PrintRegistry(registryURLs string, devfileType string, options RegistryOpti
210214
return nil
211215
}
212216

213-
// PullStackByMediaTypesFromRegistry pulls stack from registry with allowed media types to the destination directory
217+
// PullStackByMediaTypesFromRegistry pulls a specified stack with allowed media types from a given registry URL to the destination directory
214218
func PullStackByMediaTypesFromRegistry(registry string, stack string, allowedMediaTypes []string, destDir string, options RegistryOptions) error {
215219
// Get the registry index
216220
registryIndex, err := GetRegistryIndex(registry, options, indexSchema.StackDevfileType)
@@ -278,7 +282,7 @@ func PullStackByMediaTypesFromRegistry(registry string, stack string, allowedMed
278282
return nil
279283
}
280284

281-
// PullStackFromRegistry pulls stack from registry with all stack resources (all media types) to the destination directory
285+
// PullStackFromRegistry pulls a specified stack with all devfile supported media types from a registry URL to the destination directory
282286
func PullStackFromRegistry(registry string, stack string, destDir string, options RegistryOptions) error {
283287
return PullStackByMediaTypesFromRegistry(registry, stack, DevfileAllMediaTypesList, destDir, options)
284288
}

0 commit comments

Comments
 (0)