Documentation
¶
Overview ¶
Package api provides functions for handling http requests on the control server. This is used to respond to request from pixiecore, to serve files (kernel, initramfs, disk images) and to communicate with machines running the management os.
Index ¶
- func CreateNewVersion(uuid string, store database.Store) (images.Version, error)
- func DownloadImageFile(image *images.ImageModel, version string, w http.ResponseWriter)
- func ErrorWrite(w http.ResponseWriter, err error, msg string) error
- func GetName(w http.ResponseWriter, r *http.Request) (string, error)
- func GetTag(tag string, w http.ResponseWriter, r *http.Request) (string, error)
- func StartServer(machineStore database.Store, staticDir string, diskPath string, address string, ...)
- type API
- func (api_ *API) BootInform(w http.ResponseWriter, r *http.Request)
- func (api_ *API) CheckRole(route Route, next http.HandlerFunc) http.HandlerFunc
- func (api_ *API) CreateImage(w http.ResponseWriter, r *http.Request)
- func (api_ *API) CreateMachine(w http.ResponseWriter, r *http.Request)
- func (api_ *API) CreateUser(w http.ResponseWriter, r *http.Request)
- func (api_ *API) DeleteImage(w http.ResponseWriter, r *http.Request)
- func (api_ *API) DeleteMachine(w http.ResponseWriter, r *http.Request)
- func (api_ *API) DeleteUser(w http.ResponseWriter, r *http.Request)
- func (api_ *API) DownloadDiskImage(w http.ResponseWriter, r *http.Request)
- func (api_ *API) DownloadImage(w http.ResponseWriter, r *http.Request)
- func (api_ *API) DownloadLatestImage(w http.ResponseWriter, r *http.Request)
- func (api_ *API) GetImage(w http.ResponseWriter, r *http.Request)
- func (api_ *API) GetImagesByName(w http.ResponseWriter, r *http.Request)
- func (api_ *API) GetImagesByUser(w http.ResponseWriter, r *http.Request)
- func (api_ *API) GetLoggedInUser(w http.ResponseWriter, r *http.Request)
- func (api_ *API) GetMachine(w http.ResponseWriter, r *http.Request)
- func (api_ *API) GetMachines(w http.ResponseWriter, _ *http.Request)
- func (api_ *API) GetUser(w http.ResponseWriter, r *http.Request)
- func (api_ *API) GetUsers(w http.ResponseWriter, _ *http.Request)
- func (api_ *API) LoginGithub(w http.ResponseWriter, _ *http.Request)
- func (api_ *API) LoginGithubCallback(w http.ResponseWriter, r *http.Request)
- func (api_ *API) ModifyUser(w http.ResponseWriter, r *http.Request)
- func (api_ *API) RegisterImageDockerHandlers()
- func (api_ *API) RegisterImageHandlers()
- func (api_ *API) RegisterImagePackageHandlers()
- func (api_ *API) RegisterImageSetupHandlers()
- func (api_ *API) RegisterMachineHandlers()
- func (api_ *API) RegisterUserHandlers()
- func (api_ *API) RunDocker(w http.ResponseWriter, r *http.Request)
- func (api_ *API) ServeBootConfigurations(w http.ResponseWriter, r *http.Request)
- func (api_ *API) SetBootSetup(w http.ResponseWriter, r *http.Request)
- func (api_ *API) UpdateImage(w http.ResponseWriter, r *http.Request)
- func (api_ *API) UpdateMachine(w http.ResponseWriter, r *http.Request)
- func (api_ *API) UploadDiskImage(w http.ResponseWriter, r *http.Request)
- func (api_ *API) UploadImage(w http.ResponseWriter, r *http.Request)
- type Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateNewVersion ¶
CreateNewVersion creates a new version for a specified image
func DownloadImageFile ¶
func DownloadImageFile(image *images.ImageModel, version string, w http.ResponseWriter)
DownloadImageFile gets the specified version of the image off the disk and offers it to the client
func ErrorWrite ¶
func ErrorWrite(w http.ResponseWriter, err error, msg string) error
ErrorWrite writes the same error message on the HTTP stream and log
Types ¶
type API ¶
type API struct { Routes []Route // contains filtered or unexported fields }
API is a struct on which functions are defined that respond to request from either the management OS, or the end user (through some kind of interface). This struct holds state necessary for the request handlers.
func (*API) BootInform ¶
func (api_ *API) BootInform(w http.ResponseWriter, r *http.Request)
BootInform handles all incoming boot inform requests
func (*API) CheckRole ¶
func (api_ *API) CheckRole(route Route, next http.HandlerFunc) http.HandlerFunc
CheckRole verifies whether a user is allowed to use this particular route or not. lint:
func (*API) CreateImage ¶
func (api_ *API) CreateImage(w http.ResponseWriter, r *http.Request)
CreateImage creates an image based on a name Example request: POST user/Jan/image Example body: {"DiskUUID": "30DF-844C", "Name": "Fedora"} Example response: {"Name": "Fedora",
"Versions": [{"Version": "2021-11-01T00:11:22.38125222+01:00", "ImageModelID": 0}], "UUID": "eed13670-5974-4c98-b044-347e1f630bc5", "DiskUUID": "30DF-844C", "UserModelID": 0}
func (*API) CreateMachine ¶
func (api_ *API) CreateMachine(w http.ResponseWriter, r *http.Request)
CreateMachine creates the machine in the database and returns a JSON object representing it
func (*API) CreateUser ¶
func (api_ *API) CreateUser(w http.ResponseWriter, r *http.Request)
CreateUser creates a new user in the database Example request: user, {"name": "William Narchi",
"email", "w.narchi1@student.tudelft.nl", "role": "user"}
Response: Either an error message or success.
func (*API) DeleteImage ¶
func (api_ *API) DeleteImage(w http.ResponseWriter, r *http.Request)
DeleteImage removes an image based on its UUID Example request: DELETE image/57bf0cd3-c2bf-4257-acdd-b7f1c8633fcf Example response: Successfully deleted image
func (*API) DeleteMachine ¶
func (api_ *API) DeleteMachine(w http.ResponseWriter, r *http.Request)
DeleteMachine Deletes a machine from the database Example request: DELETE machine/[mac] Example response: Successfully deleted
func (*API) DeleteUser ¶
func (api_ *API) DeleteUser(w http.ResponseWriter, r *http.Request)
DeleteUser removes a user from the database Request: DELETE /user/[name] Response: Successfully deleted user
func (*API) DownloadDiskImage ¶
func (api_ *API) DownloadDiskImage(w http.ResponseWriter, r *http.Request)
DownloadDiskImage provides disk images for the management os to download
func (*API) DownloadImage ¶
func (api_ *API) DownloadImage(w http.ResponseWriter, r *http.Request)
DownloadImage offers the requested image to the respective client Example request: image/87f58936-9540-4dad-aba6-253f06142166/1635888918
func (*API) DownloadLatestImage ¶
func (api_ *API) DownloadLatestImage(w http.ResponseWriter, r *http.Request)
DownloadLatestImage offers the latest version Example request: image/87f58936-9540-4dad-aba6-253f06142166/latest
func (*API) GetImage ¶
func (api_ *API) GetImage(w http.ResponseWriter, r *http.Request)
GetImage gets any image based on its unique id. Example request: image/57bf0cd3-c2bf-4257-acdd-b7f1c8633fcf
Example response: { "Name": "Gentoo", "Versions": null, "UUID": "57bf0cd3-c2bf-4257-acdd-b7f1c8633fcf", "DiskUUID": "30DF-844C", "UserModelID": 1 }
func (*API) GetImagesByName ¶
func (api_ *API) GetImagesByName(w http.ResponseWriter, r *http.Request)
GetImagesByName gets any image based on the user who created it and human-readable name assigned to it. Example Request: user/Jan/images/Gentoo Example Response: [
{ "Name": "Gentoo", "Versions": null, "UUID": "57bf0cd3-c2bf-4257-acdd-b7f1c8633fcf", "DiskUUID": "30DF-844C", "UserModelID": 1 }
]
func (*API) GetImagesByUser ¶
func (api_ *API) GetImagesByUser(w http.ResponseWriter, r *http.Request)
GetImagesByUser fetches all the images of the given user Example request: user/Jan/images Example result: [
{ "Name": "Windows", "Versions "a9c11954-6161-410b-b238-c03df5c529e9", "DiskUUID": "30DF-844C", "UserModelID": 2 }, { "Name": "Arch Linux", "Versions": null, "UUID": "341b2c69-8776-4e54-9330-7c9692f7ed28", "DiskUUID": "30DF-844C", "UserModelID": 2 }
]
func (*API) GetLoggedInUser ¶
func (api_ *API) GetLoggedInUser(w http.ResponseWriter, r *http.Request)
GetLoggedInUser gets the currently logged-in user and returns it. Example request: user/me
func (*API) GetMachine ¶
func (api_ *API) GetMachine(w http.ResponseWriter, r *http.Request)
GetMachine GETs any machine in the database based on its MAC address Example message: machine/00:11:22:33:44:55:66 Example response: {"name": "Machine 1",
"Architecture": "x86_64", "MacAddresses": [{"Mac": "00:11:22:33:44:55:66}]}
func (*API) GetMachines ¶
func (api_ *API) GetMachines(w http.ResponseWriter, _ *http.Request)
GetMachines fetches all the machines from the database using a GET request Example request: machines Example response: {"name": "Machine 1",
"Architecture": "x86_64", "MacAddresses": [{"Mac": "00:11:22:33:44:55:66}]}
func (*API) GetUser ¶
func (api_ *API) GetUser(w http.ResponseWriter, r *http.Request)
GetUser fetches a user based on their name and returns it Example request: GET /user/[name] Response: {"Name": "Jan",
"Email": "v.d.vandebeek@student.tudelft.nl", "role": "admin"}
func (*API) GetUsers ¶
func (api_ *API) GetUsers(w http.ResponseWriter, _ *http.Request)
GetUsers fetches all the users from the database Example request: users Response: [{"Name": "Valentijn", "Email": "v.d.vandebeek@student.tudelft.nl",
"Role": "admin", "Image": null}
func (*API) LoginGithub ¶
func (api_ *API) LoginGithub(w http.ResponseWriter, _ *http.Request)
LoginGithub defines the entrypoint to start the OAuth flow
func (*API) LoginGithubCallback ¶
func (api_ *API) LoginGithubCallback(w http.ResponseWriter, r *http.Request)
LoginGithubCallback gets the token and creates the user model for the GitHub User
func (*API) ModifyUser ¶
func (api_ *API) ModifyUser(w http.ResponseWriter, r *http.Request)
ModifyUser modifies the metadata related to the user Request: PUT /user/[name] Response: the modified user
func (*API) RegisterImageDockerHandlers ¶
func (api_ *API) RegisterImageDockerHandlers()
RegisterImageDockerHandlers sets the metadata for each of the routes and registers them to the global handler
func (*API) RegisterImageHandlers ¶
func (api_ *API) RegisterImageHandlers()
RegisterImageHandlers sets the metadata for each of the routes and registers them to the global handler
func (*API) RegisterImagePackageHandlers ¶
func (api_ *API) RegisterImagePackageHandlers()
RegisterImagePackageHandlers runs the handlers which install the routes for the modules
func (*API) RegisterImageSetupHandlers ¶
func (api_ *API) RegisterImageSetupHandlers()
RegisterImageSetupHandlers sets the metadata for each of the routes and registers them to the global handler
func (*API) RegisterMachineHandlers ¶
func (api_ *API) RegisterMachineHandlers()
RegisterMachineHandlers sets the metadata for each of the routes and registers them to the global handler
func (*API) RegisterUserHandlers ¶
func (api_ *API) RegisterUserHandlers()
RegisterUserHandlers sets the metadata for each of the routes and registers them to the global handler
func (*API) RunDocker ¶
func (api_ *API) RunDocker(w http.ResponseWriter, r *http.Request)
RunDocker takes a Dockerfile and generates a bootable OS image Request request: /image/{uuid}/docker
func (*API) ServeBootConfigurations ¶
func (api_ *API) ServeBootConfigurations(w http.ResponseWriter, r *http.Request)
ServeBootConfigurations actually responds to requests from pixiecore.
func (*API) SetBootSetup ¶
func (api_ *API) SetBootSetup(w http.ResponseWriter, r *http.Request)
SetBootSetup adds an image to the schedule to be flashed onto the machine Example request: POST machine/52:54:00:d9:71:93/boot Example body: {"Version": 1636116090, "ImageUUID": "74368cec-7903-4233-87b7-564195619dce", "update": true}
Example response: { "MachineModelID": 1, "Version": 1636116090, "ImageUUID": "74368cec-7903-4233-87b7-564195619dce", "Update": true}
func (*API) UpdateImage ¶
func (api_ *API) UpdateImage(w http.ResponseWriter, r *http.Request)
UpdateImage changes some of the parameters of the image Example request: PUT image/57bf0cd3-c2bf-4257-acdd-b7f1c8633fcf Example response: the updated image
func (*API) UpdateMachine ¶
func (api_ *API) UpdateMachine(w http.ResponseWriter, r *http.Request)
UpdateMachine updates (or adds) the machine to the database.
Example of a JSON message:
{ "name": "Hello World", "Architecture": "x86_64", "Managed": true, "DiskUUIDs": null, "MacAddresses": [{ "Mac": "52:54:00:d9:71:15", "MachineModelID": 12 }] }
func (*API) UploadDiskImage ¶
func (api_ *API) UploadDiskImage(w http.ResponseWriter, r *http.Request)
UploadDiskImage allows the management os to upload disk images
func (*API) UploadImage ¶
func (api_ *API) UploadImage(w http.ResponseWriter, r *http.Request)
UploadImage takes the uploaded file and stores as a new version of the image Example request: image/87f58936-9540-4dad-aba6-253f06142166 -H "Content-Type: multipart/form-data"
-F "file=@/tmp/test3.img"
Example return: Successfully uploaded image: 134251234