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

Create a download-starter-project endpoint in the registry. #720

Closed
schultzp2020 opened this issue Jan 10, 2022 · 7 comments · Fixed by devfile/registry-support#109
Closed
Assignees
Labels
area/registry Devfile registry for stacks and infrastructure

Comments

@schultzp2020
Copy link
Contributor

Which area this feature is related to?
/area registry

Which functionality do you think we should add?

Create a download-starter-project endpoint in the registry.

Why is this needed? Is your feature request related to a problem?
Currently, we have this functionality in the registry-viewer; however, Next.js is limiting the body download size in future versions.

In addition, by creating this endpoint we can deploy the registry-viewer statically. The previous holdup was because any file in the /pages/api directory would create an api which requires a node server. If we could rip the download-starter-project functionality out of the api directory, the only other api in the directory, which is nonessential, is to make the registry-viewer dynamic. Therefore, by making this change it allows the registry-viewer to be static.

Describe the solution you'd like

An endpoint that takes a devfileName and a starterProjectName and downloads the starterProject when queried.

Describe alternatives you've considered

Keep this functionality inside of the registry-viewer; however, this has issues as stated above.

@openshift-ci openshift-ci bot added the area/registry Devfile registry for stacks and infrastructure label Jan 10, 2022
@michael-valdron
Copy link
Member

michael-valdron commented Jan 27, 2022

This new feature introduces a new endpoint GET /devfiles/:devfileName/starterProjects/:starterProjectName which will handle the download trigger for the starter project template. The handler for this endpoint is currently called serveDevfileStarterProject.

@michael-valdron
Copy link
Member

michael-valdron commented Jan 27, 2022

Part of the /devfiles/:devfileName/starterProjects/:starterProjectName endpoint this new feature introduces reuses source that already exists for the /devfiles/:name endpoint. As such, I am purposing one of the following implementations for a new function I am currently calling fetchDevfile.

Implementation 1

func fetchDevfile(devfileName string) ([]byte, error) {
	...
}

This implementation does not take the gin.Context entity as a parameter and relies on the error being returned for logging and setting the unsuccessful responses:

func serveDevfileStarterProject(c *gin.Context) {
	...

	devfileBytes, err := fetchDevfile(devfileName)

	if err != nil {
		log.Print(err.Error())
		c.JSON(http.StatusInternalServerError, gin.H{
			"error":  err.Error(),
			"status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
		})
		return
	} else if len(devfileBytes) == 0 {
		c.JSON(http.StatusNotFound, gin.H{
			"status": fmt.Sprintf("the devfile of %s didn't exist", devfileName),
		})
		return
	}

	...
}

This implementation makes the process simple but limits the status outcomes to as they are currently. If this poses a problem to future changes I have purposed Implementation 2 as an alternative. The devfile []byte result is empty if fetchDevfile is unsuccessful.

Implementation 2

func fetchDevfile(c *gin.Context, devfileName string) []byte {
	...
}

This implementation consists most of the source from /devfile/:name endpoint for fetching the devfile. It takes a pointer to the gin.Context as a parameter so unsuccessful responses tied to this are set in this function rather than endpoint's function. Due to this, we only need to return the devfile []byte result rather than additional error entity.

michael-valdron added a commit to michael-valdron/devfile-registry-support that referenced this issue Jan 28, 2022
@michael-valdron
Copy link
Member

michael-valdron commented Feb 1, 2022

Implementation 2 for fetchDevfile has been chosen with modified return type for returning the index schema for telemetry, current version below:

func fetchDevfile(c *gin.Context, devfileName string) ([]byte, indexSchema.Schema) {
	...
}

@michael-valdron
Copy link
Member

Closed issue #750 provides the following for getting the selected starterproject download location from the devfile contents:

filterOptions := common.DevfileOptions{
    FilterByName: starterProjectName,
}
...
starterProjects, err = content.Data.GetStarterProjects(filterOptions)

@yangcao77
Copy link
Contributor

yangcao77 commented Feb 3, 2022

@michael-valdron I want to raise up your attention that for the filter, if no such object fulfills all the filter conditions, it will just return an empty list, without any errors. The same behavior applies to name filter as well.
So if you want to alert on a non-existing starterProjectName being provided, you should check len(starterProjects) == 0 .

@michael-valdron
Copy link
Member

michael-valdron commented Feb 3, 2022

@yangcao77 Perfect, thanks letting know. I will use this as one of the conditions which produces the Not Found response for the endpoint:

if len(starterProjects) == 0 {
    c.JSON(http.StatusNotFound, gin.H{
        "status": fmt.Sprintf("the starter project named %s does not exist in the devfile of %s", starterProjectName, devfileName),
    })
}

michael-valdron added a commit to michael-valdron/devfile-registry-support that referenced this issue Feb 7, 2022
michael-valdron added a commit to michael-valdron/devfile-registry-support that referenced this issue Feb 7, 2022
michael-valdron added a commit to michael-valdron/devfile-registry-support that referenced this issue Feb 7, 2022
michael-valdron added a commit to michael-valdron/devfile-registry-support that referenced this issue Feb 7, 2022
@yangcao77
Copy link
Contributor

Since the index generated is with the new format, the starterProject endpoints need to look for a version, (version string or latest). If not version is provided, then pick the default.
As documented: https://docs.google.com/document/d/1_eXbAV1eKetKKu_FHGRw6kUUiUhcp7j1gB0uUrG0WF8/edit#heading=h.1pf53oes5yvw

michael-valdron added a commit to michael-valdron/devfile-registry-support that referenced this issue Mar 16, 2022
commit 40b70ab
Merge: 655c290 018c568
Author: Michael Valdron <[email protected]>
Date:   Tue Mar 1 15:31:08 2022 -0500

    fixed merge conflicts

commit 655c290
Merge: 3f4fb80 7a90a42
Author: Michael Valdron <[email protected]>
Date:   Thu Feb 24 21:24:37 2022 -0500

    Merge branch 'main' into addDownloadStarterProject

commit 3f4fb80
Author: Michael Valdron <[email protected]>
Date:   Thu Feb 17 18:13:18 2022 -0500

    starter project download git source changed to use index/generator functions.

commit 7170750
Author: Michael Valdron <[email protected]>
Date:   Thu Feb 17 18:12:14 2022 -0500

    dependency updates.

commit 9f72032
Author: Stephanie <[email protected]>
Date:   Tue Feb 15 16:21:24 2022 -0500

    add util.go for download from git

    Signed-off-by: Stephanie <[email protected]>

commit a86df62
Author: Michael Valdron <[email protected]>
Date:   Fri Feb 11 16:52:06 2022 -0500

    remove https from git url.

commit 40cde78
Author: Michael Valdron <[email protected]>
Date:   Fri Feb 11 15:01:28 2022 -0500

    Read archive bytes for zip urls fixed. Fixed ContentType set in response.

commit ce2090e
Author: Michael Valdron <[email protected]>
Date:   Fri Feb 11 14:01:31 2022 -0500

    golang image tag updated from alpine3.11 to alpine3.15

commit 1ce4615
Author: Michael Valdron <[email protected]>
Date:   Thu Feb 10 16:51:52 2022 -0500

    Removed commented out source of fetchDevfile impl 1 (unused).

commit 4edf10a
Author: Michael Valdron <[email protected]>
Date:   Thu Feb 10 16:50:37 2022 -0500

    source added for downloading starter project from zip url and git repository (root, remote -> origin)

commit ef946e8
Author: Michael Valdron <[email protected]>
Date:   Thu Feb 10 16:48:05 2022 -0500

    Dependency go-getter added for downloading starter projects using git as a source and with subDir set.

commit 8ca0364
Author: Michael Valdron <[email protected]>
Date:   Wed Feb 9 11:29:57 2022 -0500

    added missing return statements to error condition blocks.

commit 95c39f7
Merge: e8852e3 723fa9c
Author: Michael Valdron <[email protected]>
Date:   Wed Feb 9 11:20:49 2022 -0500

    Merge branch 'main' into addDownloadStarterProject

commit e8852e3
Author: Michael Valdron <[email protected]>
Date:   Tue Feb 8 19:50:42 2022 -0500

    param key change in index.go applied to serveStarterProjects endpoint. Control logic for starter project download methods added.

commit 768f0cb
Author: Michael Valdron <[email protected]>
Date:   Tue Feb 8 19:43:50 2022 -0500

    serveStarterProjects endpoint key :devfileName changed to :name to match serveDevfile endpoint pattern.

commit ff614c5
Author: Michael Valdron <[email protected]>
Date:   Mon Feb 7 18:03:34 2022 -0500

    dependency updates: go v1.14->v1.17, gin v1.6.3->v1.7.7, github.com/deislabs/oras v0.8.1->oras.land/oras-go v0.4.0

commit 9a5b40f
Merge: 0d01cd3 6566c05
Author: Michael Valdron <[email protected]>
Date:   Mon Feb 7 14:13:55 2022 -0500

    Merge branch 'addDownloadStarterProject' of github:michael-valdron/registry-support into addDownloadStarterProject

commit 0d01cd3
Author: Michael Valdron <[email protected]>
Date:   Fri Jan 28 17:29:35 2022 -0500

    fetchDevfile now returns the devfile's index schema for telemetry data.

commit 40db91a
Author: Michael Valdron <[email protected]>
Date:   Fri Jan 28 16:44:44 2022 -0500

    Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: devfile/api#720

commit 336153a
Author: Michael Valdron <[email protected]>
Date:   Tue Feb 1 16:52:43 2022 -0500

    filtering added using temp iteration and control logic, filter options commented out until new release of library.

commit f25e6b8
Author: Michael Valdron <[email protected]>
Date:   Tue Feb 1 11:25:03 2022 -0500

    library dependency added.

commit de05073
Author: Michael Valdron <[email protected]>
Date:   Mon Jan 31 20:58:45 2022 -0500

    get starter project entity source added.

commit c0a0f6e
Author: Michael Valdron <[email protected]>
Date:   Fri Jan 28 17:29:35 2022 -0500

    fetchDevfile now returns the devfile's index schema for telemetry data.

commit ac4f605
Author: Michael Valdron <[email protected]>
Date:   Fri Jan 28 16:44:44 2022 -0500

    Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: devfile/api#720

commit 8dd8c1c
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 27 17:34:18 2022 -0500

    fixed up some return statements and flow control for fetching a devfile.

commit d5aba7a
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 20 16:54:50 2022 -0500

    serveDevfileStarterProject endpoint definitions added.

commit 7b8e5ac
Author: Michael Valdron <[email protected]>
Date:   Wed Jan 26 19:21:38 2022 -0500

    draft proposal function source added.

commit 6b44b81
Author: Michael Valdron <[email protected]>
Date:   Wed Jan 26 19:20:21 2022 -0500

    endpoint URL format changes.

commit 0de93f6
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 20 16:54:50 2022 -0500

    serveDevfileStarterProject endpoint definitions added.

commit 2dd0890
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 20 16:46:08 2022 -0500

    reorganized util package import in index.go

commit 6566c05
Merge: 65dcb66 f96264a
Author: Michael Valdron <[email protected]>
Date:   Mon Feb 7 13:58:12 2022 -0500

    Merge branch 'addDownloadStarterProject' of github:michael-valdron/registry-support into addDownloadStarterProject

commit 65dcb66
Author: Michael Valdron <[email protected]>
Date:   Fri Jan 28 17:29:35 2022 -0500

    fetchDevfile now returns the devfile's index schema for telemetry data.

commit 9c10f03
Author: Michael Valdron <[email protected]>
Date:   Fri Jan 28 16:44:44 2022 -0500

    Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: devfile/api#720

commit f96264a
Merge: 3d7a869 e0351de
Author: Michael Valdron <[email protected]>
Date:   Mon Feb 7 13:51:24 2022 -0500

    Merge branch 'addDownloadStarterProject' of github:michael-valdron/registry-support into addDownloadStarterProject

commit 3d7a869
Author: Michael Valdron <[email protected]>
Date:   Tue Feb 1 16:52:43 2022 -0500

    filtering added using temp iteration and control logic, filter options commented out until new release of library.

commit 8cdd723
Author: Michael Valdron <[email protected]>
Date:   Tue Feb 1 11:25:03 2022 -0500

    library dependency added.

commit 476e7c6
Author: Michael Valdron <[email protected]>
Date:   Mon Jan 31 20:58:45 2022 -0500

    get starter project entity source added.

commit 9843452
Author: Michael Valdron <[email protected]>
Date:   Fri Jan 28 17:29:35 2022 -0500

    fetchDevfile now returns the devfile's index schema for telemetry data.

commit b6658b8
Author: Michael Valdron <[email protected]>
Date:   Fri Jan 28 16:44:44 2022 -0500

    Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: devfile/api#720

commit c0a9685
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 27 17:34:18 2022 -0500

    fixed up some return statements and flow control for fetching a devfile.

commit 5da0574
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 20 16:54:50 2022 -0500

    serveDevfileStarterProject endpoint definitions added.

commit e0351de
Author: Michael Valdron <[email protected]>
Date:   Tue Feb 1 16:52:43 2022 -0500

    filtering added using temp iteration and control logic, filter options commented out until new release of library.

commit 94e64ea
Author: Michael Valdron <[email protected]>
Date:   Tue Feb 1 11:25:03 2022 -0500

    library dependency added.

commit 99cbed9
Author: Michael Valdron <[email protected]>
Date:   Mon Jan 31 20:58:45 2022 -0500

    get starter project entity source added.

commit 2ca9308
Author: Michael Valdron <[email protected]>
Date:   Fri Jan 28 17:29:35 2022 -0500

    fetchDevfile now returns the devfile's index schema for telemetry data.

commit 2bb8eb9
Author: Michael Valdron <[email protected]>
Date:   Fri Jan 28 16:44:44 2022 -0500

    Implementation 2 for fetchDevfile chosen and added. See Issue #720 discussion at: devfile/api#720

commit 6ee2896
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 27 17:34:18 2022 -0500

    fixed up some return statements and flow control for fetching a devfile.

commit b768325
Merge: 6bd6809 4e3a233
Author: Michael Valdron <[email protected]>
Date:   Wed Jan 26 19:23:38 2022 -0500

    fixed merge conflicts.

commit 6bd6809
Author: Michael Valdron <[email protected]>
Date:   Wed Jan 26 19:21:38 2022 -0500

    draft proposal function source added.

commit 0ed5d25
Author: Michael Valdron <[email protected]>
Date:   Wed Jan 26 19:20:21 2022 -0500

    endpoint URL format changes.

commit b119a18
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 20 16:54:50 2022 -0500

    serveDevfileStarterProject endpoint definitions added.

commit 1bac181
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 20 16:46:08 2022 -0500

    reorganized util package import in index.go

commit 4e3a233
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 20 16:54:50 2022 -0500

    serveDevfileStarterProject endpoint definitions added.

commit a6f6343
Author: Michael Valdron <[email protected]>
Date:   Thu Jan 20 16:46:08 2022 -0500

    reorganized util package import in index.go

Signed-off-by: Michael Valdron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/registry Devfile registry for stacks and infrastructure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants