Display the configured agents on the home page
This commit is contained in:
parent
fcdf259bb9
commit
f7a3dc3e8d
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
agents:
|
||||
- 'http://localhost:9000'
|
||||
'local':
|
||||
url: 'http://localhost:9000'
|
||||
projects:
|
||||
'janky':
|
||||
filename: 'ci.janky.yml'
|
||||
|
|
|
@ -93,6 +93,7 @@ struct Project {
|
|||
*/
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct Agent {
|
||||
name: String,
|
||||
url: Url,
|
||||
capabilities: Vec<janky::Capability>,
|
||||
}
|
||||
|
@ -113,9 +114,14 @@ impl Agent {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
struct AgentConfig {
|
||||
url: Url,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct ServerConfig {
|
||||
agents: Vec<Url>,
|
||||
agents: HashMap<String, AgentConfig>,
|
||||
projects: HashMap<String, Project>,
|
||||
}
|
||||
|
||||
|
@ -128,7 +134,7 @@ impl ServerConfig {
|
|||
impl Default for ServerConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
agents: vec![],
|
||||
agents: HashMap::default(),
|
||||
projects: HashMap::default(),
|
||||
}
|
||||
}
|
||||
|
@ -188,14 +194,15 @@ async fn main() -> Result<(), tide::Error> {
|
|||
}
|
||||
}
|
||||
|
||||
for url in &config.agents {
|
||||
debug!("Requesting capabilities from agent: {}", url);
|
||||
let response: janky::CapsResponse = reqwest::get(url.join("/api/v1/capabilities")?)
|
||||
for (name, agent) in config.agents.iter() {
|
||||
debug!("Requesting capabilities from agent: {:?}", agent);
|
||||
let response: janky::CapsResponse = reqwest::get(agent.url.join("/api/v1/capabilities")?)
|
||||
.await?
|
||||
.json()
|
||||
.await?;
|
||||
state.agents.push(Agent {
|
||||
url: url.clone(),
|
||||
name: name.clone(),
|
||||
url: agent.url.clone(),
|
||||
capabilities: response.caps,
|
||||
});
|
||||
}
|
||||
|
@ -251,6 +258,7 @@ mod tests {
|
|||
let needs: Vec<String> = vec!["rspec".into(), "git".into(), "dotnet".into()];
|
||||
let capabilities = vec![Capability::with_name("rustc")];
|
||||
let agent = Agent {
|
||||
name: "test".into(),
|
||||
url: Url::parse("http://localhost").unwrap(),
|
||||
capabilities,
|
||||
};
|
||||
|
@ -262,6 +270,7 @@ mod tests {
|
|||
let needs: Vec<String> = vec!["dotnet".into()];
|
||||
let capabilities = vec![Capability::with_name("dotnet")];
|
||||
let agent = Agent {
|
||||
name: "test".into(),
|
||||
url: Url::parse("http://localhost").unwrap(),
|
||||
capabilities,
|
||||
};
|
||||
|
@ -273,6 +282,7 @@ mod tests {
|
|||
let needs: Vec<String> = vec!["rspec".into(), "git".into(), "dotnet".into()];
|
||||
let capabilities = vec![Capability::with_name("dotnet")];
|
||||
let agent = Agent {
|
||||
name: "test".into(),
|
||||
url: Url::parse("http://localhost").unwrap(),
|
||||
capabilities,
|
||||
};
|
||||
|
@ -287,6 +297,7 @@ mod tests {
|
|||
Capability::with_name("rspec"),
|
||||
];
|
||||
let agent = Agent {
|
||||
name: "test".into(),
|
||||
url: Url::parse("http://localhost").unwrap(),
|
||||
capabilities,
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@ use tide::{Body, Request};
|
|||
pub async fn index(req: Request<AppState<'_>>) -> Result<Body, tide::Error> {
|
||||
let params = json!({
|
||||
"page": "home",
|
||||
"agents" : req.state().agents,
|
||||
"config" : req.state().config,
|
||||
});
|
||||
|
||||
|
|
|
@ -11,38 +11,58 @@
|
|||
{{> _navbar }}
|
||||
|
||||
<div class="cover-container d-flex h-100 p-3 mx-auto flex-column">
|
||||
<main role="main" class="inner cover">
|
||||
<div id="projects">
|
||||
<table class="table table-dark table-striped">
|
||||
<thead>
|
||||
<td>
|
||||
<strong>Name</strong>
|
||||
</td>
|
||||
<td>
|
||||
<strong>Description</strong>
|
||||
</td>
|
||||
<td>
|
||||
<strong>Actions</strong>
|
||||
</td>
|
||||
</thead>
|
||||
{{#each config.projects}}
|
||||
<tr>
|
||||
<td>
|
||||
<a class="text-reset" href="/projects/{{@key}}"><strong>{{@key}}</strong></a>
|
||||
</td>
|
||||
<td>
|
||||
No Description
|
||||
</td>
|
||||
<td>
|
||||
<form method="POST" action="/api/v1/projects/{{@key}}">
|
||||
<input type="submit" value="Execute"/>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
<div class="row">
|
||||
<div class="col col-sm-2">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<td>Agents</td>
|
||||
</thead>
|
||||
{{#each agents}}
|
||||
<tr>
|
||||
<td>
|
||||
<span title="Capabilities: {{#each this.capabilities}}
|
||||
* {{this.name}} {{/each}}">
|
||||
{{this.name}}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
</div>
|
||||
<div class="col col-lg">
|
||||
<main role="main" class="inner cover"> <div id="projects">
|
||||
<table class="table table-dark table-striped">
|
||||
<thead>
|
||||
<td>
|
||||
<strong>Name</strong>
|
||||
</td>
|
||||
<td>
|
||||
<strong>Description</strong>
|
||||
</td>
|
||||
<td>
|
||||
<strong>Actions</strong>
|
||||
</td>
|
||||
</thead>
|
||||
{{#each config.projects}}
|
||||
<tr>
|
||||
<td>
|
||||
<a class="text-reset" href="/projects/{{@key}}"><strong>{{@key}}</strong></a>
|
||||
</td>
|
||||
<td>
|
||||
No Description
|
||||
</td>
|
||||
<td>
|
||||
<form method="POST" action="/api/v1/projects/{{@key}}">
|
||||
<input type="submit" value="Execute"/>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue