fs_tools

package
v0.0.0-...-d758611 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 32 Imported by: 0

README

FS Tools

This module provides access to File System.

Features:

  • Authentication using user and password credentials;
  • WEBDAV access protocol.
File System page
File System page

Documentation

Index

Constants

View Source
const (
	AccessWebDAV = "webdav"
	AccessGit    = "git"
)

The kinds of access OnAccess is told.

View Source
const GitKeyPattern = "{key}"

GitKeyPattern ends the Name of a repository of each key (GitRepo).

View Source
const MessagesKey i18n.ModuleKey = "rvq-admin/fs-tools"
View Source
const ZeroID = "0000000000000000000000000000000000000000"

ZeroID is the id of no commit: the Old of a ref created, the New of one deleted.

Variables

View Source
var (
	Messages_en_US = &Messages{
		ModuleDescription: "The file system tools: browsing the files and reaching them through WebDAV.",
		FileSystem:        "File System",
		WebDavAccessTemplate: "Access the files through the WEBDAV protocol at the URL: <code class='text-primary'>%s" +
			"</code>, using your user login and password.",
		WebDavProtocolTitle: "WEBDAV Protocol",
		WebDavProtocolSoftwareExample: "<div class='mt-2'>Some programs for WEBDAV protocol access: " +
			"<a href='https://winscp.net/eng/index.php' target='_blank'>WinSCP</a> (Windows); " +
			"Dolphin and Nautilus (Linux). </div>",
	}

	Messages_pt_BR = &Messages{
		ModuleDescription: "As ferramentas do sistema de arquivos: navegar pelos arquivos e acessá-los por WebDAV.",
		FileSystem:        "Sistema de Arquivos",
		WebDavAccessTemplate: "Acesse os arquivos através do protocolo WEBDAV, pela URL: <code class='text-primary'>%s" +
			"</code>, usando seu login e senha de usuário.",
		WebDavProtocolTitle: "Protocolo WEBDAV",
		WebDavProtocolSoftwareExample: "<div class='mt-2'>Alguns programas para acesso de Protocolo WEBDAV: " +
			"<a href='https://winscp.net/eng/index.php' target='_blank'>WinSCP</a> (Windows); " +
			"Dolphin and Nautilus (Linux). </div>",
	}
)
View Source
var EnvDirs = osenv.Get("RVQ_FSTOOLS_DIRS", "Directories available for webdav service. Values separated by "+
	"semi collon. Value format is MODE,MOUNT_POINT,LOCAL_PATH, when MODE=[r or w (default)]."+
	" Example: 'r,/media,data/media;w,/writable,/x/media'", "")
View Source
var ErrNotHook = errors.New("not run as a git hook")

ErrNotHook is RunGitHook's error when the application was not run as a hook.

Functions

func ConfigureMessages

func ConfigureMessages(b *i18n.Builder)

func GitRepoKey

func GitRepoKey(r *http.Request) string

GitRepoKey is the key of the repository of r, of a GitRepo of each key ("drafts/{key}": the <key> of <admin>/drafts/<key>.git); "" for one of its own.

func RunGitHookIfInvoked

func RunGitHookIfInvoked()

RunGitHookIfInvoked runs the application as the hook of a push, when git ran it so (a repository of GitHandler): it tells the server the push and exits — with the server's answer, its message shown to whoever pushed. Otherwise it returns at once. Call it first thing in main.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func New

func New(p *presets.Builder, ib *i18n.Builder, lb *login.Builder) (b *Builder, err error)

func (*Builder) AddGitRepo

func (b *Builder) AddGitRepo(repo *GitRepo) *Builder

AddGitRepo serves a git repository at <admin>/<Name>.git (GitHandler).

func (*Builder) AddMount

func (b *Builder) AddMount(m *Mount) *Builder

AddMount adds a directory of each request to the WebDAV.

func (*Builder) DavPath

func (b *Builder) DavPath() string

func (*Builder) FS

func (b *Builder) FS() hackpadfs.FS

func (*Builder) GitHandler

func (b *Builder) GitHandler() http.Handler

GitHandler serves the repositories added (AddGitRepo), each at its path (GitPath) — a mux of its own for the paths <admin>/<name>.git/…, each request by the user of its login (HTTP Basic, as the WebDAV) — or the secure key as its password: the administrator (login.SecureKeyBasicAuthMiddleware). nil when there is none.

func (*Builder) GitKeyPath

func (b *Builder) GitKeyPath(name, key string) string

GitKeyPath is the path of the repository of key of name ("drafts/{key}"): <admin>/drafts/<key>.git.

func (*Builder) GitMountPaths

func (b *Builder) GitMountPaths() (paths []string)

GitMountPaths are the paths GitHandler serves, each ending in "/": a repository's (<admin>/<name>.git/), or the folder of the repositories of each key (<admin>/<base>/) — to mount it on another mux.

func (*Builder) GitPath

func (b *Builder) GitPath(name string) string

GitPath is the path of the repository name: <admin>/<name>.git.

func (*Builder) GitRepos

func (b *Builder) GitRepos() []*GitRepo

GitRepos are the repositories added (AddGitRepo).

func (*Builder) Install

func (b *Builder) Install(p *presets.Builder) (err error)

func (*Builder) Model

func (b *Builder) Model() *presets.ModelBuilder

func (*Builder) OnAccess

func (b *Builder) OnAccess(f func(r *http.Request, kind string)) *Builder

OnAccess is told each request of the WebDAV (AccessWebDAV) and of the git (AccessGit), once its user is told (login.AuthOf: how): the log of its sessions.

func (*Builder) SetFS

func (b *Builder) SetFS(fs hackpadfs.FS) *Builder

func (*Builder) WebDavHandler

func (b *Builder) WebDavHandler() (h http.Handler)

type GitAccess

type GitAccess int

GitAccess is what a request asks of a git repository: to read it (clone, fetch) or to write in it (push).

const (
	GitRead GitAccess = iota
	GitWrite
)

type GitReceive

type GitReceive struct {
	Request *http.Request
	Dir     string
	// GitDir is the git directory of the repository (absolute).
	GitDir  string
	Updates []RefUpdate
	Env     []string
}

GitReceive is a push being received: its request, the repository (Dir) and the refs it changes. Env is the environment of git in the hook — with it, git sees the objects of the push, not yet in the repository before it is accepted (the quarantine).

func (*GitReceive) Git

func (rc *GitReceive) Git(ctx context.Context, args ...string) (string, error)

Git runs git on the repository of the push, the objects of the push seen.

type GitRepo

type GitRepo struct {
	// Name is its name in the URL: "site-files" is <admin>/site-files.git.
	// Ending in "/{key}", it is a repository of each key: "drafts/{key}" is
	// <admin>/drafts/<key>.git, the key told by GitRepoKey.
	Name string
	// Dir is the repository of the request (its .git, or the directory
	// holding it): one of each user, say.
	Dir func(r *http.Request) (string, error)
	// Allowed says whether the request may read the repository, or write in
	// it; nil allows all (to whoever logged in).
	Allowed func(r *http.Request, a GitAccess) bool
	// Middleware wraps the repository's handler, after the login and before
	// the permission: making the user's repository the first time, say.
	Middleware []func(http.Handler) http.Handler
	// Config is the configuration of git for it, "key=value"
	// ("receive.denyCurrentBranch=updateInstead").
	Config []string
	// Env is more of git's environment, "KEY=value" (GIT_WORK_TREE, over a
	// core.worktree that names another machine's path); the hooks' commands
	// (GitReceive.Git) have its GIT_WORK_TREE too.
	Env []string
	// PreReceive is asked before a push is accepted: an error refuses it —
	// nothing written —, its message shown to whoever pushed.
	PreReceive func(ctx context.Context, rc *GitReceive) error
	// PostReceive is told of a push accepted: its refs updated.
	PostReceive func(ctx context.Context, rc *GitReceive)
}

GitRepo is a git repository served by HTTP (git's smart protocol), at <admin>/<Name>.git: cloned and pushed to by the users of the admin, by their login.

type Messages

type Messages struct {
	ModuleDescription             string    `i18n:"hint='Says what the module is, for whoever translates its texts.'"`
	FileSystem                    string    `i18n:"hint='Title of the file system tools page.'"`
	WebDavAccessTemplate          h.RawHTML `` /* 126-byte string literal not displayed */
	WebDavProtocolTitle           string    `i18n:"label='WebDAV protocol title', hint='Title of the section about the WebDAV protocol.'"`
	WebDavProtocolSoftwareExample h.RawHTML `i18n:"type=html, label='WebDAV programs', hint='Programs that access files through WebDAV, with their links (HTML).'"`
}

func GetMessages

func GetMessages(ctx context.Context) *Messages

func (*Messages) WebDavAccess

func (m *Messages) WebDavAccess(url string) h.RawHTML

type Mount

type Mount struct {
	Name    string
	Dir     func(r *http.Request) (string, error)
	Allowed func(r *http.Request, a MountAccess) bool
	// Hidden says whether the path, in the mount ("/.git/config"), is not
	// served.
	Hidden func(p string) bool
}

Mount is a directory of each request, shown in the WebDAV at /Name: the draft of the user's files, say. Dir is the directory of the request; Allowed says whether the request may do what it asks (MountAccess: the path, the destination of a COPY or a MOVE, its method in r). Hidden paths (".git") are not served.

type MountAccess

type MountAccess struct {
	Path  string
	Dest  string
	Write bool
}

MountAccess is what a request asks of a mount: its path in it ("/a.css"), where a COPY or a MOVE puts it, in the same mount ("" otherwise), and whether it changes the files (Write; r.Method says how).

type RefUpdate

type RefUpdate struct {
	Old, New, Ref string
}

RefUpdate is a ref a push changes: from Old to New (a zero id: created or deleted).

Directories

Path Synopsis
Package user_docs is the documentation of github.com/go-rvq/rvq/admin/packages/fs-tools for whoever uses the admin (userdocs), in en/ and pt-BR/.
Package user_docs is the documentation of github.com/go-rvq/rvq/admin/packages/fs-tools for whoever uses the admin (userdocs), in en/ and pt-BR/.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址