api

package
v0.0.0-...-b63ba6b Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	GetHealth() (string, error)

	GetAliases() ([]Alias, error)
	GetAlias(id string) (Alias, error)
	GetAliasByID(id string) (Alias, error)
	GetAliasByPayloadID(id string) (Alias, error)
	AddAlias(name string, payloadID string) (Alias, error)
	DeleteAlias(id string) error

	GetLoots() ([]Loot, error)
	GetLoot(id string) (Loot, error)
	AddLoot(data string) (Loot, error)
	DeleteLoot(id string) error

	GetExecutions() ([]Execution, error)
	GetExecution(id string) (Execution, error)
	AddExecution(payloadID string, aliasID string) (Execution, error)
	DeleteExecution(id string) error

	GetInjections() ([]Injection, error)
	GetInjection(id string) (Injection, error)
	AddInjection(name string, content string) (Injection, error)
	DeleteInjection(id string) error

	GetPayloads() ([]Payload, error)
	GetPayload(id string) (Payload, error)
	AddPayload(name string, content string, contentType string) (Payload, error)
	DeletePayload(id string) error

	//Login doesn't return a user but a JWT token if the auth is successful
	Login(loginParam, passwordParam, otp string) (string, error)
	GetUserByName(name string) (User, error)
	GetUser(id string) (User, error)
	CreateOTP(userID string, secret string, otp string) (User, error)
	CreateUser(username, password string) (User, error)
	DeleteUser(id string) error
}

API is the general API interface used by all the API. All field must be implemented to be able to create a new "api" For example, the Local and HTTP APIs are using the same interface so we can call them with the same calling convention

type Alias

type Alias struct {
	ID         string    `json:"id" mapstructure:"id"`
	PayloadID  string    `json:"payload_id" mapstructure:"payload_id"` // Used for SRI (sub ressource integrity)
	Alias      string    `json:"alias" mapstructure:"alias"`           // Used for SRI (sub ressource integrity)
	CreatedAt  time.Time `json:"created_at" mapstructure:"created_at"`
	ModifiedAt time.Time `json:"modified_at" mapstructure:"modified_at"`
}

Alias represent the structure of the frontend-facing Aliases. Not the stored one. It offers an `FromStorage` function to convert itself from the storage payload.

func (Alias) FromStorage

func (p Alias) FromStorage(s models.Alias) Alias

FromStorage convert a models.Alias to an api.Alias

type Error

type Error int

Error defines all the errors that can be sent by the API.

const (
	Success Error = iota
	NotFound
	AlreadyExist
	DatabaseError
	InvalidInput
	MissingAuthorization
	InvalidAuthorization
	NotImplementedYet
)

Enum all the possible error from the API They all have String() representation

func (Error) Error

func (s Error) Error() string

type Execution

type Execution struct {
	ID          string    `json:"id" mapstructure:"id"`
	PayloadID   string    `json:"payload_id" mapstructure:"payload_id"`
	AliasID     string    `json:"alias_id" mapstructure:"alias_id"`
	TriggeredAt time.Time `json:"triggered_at" mapstructure:"triggered_at"`
}

Execution represent the structure of the frontend-facing Executions. Not the stored one. It offers an `FromStorage` function to convert itself from the storage payload.

func (Execution) FromStorage

func (l Execution) FromStorage(s models.Execution) Execution

FromStorage convert a models.Execution to an api.Execution

type Injection

type Injection struct {
	ID         string    `json:"id" mapstructure:"id"`
	Name       string    `json:"name" mapstructure:"name"`
	Content    string    `json:"content" mapstructure:"content"`
	CreatedAt  time.Time `json:"created_at" mapstructure:"created_at"`
	ModifiedAt time.Time `json:"modified_at" mapstructure:"modified_at"`
}

Injection represent the structure of the frontend-facing Executions. Not the stored one. It offers an `FromStorage` function to convert itself from the storage payload.

func (Injection) FromStorage

func (l Injection) FromStorage(s models.Injection) Injection

FromStorage convert a models.Injection to an api.Injection

type Loot

type Loot struct {
	ID        string    `json:"id" mapstructure:"id"`
	Data      string    `json:"data" mapstructure:"data"`
	CreatedAt time.Time `json:"created_at" mapstructure:"created_at"`
}

Loot represent the structure of the frontend-facing Executions. Not the stored one. It offers an `FromStorage` function to convert itself from the storage payload.

func (Loot) FromStorage

func (l Loot) FromStorage(s models.Loot) Loot

FromStorage convert a models.Loot to an api.Loot

type Payload

type Payload struct {
	ID          string           `json:"id" mapstructure:"id"`
	Name        string           `json:"name" mapstructure:"name"`
	Content     string           `json:"content" mapstructure:"content"`
	ContentType string           `json:"content_type" mapstructure:"content_type"`
	Hashes      models.SRIHashes `json:"hashes" mapstructure:"hashes"` // Used for SRI (sub ressource integrity)
	CreatedAt   time.Time        `json:"created_at" mapstructure:"created_at"`
	ModifiedAt  time.Time        `json:"modified_at" mapstructure:"modified_at"`
}

Payload represent the structure of the frontend-facing payload. Not the stored one. It offers an `FromStorage` function to convert itself from the storage payload.

func (Payload) FromStorage

func (p Payload) FromStorage(s models.Payload) Payload

FromStorage convert a models.Payload to an api.Payload

type Response

type Response struct {
	Error string      `json:"error,omitempty"`
	Data  interface{} `json:"data,omitempty"`
}

Response represent the main structure for ALL the response from the API The error must be empty if there wasn't an error They should also be only using the api.Error model Data can be anything but we try to not nest to many things

type User

type User struct {
	ID string `json:"id" mapstructure:"id"`
	// The username is the login of the user.
	Username string `json:"username" mapstructure:"username"`
	// Is 2FA enabled on this account.
	// It will be used to determine if it requires another step during the login process
	TwoFactorEnabled bool      `json:"two_factor_enabled" mapstructure:"two_factor_enabled"`
	CreatedAt        time.Time `json:"created_at" mapstructure:"created_at"`
	ModifiedAt       time.Time `json:"modified_at" mapstructure:"modified_at"`
}

User represent the structure of the frontend-facing user. Not the stored one. It offers an `FromStorage` function to convert itself from the storage payload.

func (User) FromStorage

func (u User) FromStorage(s models.User) User

FromStorage convert a models.User to an api.User

Directories

Path Synopsis
http

Jump to

Keyboard shortcuts

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