Skip to content

Commit 6856e59

Browse files
implement parsing
1 parent c8c8410 commit 6856e59

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

backend/graph-proxy/src/graphql/workflow_templates.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use kube::{
2020
core::GroupVersionKind,
2121
Api, Client,
2222
};
23+
use serde::{Deserialize, Serialize};
2324
use serde_json::Value;
2425
use std::{collections::HashMap, ops::Deref};
2526
use tracing::{debug, instrument};
@@ -37,20 +38,22 @@ enum WorkflowTemplateParsingError {
3738
MalformParameterSchema(#[from] serde_json::Error),
3839
}
3940

40-
#[derive(Debug, Clone, SimpleObject, Eq, PartialEq)]
41+
#[derive(Debug, Serialize, Deserialize, Default, Clone, SimpleObject, Eq, PartialEq)]
4142
struct GitHubPath {
42-
repo: String,
4343
path: String,
44+
repo_url: String,
45+
target_revision: String,
4446
}
4547

46-
impl GitHubPath {
47-
fn new(repo: impl Into<String>, path: impl Into<String>) -> Self {
48-
Self {
49-
repo: repo.into(),
50-
path: path.into(),
51-
}
52-
}
53-
}
48+
// impl GitHubPath {
49+
// fn new(repo_url: impl Into<String>, path: impl Into<String>, target_revision: impl Into<String>) -> Self {
50+
// Self {
51+
// repo_url: repo_url.into(),
52+
// path: path.into(),
53+
// target_revision: target_revision.into(),
54+
// }
55+
// }
56+
// }
5457

5558
/// A Template which specifies how to produce a [`Workflow`]
5659
#[derive(Debug, derive_more::Deref, derive_more::From)]
@@ -112,6 +115,7 @@ impl WorkflowTemplate {
112115
}
113116

114117
async fn template_url(&self) -> Result<GitHubPath, WorkflowTemplateParsingError> {
118+
115119
let instance = match self.metadata.labels.get("argocd.argoproj.io/instance") {
116120
Some(val) => val,
117121
None => return Err(WorkflowTemplateParsingError::MissingInstanceLabel),
@@ -126,25 +130,23 @@ impl WorkflowTemplate {
126130
);
127131

128132
let obj = api.get(&instance).await.unwrap();
129-
let annotations = obj.metadata.annotations.clone().unwrap_or_default();
130-
println!("Annotations: ");
131-
for (key, value) in &annotations {
132-
println!("{}: {}", key, value);
133-
}
134-
let path = match annotations.get("path") {
135-
Some(path) => path,
136-
None => &String::from(""),
137-
};
138-
let repo = match self
139-
.metadata
140-
.annotations
141-
.get("workflows.diamond.ac.uk/repository")
142-
{
143-
Some(repo) => repo,
144-
None => &String::from(""),
133+
let group_annotations = obj.metadata.annotations.clone().unwrap_or_default();
134+
let last_config =
135+
match group_annotations.get("kubectl.kubernetes.io/last-applied-configuration") {
136+
Some(s) => s,
137+
None => "",
138+
};
139+
140+
let last_config_val: Value = serde_json::from_str(&last_config)?;
141+
let source: GitHubPath = match last_config_val.get("spec") {
142+
Some(val) => match val.get("source") {
143+
Some(src) => serde_json::from_value(src.clone()).unwrap(),
144+
None => GitHubPath {..Default::default()}
145+
}
146+
None => GitHubPath {..Default::default()}
145147
};
146148

147-
Ok(GitHubPath::new(repo, path))
149+
Ok(source)
148150

149151
// let list = api.list(&ListParams::default()).await?;
150152
// for obj in list {

charts/graph-proxy/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ image:
22
registry: ghcr.io
33
repository: diamondlightsource/workflows-graph-proxy
44
tag: "jamesdoingstuff"
5-
digest: "sha256:2b8bc3a4d05e5b8cb8d0ee696add6b22989becaf00a499550f85d773c3e3473c"
5+
digest: "sha256:b3354b17d4973da11a482d15913f7ca31be4dceac866b32395af6dce8759c5a8"
66
pullPolicy: IfNotPresent
77
pullSecrets: []
88

0 commit comments

Comments
 (0)