Skip to content

Commit

Permalink
feat: return metadata for go get (#804)
Browse files Browse the repository at this point in the history
Return special meta that will help Go tools to discover correct VCS.

That will allow developers to get modules with go get maas.io/core/maas and then import as:

`maas.io/core/src/maasagent/pkg/workflow/codec`
  • Loading branch information
troyanov authored Aug 17, 2023
1 parent 20be5a8 commit d76ab5c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions templates/gomod.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="go-import" content="maas.io/core git https://git.launchpad.net/~maas-committers/maas">
</head>
</html>
28 changes: 28 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ def test_not_found(self):

self.assertEqual(self.client.get("/not-found-url").status_code, 404)

def test_gomod(self):
"""
When given /core.* with go-get=1 query parameter,
we should return gomod
"""

self.assertEqual(self.client.get("/core?go-get=1").status_code, 200)
self.assertEqual(
self.client.get("/core/maas?go-get=1").status_code, 200
)
self.assertEqual(
self.client.get("/core/maas/src?go-get=1").status_code, 200
)

def test_gomod_not_found(self):
"""
When given /core.* without go-get=1 query parameter,
we should return a 404 status code
"""

self.assertEqual(self.client.get("/core").status_code, 404)
self.assertEqual(self.client.get("/core/maas").status_code, 404)
self.assertEqual(self.client.get("/core/maas/src").status_code, 404)
self.assertEqual(self.client.get("/core/maas?go-get").status_code, 404)
self.assertEqual(
self.client.get("/core/maas/src?go-get=0").status_code, 404
)


if __name__ == "__main__":
unittest.main()
15 changes: 15 additions & 0 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,20 @@ def api():
)


@app.route("/core", defaults={"subpath": None})
@app.route("/core/<path:subpath>")
def gomod(subpath):
"""
Return metadata for Go package manager
That allows to do things like `go get maas.io/core/src/maasagent`
by using Git repository at https://code.launchpad.net/maas
"""

if flask.request.query_string == b"go-get=1":
return flask.render_template("gomod.html"), 200

flask.abort(404)


init_blog(app, "/blog")
init_tutorials(app, "/tutorials", session)

0 comments on commit d76ab5c

Please sign in to comment.