api

package
v0.0.0-...-2d054f7 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SameSiteDefaultMode http.SameSite = iota + 1
	SameSiteLaxMode
	SameSiteStrictMode
	SameSiteNoneMode
)
View Source
const TimeFormat = time.RFC3339 // "2006-01-02T15:04:05-0700"

TimeFormat (RFC3339)

Variables

View Source
var Branch string
View Source
var BuildNr string
View Source
var Buildtime int64
View Source
var ExampleTime = "2006-01-02T15:04:05-07:00"
View Source
var Publish func(topic string, data []byte)
View Source
var Urls = []string{"http://localhost/"}

Only use host API calls for export

View Source
var Version string

Functions

func CheckToken

func CheckToken(t string) (*jwt.Token, error)

func DeleteActuator

func DeleteActuator(resp http.ResponseWriter, req *http.Request, params routing.Params)

DeleteActuator implements DELETE /actuators/{actuatorID}

func DeleteApp

func DeleteApp(resp http.ResponseWriter, req *http.Request, params routing.Params)

DeleteApp implements DELETE /apps/{app_id}?keepConfig={true | false}

func DeleteCloud

func DeleteCloud(resp http.ResponseWriter, req *http.Request, params routing.Params)

DeleteCloud implements DELETE /clouds/{cloudID}

func DeleteCodec

func DeleteCodec(resp http.ResponseWriter, req *http.Request, params routing.Params)

DeleteCodec implements DELETE /codecs/{id}

func DeleteCurrentDevice

func DeleteCurrentDevice(resp http.ResponseWriter, req *http.Request, params routing.Params)

DeleteCurrentDevice implements DELETE /device

func DeleteDevice

func DeleteDevice(resp http.ResponseWriter, req *http.Request, params routing.Params)

DeleteDevice implements DELETE /devices/{deviceID}

func DeleteDeviceActuator

func DeleteDeviceActuator(resp http.ResponseWriter, req *http.Request, params routing.Params)

DeleteDeviceActuator implements DELETE /devices/{deviceID}/actuators/{actuatorID}

func DeleteDeviceSensor

func DeleteDeviceSensor(resp http.ResponseWriter, req *http.Request, params routing.Params)

DeleteDeviceSensor implements DELETE /devices/{deviceID}/sensors/{sensorID}

func DeleteSensor

func DeleteSensor(resp http.ResponseWriter, req *http.Request, params routing.Params)

DeleteSensor implements DELETE /sensors/{sensorID}

func GetActuator

func GetActuator(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetActuator implements GET /actuators/{actuatorID}

func GetActuatorValue

func GetActuatorValue(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetActuatorValue implements GET /actuators/{actuatorID}/value

func GetActuatorValues

func GetActuatorValues(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetActuatorValues implements GET /actuators/{actuatorID}/values

func GetActuators

func GetActuators(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetActuators implements GET /actuators

func GetApp

func GetApp(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetApp implements GET /apps/{app_id} GetApp implements GET /apps/{app_id}?install_logs

func GetApps

func GetApps(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetApps implements GET /apps

func GetCloud

func GetCloud(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetCloud implements GET /clouds/{cloudID}

func GetCloudEvents

func GetCloudEvents(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetCloudEvents implements GET /clouds/{cloudID}/events

func GetCloudStatus

func GetCloudStatus(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetCloudStatus implements GET /clouds/{cloudID}/status

func GetClouds

func GetClouds(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetClouds implements GET /clouds

func GetCodecs

func GetCodecs(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetCodecs implements GET /codecs

func GetCurrentDevice

func GetCurrentDevice(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetCurrentDevice implements GET /device

func GetCurrentDeviceID

func GetCurrentDeviceID(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetCurrentDeviceID implements GET /device/id

func GetCurrentDeviceMeta

func GetCurrentDeviceMeta(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetCurrentDeviceMeta implements GET /device/meta

func GetCurrentDeviceName

func GetCurrentDeviceName(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetCurrentDeviceName implements GET /device/name

func GetDevice

func GetDevice(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDevice implements GET /devices/{deviceID}

func GetDeviceActuator

func GetDeviceActuator(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDeviceActuator implements GET /devices/{deviceID}/actuators/{actuatorID}

func GetDeviceActuatorValue

func GetDeviceActuatorValue(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDeviceActuatorValue implements GET /devices/{deviceID}/actuators/{actuatorID}/value

func GetDeviceActuatorValues

func GetDeviceActuatorValues(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDeviceActuatorValues implements GET /devices/{deviceID}/actuators/{actuatorID}/values

func GetDeviceActuators

func GetDeviceActuators(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDeviceActuators implements GET /devices/{deviceID}/actuators

func GetDeviceMeta

func GetDeviceMeta(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDeviceMeta implements GET /devices/{deviceID}/meta

func GetDeviceName

func GetDeviceName(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDeviceName implements GET /devices/{deviceID}/name

func GetDeviceSensor

func GetDeviceSensor(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDeviceSensor implements GET /devices/{deviceID}/sensors/{sensorID}

func GetDeviceSensorValue

func GetDeviceSensorValue(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDeviceSensorValue implements GET /devices/{deviceID}/sensors/{sensorID}/value

func GetDeviceSensorValues

func GetDeviceSensorValues(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDeviceSensorValues implements GET /devices/{deviceID}/sensors/{sensorID}/values

func GetDeviceSensors

func GetDeviceSensors(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDeviceSensors implements GET /devices/{deviceID}/sensors

func GetDevices

func GetDevices(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetDevices implements GET /devices

func GetExportAllInOne

func GetExportAllInOne(resp http.ResponseWriter, req *http.Request, params routing.Params)

func GetExportBins

func GetExportBins(resp http.ResponseWriter, req *http.Request, params routing.Params)

func GetExportTree

func GetExportTree(resp http.ResponseWriter, req *http.Request, params routing.Params)

func GetLocalID

func GetLocalID() string

GetLocalID returns the ID of this device

func GetMessages

func GetMessages(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetMessages implements GET /devices

func GetPermissions

func GetPermissions(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetPermissions implements GET /auth/permissions

func GetRefereshToken

func GetRefereshToken(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetRefereshToken implements POST /auth/retoken it takes a valid token and generate a new valid token it is used to keep the user logged in without asking for credentials every time the token gets expired

func GetSensor

func GetSensor(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetSensor implements GET /sensors/{sensorID}

func GetSensorValue

func GetSensorValue(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetSensorValue implements GET /sensors/{sensorID}/value

func GetSensorValues

func GetSensorValues(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetSensorValues implements GET /sensors/{sensorID}/values

func GetSensors

func GetSensors(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetSensors implements GET /sensors

func GetToken

func GetToken(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetToken implements POST /auth/token

func GetUpdateApp

func GetUpdateApp(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetUpdateApp implements GET /update/:app_id

func GetUserProfile

func GetUserProfile(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetUserProfile implements GET /auth/profile

func HandleAppProxyRequest

func HandleAppProxyRequest(resp http.ResponseWriter, req *http.Request, params routing.Params)

HandleAppProxyRequest implements GET, POST, PUT and DELETE /apps/{app_id}/*file_path

func IsAuthorized

func IsAuthorized(endpoint routing.Handle, checkIPWhiteList bool) routing.Handle

IsAuthorized checks if the given request is valid for the API call

func IsDockerSubnet

func IsDockerSubnet(ip net.IP) (bool, error)

IsDockerSubnet calls `docker network inspect wazigate` to get the wazigate subnet from docker. It checks if the ip is in the subnet, because all containers from docker are whitelisted for the API.

func Logout

func Logout(resp http.ResponseWriter, req *http.Request, params routing.Params)

Logout implements GET /auth/logout

func PostActuator

func PostActuator(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostActuator implements POST /actuators

func PostActuatorMeta

func PostActuatorMeta(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostActuatorMeta implements POST /actuators/{actuatorID}/meta

func PostActuatorName

func PostActuatorName(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostActuatorName implements POST /actuators/{actuatorID}/name

func PostActuatorValue

func PostActuatorValue(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostActuatorValue implements POST /actuators/{actuatorID}/value

func PostActuatorValues

func PostActuatorValues(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostActuatorValues implements POST /actuators/{actuatorID}/values

func PostApp

func PostApp(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostApp implements POST /apps/{app_id} action={start | stop} PostApp implements POST /apps/{app_id} restart={"always" | "on-failure" | "unless-stopped" | "no"}

func PostApps

func PostApps(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostApps implements POST /apps It installs a new app

func PostCloudMQTTAddr

func PostCloudMQTTAddr(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCloudMQTTAddr implements POST /clouds/{cloudID}/mqtt

func PostCloudName

func PostCloudName(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCloudMQTTAddr implements POST /clouds/{cloudID}/name

func PostCloudPaused

func PostCloudPaused(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCloudPaused implements POST /clouds/{cloudID}/paused

func PostCloudRESTAddr

func PostCloudRESTAddr(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCloudRESTAddr implements POST /clouds/{cloudID}/rest

func PostCloudToken

func PostCloudToken(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCloudToken implements POST /clouds/{cloudID}/token

func PostCloudUsername

func PostCloudUsername(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCloudUsername implements POST /clouds/{cloudID}/username

func PostClouds

func PostClouds(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostClouds implements POST /clouds

func PostCodec

func PostCodec(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCodec implements POST /codecs/{id}

func PostCodecs

func PostCodecs(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCodecs implements POST /codecs

func PostCurrentDeviceID

func PostCurrentDeviceID(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCurrentDeviceID implements POST /device/id

func PostCurrentDeviceMeta

func PostCurrentDeviceMeta(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCurrentDeviceMeta implements POST /device/meta

func PostCurrentDeviceName

func PostCurrentDeviceName(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostCurrentDeviceName implements POST /device/name

func PostDevice

func PostDevice(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDevice implements POST /devices/{deviceID}

func PostDeviceActuator

func PostDeviceActuator(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceActuator implements POST /devices/{deviceID}/actuators

func PostDeviceActuatorMeta

func PostDeviceActuatorMeta(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceActuatorMeta implements POST /devices/{deviceID}/actuators/{actuatorID}/meta

func PostDeviceActuatorName

func PostDeviceActuatorName(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceActuatorName implements POST /devices/{deviceID}/actuators/{actuatorID}/name

func PostDeviceActuatorValue

func PostDeviceActuatorValue(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceActuatorValue implements POST /devices/{deviceID}/actuators/{actuatorID}/value

func PostDeviceActuatorValues

func PostDeviceActuatorValues(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceActuatorValues implements POST /devices/{deviceID}/actuators/{actuatorID}/values

func PostDeviceMeta

func PostDeviceMeta(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceMeta implements POST /devices/{deviceID}/meta

func PostDeviceName

func PostDeviceName(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceName implements POST /devices/{deviceID}/name

func PostDeviceSensor

func PostDeviceSensor(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceSensor implements POST /devices/{deviceID}/sensors

func PostDeviceSensorMeta

func PostDeviceSensorMeta(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceSensorMeta implements POST /devices/{deviceID}/sensors/{sensorID}/meta

func PostDeviceSensorMetaField

func PostDeviceSensorMetaField(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceSensorMetaField implements POST /devices/{deviceID}/sensors/{sensorID}/meta/{meta}

func PostDeviceSensorName

func PostDeviceSensorName(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceSensorName implements POST /devices/{deviceID}/sensors/{sensorID}/name

func PostDeviceSensorValue

func PostDeviceSensorValue(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceSensorValue implements POST /devices/{deviceID}/sensors/{sensorID}/value

func PostDeviceSensorValues

func PostDeviceSensorValues(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDeviceSensorValues implements POST /devices/{deviceID}/sensors/{sensorID}/values

func PostDevices

func PostDevices(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostDevices implements POST /devices

func PostMessage

func PostMessage(resp http.ResponseWriter, req *http.Request, params routing.Params)

func PostSensor

func PostSensor(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostSensor implements POST /sensors

func PostSensorMeta

func PostSensorMeta(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostSensorMeta implements POST /sensors/{sensorID}/meta

func PostSensorName

func PostSensorName(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostSensorName implements POST /sensors/{sensorID}/name

func PostSensorValue

func PostSensorValue(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostSensorValue implements POST /sensors/{sensorID}/value

func PostSensorValues

func PostSensorValues(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostSensorValues implements POST /sensors/{sensorID}/values

func PostUpdateApp

func PostUpdateApp(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostUpdateApp implements POST /update/:app_id it updates the given app by pulling the latest images from docker hub and replace with the current one (uninstall the current version and install a new one ;]) please note that it will replace docker-compose.yml and package.json files with the new version as well.

func PostUserProfile

func PostUserProfile(resp http.ResponseWriter, req *http.Request, params routing.Params)

PostUserProfile implements POST /auth/profile

func SysClearAll

func SysClearAll(resp http.ResponseWriter, req *http.Request, params routing.Params)

SysClearAll implements PUT /sys/clear_all

func SysDeleteLog

func SysDeleteLog(resp http.ResponseWriter, req *http.Request, params routing.Params)

SysDeleteLog implements DELETE /sys/log/{log_name}

func SysGetBuildNr

func SysGetBuildNr(resp http.ResponseWriter, req *http.Request, params routing.Params)

func SysGetInfo

func SysGetInfo(resp http.ResponseWriter, req *http.Request, params routing.Params)

func SysGetLog

func SysGetLog(resp http.ResponseWriter, req *http.Request, params routing.Params)

SysGetLog implements GET /sys/log/{log_name}

func SysGetLogs

func SysGetLogs(resp http.ResponseWriter, req *http.Request, params routing.Params)

SysGetLogs implements GET /sys/logs

func SysGetUptime

func SysGetUptime(resp http.ResponseWriter, req *http.Request, params routing.Params)

SysGetUptime implements GET /sys/uptime

func SysGetVersion

func SysGetVersion(resp http.ResponseWriter, req *http.Request, params routing.Params)

func SysSetNewTimezone

func SysSetNewTimezone(resp http.ResponseWriter, req *http.Request, params routing.Params)

Types

type Actuator

type Actuator struct {
	ID       string      `json:"id" bson:"id"`
	Name     string      `json:"name" bson:"name"`
	Modified time.Time   `json:"modified" bson:"modified"`
	Created  time.Time   `json:"created" bson:"created"`
	Time     time.Time   `json:"time" bson:"time"`
	Value    interface{} `json:"value" bson:"value"`
	Meta     Meta        `json:"meta" bson:"meta"`
}

Actuator represents a Waziup actuator

type ActuatorValue

type ActuatorValue struct {
	ID         bson.ObjectId `json:"id" bson:"_id"`
	Value      interface{}   `json:"value" bson:"value"`
	DeviceID   string        `json:"deviceId" bson:"deviceId"`
	ActuatorID string        `json:"actuatorId" bson:"actuatorId"`
}

ActuatorValue represents a Waziup actuator data value

func (*ActuatorValue) MarshalJSON

func (v *ActuatorValue) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for ActuatorValue

type Device

type Device struct {
	Name      string      `json:"name" bson:"name"`
	ID        string      `json:"id" bson:"_id"`
	Sensors   []*Sensor   `json:"sensors" bson:"sensors"`
	Actuators []*Actuator `json:"actuators" bson:"actuators"`
	Modified  time.Time   `json:"modified" bson:"modified"`
	Created   time.Time   `json:"created" bson:"created"`
	Meta      Meta        `json:"meta" bson:"meta"`
}

Device represents a Waziup Device

type Info

type Info struct {
	Version   string `json:"version"`
	Branch    string `json:"branch"`
	Buildtime int64  `json:"buildtime"`
}

type Meta

type Meta map[string]interface{}

Meta holds entity metadata.

func (Meta) Kind

func (meta Meta) Kind() string

type ProbeMeta

type ProbeMeta struct {
	Kind     string `json:"kind" bson:"kind"`
	Quantity string `json:"quantity" bson:"quantity"`
	Unit     string `json:"unit" bson:"unit"`
}

type Query

type Query struct {
	Limit int64
	From  time.Time
	To    time.Time
	Size  int64
}

Query is used to range or limit query results

type Sensor

type Sensor struct {
	ID       string      `json:"id" bson:"id"`
	Name     string      `json:"name" bson:"name"`
	Modified time.Time   `json:"modified" bson:"modified"`
	Created  time.Time   `json:"created" bson:"created"`
	Time     time.Time   `json:"time" bson:"time"`
	Value    interface{} `json:"value" bson:"value"`
	Meta     Meta        `json:"meta" bson:"meta"`
}

Sensor represents a Waziup sensor

type SensorValue

type SensorValue struct {
	ID       bson.ObjectId `json:"id" bson:"_id"`
	Value    interface{}   `json:"value" bson:"value"`
	DeviceID string        `json:"deviceId" bson:"deviceId"`
	SensorID string        `json:"sensorId" bson:"sensorId"`
}

SensorValue represents a Waziup sensor data value

func (*SensorValue) MarshalJSON

func (v *SensorValue) MarshalJSON() ([]byte, error)

MarshalJSON provides a custom json serialization for values, transforming

{_id: ..., value: ...}

to

{value: ..., time: ...}

type Value

type Value struct {
	Value interface{} `json:"value" bson:"value"`
	Time  time.Time   `json:"time" bson:"time"`
}

Value is one datapoint

Jump to

Keyboard shortcuts

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