api

package
v0.0.13-beta Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSwitchPermission

func AddSwitchPermission(w http.ResponseWriter, r *http.Request)

Add a switchPermission to a given user, admin authentication required Request: `{"username": "x", "switch": "y"}` | Response: Response

func AddUser

func AddUser(w http.ResponseWriter, r *http.Request)

Creates a new user and gives him a provided password Request: `{"username": "x", "password": "y"}`, admin auth required

func AddUserPermission

func AddUserPermission(w http.ResponseWriter, r *http.Request)

Adds a given permission to a given user, admin authentication required If the permission is invalid, a `422` is returned Request: `{"username": "", "permission": ""}` | Response: Response

func CreateNewAutomation

func CreateNewAutomation(w http.ResponseWriter, r *http.Request)

Creates a new automation

func CreateNewHomescript

func CreateNewHomescript(w http.ResponseWriter, r *http.Request)

Creates a new Homescript

func DebugInfo

func DebugInfo(w http.ResponseWriter, r *http.Request)

Reading system debug information, admin authentication required Todo: read raspberry pi information

func DeleteAllUserNotifications

func DeleteAllUserNotifications(w http.ResponseWriter, r *http.Request)

func DeleteHomescriptById

func DeleteHomescriptById(w http.ResponseWriter, r *http.Request)

Deletes a Homescript by its Id, checks if it exists and if the user has permission to delete it

func DeleteUser

func DeleteUser(w http.ResponseWriter, r *http.Request)

Deletes a user given a valid username This also needs to delete any data that depends on this user in terms of a foreign key Admin auth required

func DeleteUserNotificationById

func DeleteUserNotificationById(w http.ResponseWriter, r *http.Request)

Delete a given notification from the current user

func FlushAllLogs

func FlushAllLogs(w http.ResponseWriter, r *http.Request)

Triggers deletion of ALL internal server logs, admin authentication required Request: empty | Response: Response

func FlushOldLogs

func FlushOldLogs(w http.ResponseWriter, r *http.Request)

Triggers deletion of internal server logs which are older than 30 days, admin authentication required Request: empty | Response: Response

func GetNotificationCount

func GetNotificationCount(w http.ResponseWriter, r *http.Request)

Returns a uin16 that indicates the number of notifications the current user has, no authentication required

func GetNotifications

func GetNotifications(w http.ResponseWriter, r *http.Request)

Returns a list containing notifications of the current user

func GetPowerStates

func GetPowerStates(w http.ResponseWriter, r *http.Request)

Returns a list of power states, no authentication required Request: empty | Response: `[{"switchId": "x", power: false}, {...}]`

func GetSwitches

func GetSwitches(w http.ResponseWriter, r *http.Request)

Returns a list of available switches as JSON to the user, no authentication required

func GetUserAutomations

func GetUserAutomations(w http.ResponseWriter, r *http.Request)

Returns a list of all automations set up by the current user

func GetUserDetails

func GetUserDetails(w http.ResponseWriter, r *http.Request)

Returns the user's personal data, auth required

func GetUserPermissions

func GetUserPermissions(w http.ResponseWriter, r *http.Request)

Returns a list of strings which resemble permissions of the currently logged in user, authentication required Request: empty | Response: `["a", "b", "c"]`

func GetUserRoomsWithSwitches

func GetUserRoomsWithSwitches(w http.ResponseWriter, r *http.Request)

Returns the wanted response for the frontend

func GetUserSwitches

func GetUserSwitches(w http.ResponseWriter, r *http.Request)

Only returns switches which the user has access to, authentication required

func HealthCheck

func HealthCheck(w http.ResponseWriter, r *http.Request)

Runs a healthcheck of most systems on which the appplication relies on, will be used by e.g `Uptime Kuma`, no authentication required

func InitLogger

func InitLogger(logger *logrus.Logger)

func ListLogs

func ListLogs(w http.ResponseWriter, r *http.Request)

Returns a list of logging items in the logging table, admin authentication required

func ListPersonalHomescripts

func ListPersonalHomescripts(w http.ResponseWriter, r *http.Request)

Returns a list of homescripts which are owned by the current user

func ListUsers

func ListUsers(w http.ResponseWriter, r *http.Request)

Returns a list of users and their metadata, admin auth required

func ModifyHomescript

func ModifyHomescript(w http.ResponseWriter, r *http.Request)

Modifies the metadata of a given homescript

func PowerPostHandler

func PowerPostHandler(w http.ResponseWriter, r *http.Request)

API endpoint for manipulating power states and (de) activating sockets, authentication required Permission and switch permission is needed to interact with this endpoint

func RemoveSwitchPermission

func RemoveSwitchPermission(w http.ResponseWriter, r *http.Request)

Removes a given switch permission from a given user, admin authentication required Request: `{"username": "x", "switch": "y"}` | Response: Response

func RemoveUserPermission

func RemoveUserPermission(w http.ResponseWriter, r *http.Request)

Todo: unit tests for some of the subfunction Removes a given permission from a user, admin authentication required Request: `{"username": "x", "permission": "y"}` | Response: Response

func RunHomescriptString

func RunHomescriptString(w http.ResponseWriter, r *http.Request)

Runs any given Homescript as a string

func TestImageProxy

func TestImageProxy(w http.ResponseWriter, r *http.Request)

TEST IMAGE FETCHING MODULE

Types

type AddUserRequest

type AddUserRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type CreateHomescriptRequest

type CreateHomescriptRequest struct {
	Id                  string `json:"id"`
	Name                string `json:"name"`
	Description         string `json:"description"`
	QuickActionsEnabled bool   `json:"quickActionsEnabled"`
	SchedulerEnabled    bool   `json:"schedulerEnabled"`
	Code                string `json:"code"`
}

type DeleteNotificationByIdRequest

type DeleteNotificationByIdRequest struct {
	Id uint `json:"id"`
}

type HomescriptIdRequest

type HomescriptIdRequest struct {
	Id string `json:"id"`
}

type HomescriptLiveRunRequest

type HomescriptLiveRunRequest struct {
	Code string `json:"code"`
}

type HomescriptResponse

type HomescriptResponse struct {
	Success  bool                         `json:"success"`
	Exitcode int                          `json:"exitCode"`
	Message  string                       `json:"message"`
	Output   string                       `json:"output"`
	Errors   []homescript.HomescriptError `json:"error"`
}

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type NewAutomationRequest

type NewAutomationRequest struct {
	Name         string  `json:"name"`
	Description  string  `json:"description"`
	Hour         uint    `json:"hour"`   // 24 >= h >= 0 | Can only be used with minute, specifies the exact hour in which the automation will run, 0 is midnight, 15 is 3PM, 3 is 3AM -> 24h format
	Minute       uint    `json:"minute"` // 60 >= m >= 0 | Can only be used with hour, specifies the exact minute on which the automation will run
	Days         []uint8 `json:"days"`   //  6 >= d >= 0 | Can contain 7 elements at maximum, value `0` represents Sunday, value `6` represents Saturday
	HomescriptId string  `json:"homescriptId"`
}

type NotificationCountResponse

type NotificationCountResponse struct {
	NotificationCount uint16 `json:"count"`
}

type PowerRequest

type PowerRequest struct {
	Switch  string `json:"switch"`
	PowerOn bool   `json:"powerOn"`
}

type RemoveUserRequest

type RemoveUserRequest struct {
	Username string `json:"username"`
}

type Response

type Response struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Error   string `json:"error"`
}

type UserPermissionRequest

type UserPermissionRequest struct {
	Username   string `json:"username"`
	Permission string `json:"permission"`
}

type UserSwitchPermissionRequest

type UserSwitchPermissionRequest struct {
	Username string `json:"username"`
	Switch   string `json:"switch"`
}

Jump to

Keyboard shortcuts

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