Compare commits
2 commits
32b584d7d9
...
cecc8e7b2c
Author | SHA1 | Date | |
---|---|---|---|
snow flurry | cecc8e7b2c | ||
snow flurry | 794c6a925b |
33
README.md
33
README.md
|
@ -4,7 +4,7 @@ Server application that provides cloud-init metadata via the `nocloud-net` provi
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
Only sqlite3 dev libraries are required for Diesel.
|
Only sqlite3 dev libraries are required for sea-orm.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
@ -20,33 +20,4 @@ This outputs the API key and the relevant config snippet you'll need to add to `
|
||||||
|
|
||||||
All API endpoints require an `X-API-Key` header with the key generated above, and for the API client to be connected via localhost. \todo Allow overriding the latter requirement, if needed
|
All API endpoints require an `X-API-Key` header with the key generated above, and for the API client to be connected via localhost. \todo Allow overriding the latter requirement, if needed
|
||||||
|
|
||||||
To create an instance (all requests sent to `http://[::1]`):
|
\todo HTTP API endpoints/usage
|
||||||
```
|
|
||||||
> POST /_yui/instances HTTP/1.1
|
|
||||||
> X-API-Key: Your_API_Key
|
|
||||||
> Content-type: application/json
|
|
||||||
> [...]
|
|
||||||
>
|
|
||||||
> {
|
|
||||||
> "name": "instance_hostname",
|
|
||||||
> "os_name": "netbsd|debian|invalid",
|
|
||||||
> "mac_address": "0a:42:01:23:45:67"
|
|
||||||
> }
|
|
||||||
>
|
|
||||||
< HTTP/1.1 201 Created
|
|
||||||
< Content-type: application/json
|
|
||||||
< [...]
|
|
||||||
<
|
|
||||||
< {
|
|
||||||
< "error": null,
|
|
||||||
< "instances": [
|
|
||||||
< {
|
|
||||||
< "id": 591750913,
|
|
||||||
< "name": "instance_hostname",
|
|
||||||
< "os_name": "netbsd|debian|invalid",
|
|
||||||
< "mac_address": "0a:42:01:23:45:67"
|
|
||||||
< }
|
|
||||||
< ]
|
|
||||||
< }
|
|
||||||
}
|
|
||||||
```
|
|
|
@ -10,7 +10,9 @@ pub struct Model {
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub hostname: String,
|
pub hostname: String,
|
||||||
pub mac_address: String,
|
pub mac_address: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub ssh_keys: Option<String>,
|
pub ssh_keys: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub user_data: Option<Vec<u8>>,
|
pub user_data: Option<Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::Instances;
|
||||||
use rocket::serde::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use rocket_db_pools::Connection;
|
use rocket_db_pools::Connection;
|
||||||
use sea_orm::ActiveValue::{NotSet, Set};
|
use sea_orm::ActiveValue::{NotSet, Set};
|
||||||
|
use sea_orm::QuerySelect;
|
||||||
use sea_orm::{
|
use sea_orm::{
|
||||||
ActiveModelTrait, ColumnTrait, EntityTrait, ModelTrait, PaginatorTrait, QueryFilter,
|
ActiveModelTrait, ColumnTrait, EntityTrait, ModelTrait, PaginatorTrait, QueryFilter,
|
||||||
};
|
};
|
||||||
|
@ -97,7 +98,13 @@ pub async fn get_instances(
|
||||||
db: Connection<Instances>,
|
db: Connection<Instances>,
|
||||||
_api: APIUser,
|
_api: APIUser,
|
||||||
) -> Result<Json<InstanceResponse>, APIError> {
|
) -> Result<Json<InstanceResponse>, APIError> {
|
||||||
match instance_info::Entity::find().all(&*db).await {
|
match instance_info::Entity::find()
|
||||||
|
.column(instance_info::Column::Id)
|
||||||
|
.column(instance_info::Column::MacAddress)
|
||||||
|
.column(instance_info::Column::Hostname)
|
||||||
|
.all(&*db)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(v) => Ok(Json(InstanceResponse::new(v))),
|
Ok(v) => Ok(Json(InstanceResponse::new(v))),
|
||||||
Err(err) => Err(api_err!(
|
Err(err) => Err(api_err!(
|
||||||
InternalServerError,
|
InternalServerError,
|
||||||
|
|
Loading…
Reference in a new issue