api

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Copyright © 2023 Thomas von Dein

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const ApiVersion string = "/v1"
View Source
const Bucket string = "data"

Variables

View Source
var (
	Apikeys []cfg.Apicontext
)

these vars can be savely global, since they don't change ever

View Source
var Sessionstore *session.Store

sessions are context specific and can be global savely

Functions

func AuthErrHandler

func AuthErrHandler(ctx *fiber.Ctx, err error) error

make sure we always return JSON encoded errors

func AuthSetApikeys

func AuthSetApikeys(keys []cfg.Apicontext)

fill from server: accepted keys

func AuthValidateAPIKey

func AuthValidateAPIKey(c *fiber.Ctx, key string) (bool, error)

validator hook, called by fiber via server keyauth.New()

func AuthValidateOnetimeKey

func AuthValidateOnetimeKey(c *fiber.Ctx, key string, db *Db) (bool, error)

validator hook, validates incoming api key against form id, which also acts as onetime api key

func BackgroundCleaner

func BackgroundCleaner(conf *cfg.Config, db *Db) chan bool

func DeleteExpiredUploads

func DeleteExpiredUploads(conf *cfg.Config, db *Db) error

func FormCreate

func FormCreate(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

func FormDelete

func FormDelete(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

delete form

func FormDescribe

func FormDescribe(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

returns just one form obj + error code

func FormModify added in v0.0.2

func FormModify(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

func FormPage

func FormPage(c *fiber.Ctx, cfg *cfg.Config, db *Db, shallexpire bool) error

Render the upload html form. Template given by --formpage, stored as text in cfg.Formpage. It will be rendered using golang's template engine, data to be filled in is the form matching the given id.

func FormsList

func FormsList(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

returns the whole list + error code, no post processing by server

func IsExpired

func IsExpired(conf *cfg.Config, start time.Time, duration string) bool
Calculate   if  time   is   up  based   on   start  time.Time   and
duration. Returns  true if time  is expired. Start time  comes from
the database.

aka:

if(now - start) >= duration { time is up}

func JsonStatus

func JsonStatus(c *fiber.Ctx, code int, msg string) error

Wrapper to respond with proper json status, message and code, shall be prepared and called by the handlers directly.

func Log

func Log(format string, values ...any)

vaious helbers

func ProcessFormFiles

func ProcessFormFiles(cfg *cfg.Config, members []string, id string) (string, string, error)

generate return url. in case of multiple files, zip and remove them

func Runserver

func Runserver(conf *cfg.Config, args []string) error

func SaveFormFiles

func SaveFormFiles(c *fiber.Ctx, cfg *cfg.Config, files []*multipart.FileHeader, id string) ([]string, error)

Extract form file[s] and store them on disk, returns a list of files

func SendResponse

func SendResponse(c *fiber.Ctx, msg string, err error) error

Used for non json-aware handlers, called by server

func Sendmail

func Sendmail(c *cfg.Config, recipient string, body string, subject string) error

Send an email via an external mail gateway. SMTP Auth is required. Errors may occur with a time delay, like server timeouts etc. So only call it detached via go routine.

func SessionGetApicontext

func SessionGetApicontext(c *fiber.Ctx) (string, error)

Retrieve the API Context name from the session, assuming is has been successfully authenticated. However, if there are no api contexts defined, we'll use 'default' (set in auth.validateAPIKey()).

If there's no apicontext in the session, assume unauth user, return ""

func SessionGetFormId

func SessionGetFormId(c *fiber.Ctx) (string, error)

Retrieve the formid (aka onetime api key) from the session. It is configured if an upload request has been successfully authenticated using a onetime key.

func SetupAuthStore

func SetupAuthStore(conf *cfg.Config, db *Db) func(*fiber.Ctx) error

func SetupServer

func SetupServer(conf *cfg.Config) *fiber.App

func Status added in v0.0.3

func Status(c *fiber.Ctx, cfg *cfg.Config) error

func Ts

func Ts() string

func UploadDelete

func UploadDelete(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

delete file, id dir and db entry

func UploadDescribe

func UploadDescribe(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

returns just one upload obj + error code, no post processing by server

func UploadFetch

func UploadFetch(c *fiber.Ctx, cfg *cfg.Config, db *Db, shallExpire ...bool) error

func UploadModify added in v0.0.2

func UploadModify(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

func UploadPost

func UploadPost(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

func UploadsList

func UploadsList(c *fiber.Ctx, cfg *cfg.Config, db *Db) error

returns the whole list + error code, no post processing by server

func ZipDir

func ZipDir(directory, zipfilename string) error

Create a zip archive from a directory FIXME: -e option, if any, goes here

Types

type Db

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

wrapper for bolt db

func NewDb

func NewDb(c *cfg.Config) (*Db, error)

func (*Db) Close

func (db *Db) Close()

func (*Db) Delete

func (db *Db) Delete(apicontext string, id string) error

func (*Db) Get

func (db *Db) Get(apicontext string, id string, t int) (*common.Response, error)

we only return one obj here, but could return more later FIXME: turn the id into a filter and call (Uploads|Forms)List(), same code!

func (*Db) Insert

func (db *Db) Insert(id string, entry common.Dbentry) error

func (*Db) List

func (db *Db) List(apicontext string, filter string, query string, t int) (*common.Response, error)

func (*Db) Lookup

func (db *Db) Lookup(apicontext string, id string, t int) (*common.Response, error)

a wrapper around Lookup() which extracts the 1st upload, if any

type Id

type Id struct {
	Id string `json:"name" xml:"name" form:"name"`
}

incoming id

type Meta

type Meta struct {
	Expire string `json:"expire" form:"expire"`
}

Binding from JSON, data coming from user, not tainted

type SetContext

type SetContext struct {
	Apicontext string `json:"apicontext" form:"apicontext"`
	Query      string `json:"query" form:"query"`
}

Jump to

Keyboard shortcuts

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