We still support directly setting LastSnapshot to support embedding the
snapshot in the binary (like we do internally). But this allows an
alternate way have restoring backups which doesn't require recompiling
binaries.
Even though we have our own build and deploy scripts, most users will be
more comfortable with a standard Dockerfile. We could publish our
scripts later if warranted. For now, we'll just keep them in corp.
Go 1.19 rejects relative paths in $PATH (https://go.dev/cl/403274),
so resolve the tool/ path before adding it.
Updates tailscale/tailscale#5210
Change-Id: I891dd2739fe18534e0facb4dbbaaf6a98b91aeb1
remove FileDB implementation, related flags, and filedb to sqlite
migration code. Also remove the DB interface since it's no longer
needed. dev mode now creates a temporary SQLite database.
Change-Id: I22f92dccdd575f6c35a10523ede8ecf85ae330bb
use relative links throughout rather than hardcoding the go hostname,
which allows things to continue working when other hostnames are used.
Change-Id: I5df0d10214799de9722871cbad99bf9af129941f
Properly use html/template rather than text/template so that we don't
have to worry about escaping data that is passed in to the templates.
Also move the success page into a template for both better rendering and
consistency.
Finally, this includes some tailwind changes that apparently got missed
in previous commits.
Change-Id: Ic658ab940888c44483501e33699da9021be18ecf
Add flags to specify sqlite database and migration from files to sqlite.
Migration is only supported in one direction (and flag name makes that
clear). If both sqlite and linkdir flags are provided, sqlite is
preferred. This has no change in behavior if neither of the new flags
are provided.
Change-Id: Ie13116ec3b80835b4389d228583e7a1476c00bfb
Add a new /.help URL which contains a first pass at user docs, covering
naming rules for short links, using go templates, and basic API access.
Also add client side validation for short name and a link to help page.
Change-Id: I4b66793248eba17e567c4f422ee197617f74ee24
When a user visits a non-existing go link, it's reasonable to assume
that they may then want to create that link, so autofocus on the
destination input.
We could also autofocus the short input on initial page load without a
provided short name, but I think that's less of a safe assumption.
Change-Id: Id8e15e2f02f81d319eb782576e5e19f73c0ccee4
add new DB.LoadStats and DB.SaveStats methods. DB.SaveSaveStats takes
an incremental count of clicks since the last call. This is a noop for
FileDB (the full count is still saved in the Link struct on disk), but
will allow for the SqliteDB to store stats in a separate table with
timestamps to display only recent clicks.
Change-Id: I18c7db871854923b873ae100c844940242a32bb3
If the previous owner of a link no longer appears in the tailnet users,
any user can overwrite the link and will become the new owner.
Change-Id: I52bbc5e906ff5b1b6424c0e320fd0d02c006ac12
store click stats in db. Hold stats in memory and flush to db every
minute, as well as whenever the /_/export endpoint is called.
Change DB.List() to DB.LoadAll(), since it practice we actually want
the data, not just the names.
Change-Id: I21a3aa19bfc065d595822f004a14b96bbb347de8
after successfully saving a golink, return an HTML response only if the
request indicates it can accept text/html, otherwise return JSON. This
allows for a very simple API:
% curl -d short=foo -d long=http://foo.com/ go
{"Short":"foo","Long":"http://foo.com/" ... }
Change-Id: I32e9c028207c5c7b8741d7dd31ebed35cf38a1de
append "+" to the end of a golink to get information about the link
rather than being redirected. For now, this just pretty prints the raw
JSON. We could make it prettier later.
Change-Id: If25c9f61c326f6e12cdec89b78eb3ca1b741a0ef
This is a straight refactor with no functional changes. All file access
is captured in the FileDB type. The DB interface is not strictly
necessary here since we only have a single implementation, but helped to
keep the API clean, which will be useful in a future sqlite migration.
Change-Id: I9b86db3040e2618a4ffef237369288ccfc10bc1e
This sets up an embed.FS even though we only have the one file right
now, as we will have more shortly.
Change-Id: I1292e4c00602fbfc3a7bc2a5f93a8c9b9e6715c0
Otherwise we can't save a link using the funcs.
Change-Id: If48e1527f5b21f0314d3e1b4c3c38b9ca7fa65b8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
long URLs are now executed using text/template to allow for more advaned
handling. Templates have access to PathEscape and QueryEscape funcs, as
well as a data struct containing the current time (Now) and the
remaining path from the user-provided short link (Path).
Change-Id: Iedbbafccf98c4a623d06e9519877c7137ca559e8
- ignore hyphens, preventing link ambiguity. If hyphens are included
when creating the link, they are saved as the "canonical" name for
the link, but links are still resolved without them.
- allow overwriting the "canonical" name for a short link by simply
recreating it with the new canonical name. Stats are not updated when
the canonical name is updated, which is probably fine.
Change-Id: Ia962caa846489850784ef15cdfad7f13bafd8842
In the meantime, before sqlite-and-litestream-to-S3, and as a
transition mechanism to move this service to be running on Fly instead
of Brad's dev box, add support for backing up the go/ links to a file
in git, baking it into the binary, and restoring it as needed when the
binary starts up, including in a newly added dev mode.
Change-Id: I8961f720c0f9b29eb7b0b6b1f62bac7ace2d67dc