Skip to content

FE: Switch to Typespec contract description model #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.kafbat.ui.mapper;

import io.kafbat.ui.model.ActionDTO;
import io.kafbat.ui.model.ApplicationConfigPropertiesAuthOauth2ClientValueDTO;
import io.kafbat.ui.model.ApplicationConfigPropertiesAuthOauth2ResourceServerDTO;
import io.kafbat.ui.model.ApplicationConfigPropertiesAuthOauth2ResourceServerJwtDTO;
import io.kafbat.ui.model.ApplicationConfigPropertiesAuthOauth2ResourceServerOpaquetokenDTO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void testConvertController() {
"clusterName", Map.of("type", "string"),
"topicName", Map.of("type", "string"),
"topicUpdate", SCHEMA_GENERATOR.generateSchema(TopicUpdateDTO.class)
), List.of("clusterName", "topicName"), false, null, null)
), List.of("clusterName", "topicName", "topicUpdate"), false, null, null)
)
);
assertThat(tools).allMatch(tool ->
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ext {
release = resolveBooleanProperty("release")
includeFrontend = resolveBooleanProperty("include-frontend", release)
buildDockerImages = resolveBooleanProperty("build-docker-images", release)
useTypeSpec = resolveBooleanProperty("typespec", true)
runE2e = resolveBooleanProperty("run-e2e")
}

Expand Down
141 changes: 141 additions & 0 deletions contract-typespec/api/acls.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import "@typespec/openapi";

namespace Api;

using TypeSpec.Http;
using OpenAPI;

@route("/api/clusters/{clusterName}/acls")
@tag("Acls")
interface AclApi {
@doc("listKafkaAcls")
@get
@operationId("listAcls")
listAcls(
@path clusterName: string,
@query resourceType?: KafkaAclResourceType,
@query resourceName?: string,
@query namePatternType?: KafkaAclNamePatternType,
): KafkaAcl[];

@route("/csv")
@doc("getAclAsCsv")
@get
@operationId("getAclAsCsv")
getAclAsCsv(@path clusterName: string): string;

@route("/csv")
@doc("syncAclsCsv")
@post
@operationId("syncAclsCsv")
syncAclsCsv(@path clusterName: string, @body content: string): void | ApiBadRequestResponse;

@doc("createAcl")
@post
@operationId("createAcl")
createAcl(@path clusterName: string, @body acl: KafkaAcl): void | ApiBadRequestResponse;

@doc("deleteAcl")
@delete
@operationId("deleteAcl")
deleteAcl(
@path clusterName: string,
@body acl: KafkaAcl,
): void | ApiNotFoundResponse;

@route("/consumer")
@doc("createConsumerAcl")
@post
@operationId("createConsumerAcl")
createConsumerAcl(
@path clusterName: string,
@body payload: CreateConsumerAcl,
): void | ApiBadRequestResponse;

@route("/producer")
@doc("createProducerAcl")
@operationId("createProducerAcl")
@post
createProducerAcl(
@path clusterName: string,
@body payload: CreateProducerAcl,
): void | ApiBadRequestResponse;

@route("/streamApp")
@doc("createStreamAppAcl")
@post
@operationId("createStreamAppAcl")
createStreamAppAcl(
@path clusterName: string,
@body payload: CreateStreamAppAcl,
): void | ApiBadRequestResponse;
}

model KafkaAcl {
resourceType: KafkaAclResourceType;
resourceName: string; // "*" if acl can be applied to any resource of given type
namePatternType: KafkaAclNamePatternType;
principal: string;
host: string;
operation: KafkaAclOpeations;
permission: "ALLOW" | "DENY";
}

alias KafkaAclOpeations =
"UNKNOWN"
| "ALL"
| "READ"
| "WRITE"
| "CREATE"
| "DELETE"
| "ALTER"
| "DESCRIBE"
| "CLUSTER_ACTION"
| "DESCRIBE_CONFIGS"
| "ALTER_CONFIGS"
| "IDEMPOTENT_WRITE"
| "CREATE_TOKENS"
| "DESCRIBE_TOKENS";

enum KafkaAclResourceType {
UNKNOWN,
TOPIC,
GROUP,
CLUSTER,
TRANSACTIONAL_ID,
DELEGATION_TOKEN,
USER,
}

enum KafkaAclNamePatternType {
MATCH,
LITERAL,
PREFIXED,
}

model CreateConsumerAcl {
principal?: string;
host?: string;
topics?: string[];
topicsPrefix?: string;
consumerGroups?: string[];
consumerGroupsPrefix?: string;
}

model CreateProducerAcl {
principal?: string;
host?: string;
topics?: string[];
topicsPrefix?: string;
transactionalId?: string;
transactionsIdPrefix?: string;
idempotent?: boolean = false;
}

model CreateStreamAppAcl {
principal?: string;
host?: string;
inputTopics?: string[];
outputTopics?: string[];
applicationId?: string;
}
46 changes: 46 additions & 0 deletions contract-typespec/api/auth.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import "@typespec/openapi";

namespace Api;

using TypeSpec.Http;
using OpenAPI;

@tag("Authorization")
interface AuthorizationApi {
@route("/api/authorization")
@doc("Get user authorization related info")
@operationId("getUserAuthInfo")
@get
getUserAuthInfo(): AuthenticationInfo;
}

@route("/login")
@doc("Authenticate")
@operationId("authenticate")
@post
@tag("Unmapped")
op authenticate(@header contentType: "application/x-www-form-urlencoded", @body form: LoginForm): void | Http.Response<401>;


model LoginForm {
username?: string;
password?: string;
}

model AuthenticationInfo {
rbacEnabled: boolean; // true if role based access control is enabled and granular permission access is required
userInfo?: UserInfo;
}

model UserInfo {
username: string;
permissions: UserPermission[];
}


model UserPermission {
clusters: string[];
resource: ResourceType;
value?: string;
actions: Action[];
}
128 changes: 128 additions & 0 deletions contract-typespec/api/brokers.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import "@typespec/openapi";

namespace Api;

using TypeSpec.Http;
using OpenAPI;

@route("/api/clusters/{clusterName}/brokers")
@tag("Brokers")
interface BrokersApi {
@get
@operationId("getBrokers")
@doc("getBrokers")
getBrokers(@path clusterName: string): Broker[];

@get
@route("/{id}/configs")
@operationId("getBrokerConfig")
@doc("getBrokerConfig")
getBrokerConfig(@path clusterName: string, @path id: int32): BrokerConfig[];

@put
@route("/{id}/configs/{name}")
@operationId("updateBrokerConfigByName")
@doc("updateBrokerConfigByName")
updateBrokerConfigByName(
@path clusterName: string,
@path id: int32,
@path name: string,
@body config: BrokerConfigItem,
): void | ApiBadRequestResponse;

@get
@route("/{id}/metrics")
@operationId("getBrokersMetrics")
@doc("getBrokersMetrics")
getBrokersMetrics(@path clusterName: string, @path id: int32): BrokerMetrics;

@get
@route("/logdirs")
@operationId("getAllBrokersLogdirs")
@doc("getAllBrokersLogdirs")
getAllBrokersLogdirs(
@path clusterName: string,
@query broker?: int32[],
): BrokersLogdirs[];

@patch(#{implicitOptionality: true})
@route("/{id}/logdirs")
@operationId("updateBrokerTopicPartitionLogDir")
@doc("updateBrokerTopicPartitionLogDir")
updateBrokerTopicPartitionLogDir(
@path clusterName: string,
@path id: int32,
@body update: BrokerLogdirUpdate,
): void | ApiBadRequestResponse;
}

model Broker {
id: int32;
host?: string;
port?: int32;
bytesInPerSec?: float64;
bytesOutPerSec?: float64;
partitionsLeader?: int32;
partitions?: int32;
inSyncPartitions?: int32;
partitionsSkew?: float64;
leadersSkew?: float64;
}

model BrokerLogdirUpdate {
topic?: string;
partition?: int32;
logDir?: string;
}

model BrokerConfig {
name: string;
value: string;
source: ConfigSource;
isSensitive: boolean;
isReadOnly: boolean;
synonyms?: ConfigSynonym[];
}

model BrokerConfigItem {
value?: string;
}

model BrokerLogdirs {
name?: string;
error?: string;
topics?: TopicLogdirs[];
}

model TopicLogdirs {
name?: string;
partitions?: TopicPartitionLogdir[];
}

model BrokerMetrics {
segmentSize?: int64;
segmentCount?: int32;
metrics?: Metric[];
}

model BrokersLogdirs {
name?: string;
error?: string;
topics?: BrokerTopicLogdirs[];
}

model BrokerTopicLogdirs {
name?: string;
partitions?: BrokerTopicPartitionLogdir[];
}

model BrokerTopicPartitionLogdir {
...TopicPartitionLogdir;
broker?: int32;
}

model TopicPartitionLogdir {
partition?: int32;
size?: int64;
offsetLag?: int64;
}
Loading
Loading