-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(BE): Get latest schema for a given subject
- Loading branch information
1 parent
549102e
commit 6b026e2
Showing
8 changed files
with
115 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,49 @@ | ||
use serde::{ de::DeserializeOwned }; | ||
use url::Url; | ||
use serde::{ de::DeserializeOwned, Deserialize, Serialize }; | ||
|
||
use crate::{ configuration::model::SchemaRegistry, error::Result }; | ||
use crate::{ configuration::model::SchemaRegistry, error::{ Result, TauriError } }; | ||
|
||
async fn get<T: DeserializeOwned>(url: String, config: SchemaRegistry) -> Result<T> { | ||
async fn get<T: DeserializeOwned>(url: String, config: &SchemaRegistry) -> Result<T> { | ||
println!("{}", url); | ||
let client = reqwest::Client::new(); | ||
let mut request = client.get(url); | ||
if let Some(username) = config.username { | ||
request = request.basic_auth(username, config.password); | ||
if let Some(username) = &config.username { | ||
request = request.basic_auth(username, config.password.as_ref()); | ||
} | ||
let res = request.send().await?.json().await?; | ||
let response = request.send().await?; | ||
let res = response.json().await?; | ||
Ok(res) | ||
} | ||
|
||
#[tauri::command] | ||
pub async fn list_subjects(config: SchemaRegistry) -> Result<Vec<String>> { | ||
let res = get(format!("{:}/subjects", config.endpoint), config).await?; | ||
let url = Url::parse(&config.endpoint)?.join("subjects")?; | ||
let res = get(url.to_string(), &config).await?; | ||
Ok(res) | ||
} | ||
|
||
#[tauri::command] | ||
pub async fn get_schema(subject_name: String, config: SchemaRegistry) -> Result<Schema> { | ||
let url = Url::parse(&config.endpoint)?.join( | ||
format!("/subjects/{}/versions/", subject_name).as_str() | ||
)?; | ||
let versions: Vec<i32> = get(url.to_string(), &config).await?; | ||
if let Some(latest_version) = versions.iter().max() { | ||
let latest_schema_url = url.join(&latest_version.to_string())?; | ||
let latest_schema: Schema = get(latest_schema_url.to_string(), &config).await?; | ||
Ok(latest_schema) | ||
} else { | ||
Err(TauriError { | ||
error_type: "Schema registry".to_string(), | ||
message: format!("No versions found for subject {:}", subject_name), | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct Schema { | ||
subject: String, | ||
id: i32, | ||
version: i32, | ||
schema: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
import { Group } from "@mantine/core"; | ||
import { Group, Text } from "@mantine/core"; | ||
import { useState } from "react"; | ||
import { useAppState } from "../../providers"; | ||
import { Schema } from "./schema"; | ||
import { SchemaList } from "./schema-list"; | ||
|
||
export const SchemasPage = () => { | ||
const { appState } = useAppState(); | ||
const [state, setState] = useState<{ activeSchema?: string }>({}); | ||
const { activeSchema } = state; | ||
return ( | ||
<Group grow={true} align={"stretch"} position={"center"} noWrap={true}> | ||
<SchemaList | ||
onTopicSelected={(activeSchema) => { | ||
setState({ ...state, activeSchema: activeSchema }); | ||
}} | ||
/> | ||
{activeSchema && <Schema schemaName={activeSchema} />} | ||
</Group> | ||
); | ||
const schemaRegistry = appState.activeCluster?.schemaRegistry; | ||
if (schemaRegistry && schemaRegistry.endpoint) { | ||
return ( | ||
<Group grow={true} align={"stretch"} position={"center"} noWrap={true}> | ||
<SchemaList | ||
schemaRegistry={schemaRegistry} | ||
onTopicSelected={(activeSchema) => { | ||
setState({ ...state, activeSchema: activeSchema }); | ||
}} | ||
/> | ||
{activeSchema && <Schema schemaRegistry={schemaRegistry} schemaName={activeSchema} />} | ||
</Group> | ||
); | ||
} else return <Text>Missing schema registry configuration</Text>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
import { ActionIcon, Container, Divider, Group, Title, Tooltip } from "@mantine/core"; | ||
import { IconInfoCircle } from "@tabler/icons"; | ||
import { invoke } from "@tauri-apps/api"; | ||
import { useMemo } from "react"; | ||
import { SchemaRegistry } from "../../models/kafka"; | ||
|
||
export const Schema = ({ schemaName }: { schemaName: string }) => ( | ||
<Container style={{ width: "100%" }}> | ||
<Group position={"apart"}> | ||
<Title>{schemaName}</Title> | ||
<Group> | ||
<Tooltip label="Topic info"> | ||
<ActionIcon> | ||
<IconInfoCircle /> | ||
</ActionIcon> | ||
</Tooltip> | ||
const getLatestSchema = (subjectName: string, config: SchemaRegistry) => | ||
invoke("get_schema", { subjectName, config }).catch((err) => console.error(err)); | ||
|
||
export const Schema = ({ | ||
schemaName, | ||
schemaRegistry, | ||
}: { | ||
schemaName: string; | ||
schemaRegistry: SchemaRegistry; | ||
}) => { | ||
useMemo(async () => { | ||
const lastSchema = await getLatestSchema(schemaName, schemaRegistry); | ||
console.log(lastSchema); | ||
}, [schemaName]); | ||
return ( | ||
<Container style={{ width: "100%" }}> | ||
<Group position={"apart"}> | ||
<Title>{schemaName}</Title> | ||
<Group> | ||
<Tooltip label="Topic info"> | ||
<ActionIcon> | ||
<IconInfoCircle /> | ||
</ActionIcon> | ||
</Tooltip> | ||
</Group> | ||
</Group> | ||
</Group> | ||
<Divider mt={10} /> | ||
</Container> | ||
); | ||
<Divider mt={10} /> | ||
</Container> | ||
); | ||
}; |