WIP - server: user-defined services#80000
Draft
knz wants to merge 1 commit intocockroachdb:masterfrom
Draft
Conversation
Member
Contributor
Author
|
url shortener example: CREATE TABLE IF NOT EXISTS shortener (
path STRING NOT NULL PRIMARY KEY,
url STRING NOT NULL
);
GRANT SELECT ON TABLE shortener TO myuser;
GRANT INSERT ON TABLE shortener TO myuser;
-- FIXME: use customizable user for non-authn access.
GRANT SELECT ON TABLE shortener TO anonymous;
INSERT INTO services (path, http_method, authn_method, exec_method, function)
VALUES
('/shortener', 'GET,POST', 'cookie', 'thtml', $tmpl$
<html><body>
<h1>Hello {{ getUser }}!</h1>
<!--no display needed for this logic
{{with $url := getInput "url" }}
{{with $path := getInput "path" }}
{{if ne $url "" }}{{if ne $path ""}}
{{exec "INSERT INTO defaultdb.shortener(path,url) VALUES('/go/'||$1, $2) ON CONFLICT DO NOTHING" $path $url}}
{{end}}{{end}}
{{end}}{{end}}
-->
<h2>Define new URL shortcut</h2>
<form action=/shortener method=post>
Short path: <input type=text id=path name=path><br/>
Destination URL: <input type=text id=url name=url><br/>
<input type="submit" value="Submit">
</form>
<h2>Predefined URLs</h2>
<table>
<thead><tr><th>Path</th><th>URL</th></tr></thead>
<tbody>
{{range query "SELECT path,url FROM defaultdb.shortener ORDER BY path"}}
<tr>
<td><a href="{{with index . 0}}{{.AsText}}{{end}}">
{{with index . 0}}{{.AsText}}{{end}}
</a></td>
<td>{{with index . 1}}{{.AsText}}{{end}}</td>
</tr>
{{end}}
</tbody></table>
<p><a href="/logout">logout</a></p>
</body></html>
$tmpl$);
INSERT INTO services (path, http_method, authn_method, exec_method, function)
VALUES
('/go/', 'GET', 'none', 'thtml', $tmpl$
<html><body>
{{with $path := getPath }}
{{range query "SELECT url FROM defaultdb.shortener WHERE path=$1" $path}}
{{with $urlv := index . 0 }}{{with $url := .AsText}}
{{redirect $url}}
<a href="{{$url}}">{{$url}}</a>
{{end}}{{end}}
{{else}}
<b>No URL registered for this path!</b><br/>
<a href=/shortener>Maybe add one?</a>
{{end}}
{{end}}
</html></body>
$tmpl$);
INSERT INTO services (path, exec_method)
VALUES
('/login', 'login-cookie'),
('/logout', 'logout-cookie');
INSERT INTO services (path, http_method, authn_method, exec_method, function)
VALUES
('/loginform', 'GET', 'none', 'thtml', $tmpl$
<html><body>
<form action=/login method=post>
Username: <input type=text id=username name=username><br/>
Password: <input type=password id=password name=password><br/>
<input type="submit" value="Login">
</form>
</body></html>
$tmpl$);
|
Contributor
Author
|
now using scriggo as template system |
bf2ee4b to
2456e3e
Compare
Contributor
Author
|
@bobvawter in case you're curious: https://github.com/knz/cockroach/tree/20220415-services/docs/tech-notes/services |
2cd88b2 to
77f6260
Compare
Some docs in the `docs/tech-notes/services` directory. Release note: TBD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some docs here: https://github.com/knz/cockroach/tree/20220415-services/docs/tech-notes/services
Release note: TBD