Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate default catalog
Browse files Browse the repository at this point in the history
strokyl committed Aug 2, 2024
1 parent 843d552 commit 08cf2e9
Showing 7 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ func Make(apiParameter ApiParameter) (*Client, error) {
err := result.initKindFromApi()
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot access the Conduktor API: %s\nUsing offline defaults.\n", err)
result.kinds = schema.DefaultKind()
result.kinds = schema.ConsoleDefaultKind()
}

return result, nil
2 changes: 1 addition & 1 deletion client/gateway_client.go
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ func MakeGateway(apiParameter GatewayApiParameter) (*GatewayClient, error) {
err := result.initKindFromApi()
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot access the Gateway Conduktor API: %s\nUsing offline defaults.\n", err)
result.kinds = schema.DefaultKind()
result.kinds = schema.GatewayDefaultKind()
}

return result, nil
13 changes: 8 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -64,14 +64,17 @@ func init() {
if apiClientError == nil {
kinds = apiClient_.GetKinds()
} else {
kinds = schema.DefaultKind()
kinds = schema.ConsoleDefaultKind()
}
gatewayApiClient_, gatewayApiClientError = client.MakeGatewayClientFromEnv()
var gatewayKinds schema.KindCatalog
if gatewayApiClientError == nil {
var gatewayKinds = gatewayApiClient().GetKinds()
for k, v := range gatewayKinds {
kinds[k] = v
}
gatewayKinds = gatewayApiClient().GetKinds()
} else {
gatewayKinds = schema.GatewayDefaultKind()
}
for k, v := range gatewayKinds {
kinds[k] = v
}
debug = rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show more information for debugging")
initGet(kinds)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Application":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application","Name":"Application","ParentPathParam":[],"Order":8}}},"ApplicationGroup":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-group","Name":"ApplicationGroup","ParentPathParam":[],"Order":11}}},"ApplicationInstance":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance","Name":"ApplicationInstance","ParentPathParam":[],"Order":9}}},"ApplicationInstancePermission":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance-permission","Name":"ApplicationInstancePermission","ParentPathParam":[],"Order":10}}},"Group":{"Versions":{"2":{"ListPath":"/public/iam/v2/group","Name":"Group","ParentPathParam":[],"Order":1}}},"KafkaCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/kafka-cluster","Name":"KafkaCluster","ParentPathParam":[],"Order":2}}},"KafkaConnectCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/cluster/{cluster}/kafka-connect","Name":"KafkaConnectCluster","ParentPathParam":["cluster"],"Order":3}}},"KsqlDBCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/cluster/{cluster}/ksqldb","Name":"KsqlDBCluster","ParentPathParam":["cluster"],"Order":4}}},"Subject":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/subject","Name":"Subject","ParentPathParam":["cluster"],"Order":6}}},"Topic":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/topic","Name":"Topic","ParentPathParam":["cluster"],"Order":5}}},"TopicPolicy":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/topic-policy","Name":"TopicPolicy","ParentPathParam":[],"Order":7}}},"User":{"Versions":{"2":{"ListPath":"/public/iam/v2/user","Name":"User","ParentPathParam":[],"Order":0}}},"VClusters":{"Versions":{"2":{"ListPath":"/gateway/v2/vclusters","Name":"VClusters","ParentPathParam":[],"Order":7}}},"AliasTopics":{"Versions":{"2":{"ListPath":"/gateway/v2/alias-topics","Name":"AliasTopics","ParentPathParam":[],"Order":8}}},"ConcentrationRules":{"Versions":{"2":{"ListPath":"/gateway/v2/concentration-rules","Name":"ConcentrationRules","ParentPathParam":[],"Order":9}}},"GatewayGroups":{"Versions":{"2":{"ListPath":"/gateway/v2/gateway-groups","Name":"GatewayGroups","ParentPathParam":[],"Order":10}}},"ServiceAccounts":{"Versions":{"2":{"ListPath":"/gateway/v2/service-accounts","Name":"ServiceAccounts","ParentPathParam":[],"Order":11}}},"Interceptors":{"Versions":{"2":{"ListPath":"/gateway/v2/interceptors","Name":"Interceptors","ParentPathParam":[],"Order":12}}}}
{"Application":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application","Name":"Application","ParentPathParam":[],"Order":8}}},"ApplicationGroup":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-group","Name":"ApplicationGroup","ParentPathParam":[],"Order":11}}},"ApplicationInstance":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance","Name":"ApplicationInstance","ParentPathParam":[],"Order":9}}},"ApplicationInstancePermission":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance-permission","Name":"ApplicationInstancePermission","ParentPathParam":[],"Order":10}}},"Group":{"Versions":{"2":{"ListPath":"/public/iam/v2/group","Name":"Group","ParentPathParam":[],"Order":1}}},"KafkaCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/kafka-cluster","Name":"KafkaCluster","ParentPathParam":[],"Order":2}}},"KafkaConnectCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/cluster/{cluster}/kafka-connect","Name":"KafkaConnectCluster","ParentPathParam":["cluster"],"Order":3}}},"KsqlDBCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/cluster/{cluster}/ksqldb","Name":"KsqlDBCluster","ParentPathParam":["cluster"],"Order":4}}},"Subject":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/subject","Name":"Subject","ParentPathParam":["cluster"],"Order":6}}},"Topic":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/topic","Name":"Topic","ParentPathParam":["cluster"],"Order":5}}},"TopicPolicy":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/topic-policy","Name":"TopicPolicy","ParentPathParam":[],"Order":7}}},"User":{"Versions":{"2":{"ListPath":"/public/iam/v2/user","Name":"User","ParentPathParam":[],"Order":0}}}}
1 change: 1 addition & 0 deletions schema/gateway-default-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"VClusters":{"Versions":{"2":{"ListPath":"/gateway/v2/vclusters","Name":"VClusters","ParentPathParam":[],"Order":7}}},"AliasTopics":{"Versions":{"2":{"ListPath":"/gateway/v2/alias-topics","Name":"AliasTopics","ParentPathParam":[],"Order":8}}},"ConcentrationRules":{"Versions":{"2":{"ListPath":"/gateway/v2/concentration-rules","Name":"ConcentrationRules","ParentPathParam":[],"Order":9}}},"GatewayGroups":{"Versions":{"2":{"ListPath":"/gateway/v2/gateway-groups","Name":"GatewayGroups","ParentPathParam":[],"Order":10}}},"ServiceAccounts":{"Versions":{"2":{"ListPath":"/gateway/v2/service-accounts","Name":"ServiceAccounts","ParentPathParam":[],"Order":11}}},"Interceptors":{"Versions":{"2":{"ListPath":"/gateway/v2/interceptors","Name":"Interceptors","ParentPathParam":[],"Order":12}}}}
19 changes: 15 additions & 4 deletions schema/kind.go
Original file line number Diff line number Diff line change
@@ -27,18 +27,29 @@ type Kind struct {

type KindCatalog = map[string]Kind

//go:embed default-schema.json
var defaultByteSchema []byte
//go:embed console-default-schema.json
var consoleDefaultByteSchema []byte

func DefaultKind() KindCatalog {
//go:embed gateway-default-schema.json
var gatewayDefaultByteSchema []byte

func buildKindCatalogFromByteSchema(byteSchema []byte) KindCatalog {
var result KindCatalog
err := json.Unmarshal(defaultByteSchema, &result)
err := json.Unmarshal(byteSchema, &result)
if err != nil {
panic(err)
}
return result
}

func ConsoleDefaultKind() KindCatalog {
return buildKindCatalogFromByteSchema(consoleDefaultByteSchema)
}

func GatewayDefaultKind() KindCatalog {
return buildKindCatalogFromByteSchema(gatewayDefaultByteSchema)
}

func NewKind(version int, kindVersion *KindVersion) Kind {
return Kind{
Versions: map[int]KindVersion{version: *kindVersion},
2 changes: 1 addition & 1 deletion schema/sort.go
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ func resourcePriority(catalog KindCatalog, resource resource.Resource, debug, fa
} else {
order := kindVersion.Order
if order == DefaultPriority && fallbackToDefaultCatalog {
defaultCatalog := DefaultKind()
defaultCatalog := ConsoleDefaultKind() //TODO: handle gateway
orderFromDefaultCatalog := resourcePriority(defaultCatalog, resource, false, false)
if orderFromDefaultCatalog != DefaultPriority && debug {
fmt.Fprintf(os.Stderr, "Could not find version: %d of kind %s in catalog, but find it in default catalog with priority %d\n", version, resource.Kind, orderFromDefaultCatalog)

0 comments on commit 08cf2e9

Please sign in to comment.