From 951f6b6781e2f1d824fa3948819ff1031bd84b4c Mon Sep 17 00:00:00 2001 From: nicolaferraro Date: Thu, 6 May 2021 09:19:11 +0200 Subject: [PATCH] chore: add checks for duplicate titles and descriptions and fix format --- aws-sns-fifo-sink.kamelet.yaml | 2 +- .../images/kamelets/extract-field-action.svg | 59 +++++++++++++++++++ docs/modules/ROOT/nav.adoc | 9 +-- .../modules/ROOT/pages/aws-sns-fifo-sink.adoc | 2 +- ...t-field.adoc => extract-field-action.adoc} | 22 ++++--- .../ROOT/pages/insert-field-action.adoc | 2 +- .../ROOT/pages/insert-header-action.adoc | 2 +- .../ROOT/pages/kafka-not-secured-sink.adoc | 2 +- .../ROOT/pages/kafka-not-secured-source.adoc | 2 +- .../ROOT/pages/replace-field-action.adoc | 4 +- .../ROOT/pages/value-to-key-action.adoc | 2 +- extract-field-action.kamelet.yaml | 2 +- insert-field-action.kamelet.yaml | 2 +- insert-header-action.kamelet.yaml | 2 +- kafka-not-secured-sink.kamelet.yaml | 2 +- kafka-not-secured-source.kamelet.yaml | 2 +- replace-field-action.kamelet.yaml | 4 +- script/validator/validator.go | 31 ++++++++++ value-to-key-action.kamelet.yaml | 2 +- 19 files changed, 122 insertions(+), 33 deletions(-) create mode 100644 docs/modules/ROOT/assets/images/kamelets/extract-field-action.svg rename docs/modules/ROOT/pages/{insert-field.adoc => extract-field-action.adoc} (66%) diff --git a/aws-sns-fifo-sink.kamelet.yaml b/aws-sns-fifo-sink.kamelet.yaml index b12d9595a..abb21533f 100644 --- a/aws-sns-fifo-sink.kamelet.yaml +++ b/aws-sns-fifo-sink.kamelet.yaml @@ -11,7 +11,7 @@ metadata: spec: definition: title: AWS SNS FIFO Sink - description: Send message to an AWS SQS FIFO Queue + description: Send message to an AWS SNS FIFO Topic required: - topicNameOrArn - accessKey diff --git a/docs/modules/ROOT/assets/images/kamelets/extract-field-action.svg b/docs/modules/ROOT/assets/images/kamelets/extract-field-action.svg new file mode 100644 index 000000000..fa06352da --- /dev/null +++ b/docs/modules/ROOT/assets/images/kamelets/extract-field-action.svg @@ -0,0 +1,59 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index a2a1ee4bb..16279b2ab 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -31,6 +31,7 @@ * xref:ROOT:elasticsearch-index-sink.adoc[image:kamelets/elasticsearch-index-sink.svg[] ElasticSearch Index Sink] * xref:ROOT:elasticsearch-search-source.adoc[image:kamelets/elasticsearch-search-source.svg[] ElasticSearch Index Source] * xref:ROOT:exec-sink.adoc[image:kamelets/exec-sink.svg[] Exec Sink] +* xref:ROOT:extract-field-action.adoc[image:kamelets/extract-field-action.svg[] Extract Field Action] * xref:ROOT:fhir-source.adoc[image:kamelets/fhir-source.svg[] Fhir Source] * xref:ROOT:file-watch-source.adoc[image:kamelets/file-watch-source.svg[] File Watch Source] * xref:ROOT:ftp-source.adoc[image:kamelets/ftp-source.svg[] FTP Source] @@ -42,8 +43,8 @@ * xref:ROOT:http-sink.adoc[image:kamelets/http-sink.svg[] HTTP Sink] * xref:ROOT:http-source.adoc[image:kamelets/http-source.svg[] HTTP Source] * xref:ROOT:infinispan-source.adoc[image:kamelets/infinispan-source.svg[] Infinispan Source] -* xref:ROOT:insert-field-action.adoc[image:kamelets/insert-field-action.svg[] Insert Field] -* xref:ROOT:insert-header-action.adoc[image:kamelets/insert-header-action.svg[] Insert Header] +* xref:ROOT:insert-field-action.adoc[image:kamelets/insert-field-action.svg[] Insert Field Action] +* xref:ROOT:insert-header-action.adoc[image:kamelets/insert-header-action.svg[] Insert Header Action] * xref:ROOT:jira-source.adoc[image:kamelets/jira-source.svg[] Jira Source] * xref:ROOT:kafka-not-secured-sink.adoc[image:kamelets/kafka-not-secured-sink.svg[] Kafka Not Secured Sink] * xref:ROOT:kafka-not-secured-source.adoc[image:kamelets/kafka-not-secured-source.svg[] Kafka Not Secured Source] @@ -57,7 +58,7 @@ * xref:ROOT:openai-completion-action.adoc[image:kamelets/openai-completion-action.svg[] OpenAI Completion Action] * xref:ROOT:pdf-action.adoc[image:kamelets/pdf-action.svg[] PDF Action] * xref:ROOT:rabbitmq-source.adoc[image:kamelets/rabbitmq-source.svg[] RabbitMQ Source] -* xref:ROOT:replace-field-action.adoc[image:kamelets/replace-field-action.svg[] Replace Field] +* xref:ROOT:replace-field-action.adoc[image:kamelets/replace-field-action.svg[] Replace Field Action] * xref:ROOT:salesforce-source.adoc[image:kamelets/salesforce-source.svg[] Salesforce Source] * xref:ROOT:sftp-source.adoc[image:kamelets/sftp-source.svg[] SFTP Source] * xref:ROOT:slack-source.adoc[image:kamelets/slack-source.svg[] Slack Source] @@ -68,6 +69,6 @@ * xref:ROOT:twitter-directmessage-source.adoc[image:kamelets/twitter-directmessage-source.svg[] Twitter Direct Message Source] * xref:ROOT:twitter-search-source.adoc[image:kamelets/twitter-search-source.svg[] Twitter Search Source] * xref:ROOT:twitter-timeline-source.adoc[image:kamelets/twitter-timeline-source.svg[] Twitter Timeline Source] -* xref:ROOT:value-to-key-action.adoc[image:kamelets/value-to-key-action.svg[] Value to Key action] +* xref:ROOT:value-to-key-action.adoc[image:kamelets/value-to-key-action.svg[] Value to Key Action] * xref:ROOT:webhook-source.adoc[image:kamelets/webhook-source.svg[] Webhook Source] // THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT diff --git a/docs/modules/ROOT/pages/aws-sns-fifo-sink.adoc b/docs/modules/ROOT/pages/aws-sns-fifo-sink.adoc index d8a9058db..c5fb178ba 100644 --- a/docs/modules/ROOT/pages/aws-sns-fifo-sink.adoc +++ b/docs/modules/ROOT/pages/aws-sns-fifo-sink.adoc @@ -3,7 +3,7 @@ *Provided by: "Apache Software Foundation"* -Send message to an AWS SQS FIFO Queue +Send message to an AWS SNS FIFO Topic == Configuration Options diff --git a/docs/modules/ROOT/pages/insert-field.adoc b/docs/modules/ROOT/pages/extract-field-action.adoc similarity index 66% rename from docs/modules/ROOT/pages/insert-field.adoc rename to docs/modules/ROOT/pages/extract-field-action.adoc index 886577538..7031423df 100644 --- a/docs/modules/ROOT/pages/insert-field.adoc +++ b/docs/modules/ROOT/pages/extract-field-action.adoc @@ -1,37 +1,36 @@ // THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT -= image:kamelets/insert-field.svg[] Insert Field += image:kamelets/extract-field-action.svg[] Extract Field Action *Provided by: "Apache Software Foundation"* -Adds a custom field with a constant value to the message in transit +Extract a field from the body == Configuration Options -The following table summarizes the configuration options available for the `insert-field` Kamelet: +The following table summarizes the configuration options available for the `extract-field-action` Kamelet: [width="100%",cols="2,^2,3,^2,^2,^3",options="header"] |=== | Property| Name| Description| Type| Default| Example | *field {empty}* *| Field| The name of the field to be added| string| | -| *value {empty}* *| Value| The value of the field| string| | |=== NOTE: Fields marked with ({empty}*) are mandatory. == Usage -This section summarizes how the `insert-field` can be used in various contexts. +This section summarizes how the `extract-field-action` can be used in various contexts. === Knative Action -The `insert-field` Kamelet can be used as intermediate step in a binding. +The `extract-field-action` Kamelet can be used as intermediate step in a binding. -.insert-field-binding.yaml +.extract-field-action-binding.yaml [source,yaml] ---- apiVersion: camel.apache.org/v1alpha1 kind: KameletBinding metadata: - name: insert-field-binding + name: extract-field-action-binding spec: source: ref: @@ -44,10 +43,9 @@ spec: - ref: kind: Kamelet apiVersion: camel.apache.org/v1alpha1 - name: insert-field + name: extract-field-action properties: field: "The Field" - value: "The Value" sink: ref: kind: InMemoryChannel @@ -58,12 +56,12 @@ spec: Make sure you have xref:latest@camel-k::installation/installation.adoc[Camel K installed] into the Kubernetes cluster you're connected to. -Save the `insert-field-binding.yaml` file into your hard drive, then configure it according to your needs. +Save the `extract-field-action-binding.yaml` file into your hard drive, then configure it according to your needs. You can run the action using the following command: [source,shell] ---- -kubectl apply -f insert-field-binding.yaml +kubectl apply -f extract-field-action-binding.yaml ---- // THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT diff --git a/docs/modules/ROOT/pages/insert-field-action.adoc b/docs/modules/ROOT/pages/insert-field-action.adoc index 14502bd1c..ce7704633 100644 --- a/docs/modules/ROOT/pages/insert-field-action.adoc +++ b/docs/modules/ROOT/pages/insert-field-action.adoc @@ -1,5 +1,5 @@ // THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT -= image:kamelets/insert-field-action.svg[] Insert Field += image:kamelets/insert-field-action.svg[] Insert Field Action *Provided by: "Apache Software Foundation"* diff --git a/docs/modules/ROOT/pages/insert-header-action.adoc b/docs/modules/ROOT/pages/insert-header-action.adoc index b3fba9e35..6a53f6c9c 100644 --- a/docs/modules/ROOT/pages/insert-header-action.adoc +++ b/docs/modules/ROOT/pages/insert-header-action.adoc @@ -1,5 +1,5 @@ // THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT -= image:kamelets/insert-header-action.svg[] Insert Header += image:kamelets/insert-header-action.svg[] Insert Header Action *Provided by: "Apache Software Foundation"* diff --git a/docs/modules/ROOT/pages/kafka-not-secured-sink.adoc b/docs/modules/ROOT/pages/kafka-not-secured-sink.adoc index 0c07d3597..3d9ec0b97 100644 --- a/docs/modules/ROOT/pages/kafka-not-secured-sink.adoc +++ b/docs/modules/ROOT/pages/kafka-not-secured-sink.adoc @@ -3,7 +3,7 @@ *Provided by: "Apache Software Foundation"* -Send data to Kafka topics. +Send data to Kafka topics on an insecure broker. The Kamelet is able to understand the following headers to be set: diff --git a/docs/modules/ROOT/pages/kafka-not-secured-source.adoc b/docs/modules/ROOT/pages/kafka-not-secured-source.adoc index 265596667..6620a9b85 100644 --- a/docs/modules/ROOT/pages/kafka-not-secured-source.adoc +++ b/docs/modules/ROOT/pages/kafka-not-secured-source.adoc @@ -3,7 +3,7 @@ *Provided by: "Apache Software Foundation"* -Receive data from Kafka topics. +Receive data from Kafka topics on an insecure broker. == Configuration Options diff --git a/docs/modules/ROOT/pages/replace-field-action.adoc b/docs/modules/ROOT/pages/replace-field-action.adoc index 56369610b..a3aaaa1b9 100644 --- a/docs/modules/ROOT/pages/replace-field-action.adoc +++ b/docs/modules/ROOT/pages/replace-field-action.adoc @@ -1,9 +1,9 @@ // THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT -= image:kamelets/replace-field-action.svg[] Replace Field += image:kamelets/replace-field-action.svg[] Replace Field Action *Provided by: "Apache Software Foundation"* -Adds a custom field with a constant value to the message in transit +Replaces a field with a constant value in the message in transit == Configuration Options diff --git a/docs/modules/ROOT/pages/value-to-key-action.adoc b/docs/modules/ROOT/pages/value-to-key-action.adoc index 1265bb699..a688b0407 100644 --- a/docs/modules/ROOT/pages/value-to-key-action.adoc +++ b/docs/modules/ROOT/pages/value-to-key-action.adoc @@ -1,5 +1,5 @@ // THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT -= image:kamelets/value-to-key-action.svg[] Value to Key action += image:kamelets/value-to-key-action.svg[] Value to Key Action *Provided by: "Apache Software Foundation"* diff --git a/extract-field-action.kamelet.yaml b/extract-field-action.kamelet.yaml index c313e348f..b078da191 100644 --- a/extract-field-action.kamelet.yaml +++ b/extract-field-action.kamelet.yaml @@ -10,7 +10,7 @@ metadata: camel.apache.org/kamelet.group: "Actions" spec: definition: - title: "Extract Field" + title: "Extract Field Action" description: "Extract a field from the body" required: - field diff --git a/insert-field-action.kamelet.yaml b/insert-field-action.kamelet.yaml index 2e1825587..c1dcf4a8f 100644 --- a/insert-field-action.kamelet.yaml +++ b/insert-field-action.kamelet.yaml @@ -10,7 +10,7 @@ metadata: camel.apache.org/kamelet.group: "Actions" spec: definition: - title: "Insert Field" + title: "Insert Field Action" description: "Adds a custom field with a constant value to the message in transit" required: - field diff --git a/insert-header-action.kamelet.yaml b/insert-header-action.kamelet.yaml index fdd49f150..edf461dc5 100644 --- a/insert-header-action.kamelet.yaml +++ b/insert-header-action.kamelet.yaml @@ -10,7 +10,7 @@ metadata: camel.apache.org/kamelet.group: "Actions" spec: definition: - title: "Insert Header" + title: "Insert Header Action" description: "Adds an header with a constant value to the message in transit" required: - name diff --git a/kafka-not-secured-sink.kamelet.yaml b/kafka-not-secured-sink.kamelet.yaml index a475d1518..53b65fd29 100644 --- a/kafka-not-secured-sink.kamelet.yaml +++ b/kafka-not-secured-sink.kamelet.yaml @@ -12,7 +12,7 @@ spec: definition: title: "Kafka Not Secured Sink" description: |- - Send data to Kafka topics. + Send data to Kafka topics on an insecure broker. The Kamelet is able to understand the following headers to be set: diff --git a/kafka-not-secured-source.kamelet.yaml b/kafka-not-secured-source.kamelet.yaml index 072f29943..9b48ab1b8 100644 --- a/kafka-not-secured-source.kamelet.yaml +++ b/kafka-not-secured-source.kamelet.yaml @@ -12,7 +12,7 @@ spec: definition: title: "Kafka Not Secured Source" description: |- - Receive data from Kafka topics. + Receive data from Kafka topics on an insecure broker. required: - topic - brokers diff --git a/replace-field-action.kamelet.yaml b/replace-field-action.kamelet.yaml index d32fecf73..77fd0c750 100644 --- a/replace-field-action.kamelet.yaml +++ b/replace-field-action.kamelet.yaml @@ -10,8 +10,8 @@ metadata: camel.apache.org/kamelet.group: "Actions" spec: definition: - title: "Replace Field" - description: "Adds a custom field with a constant value to the message in transit" + title: "Replace Field Action" + description: "Replaces a field with a constant value in the message in transit" required: - enabled - disabled diff --git a/script/validator/validator.go b/script/validator/validator.go index 21637c621..a6cfb2994 100644 --- a/script/validator/validator.go +++ b/script/validator/validator.go @@ -38,6 +38,7 @@ func main() { errors = append(errors, verifyParameters(kamelets)...) errors = append(errors, verifyInvalidContent(kamelets)...) errors = append(errors, verifyDescriptors(kamelets)...) + errors = append(errors, verifyDuplicates(kamelets)...) for _, err := range errors { fmt.Printf("ERROR: %v\n", err) @@ -47,6 +48,28 @@ func main() { } } +func verifyDuplicates(kamelets []KameletInfo) (errors []error) { + usedTitles := make(map[string]bool) + usedDescriptions := make(map[string]bool) + for _, kamelet := range kamelets { + if kamelet.Spec.Definition == nil { + errors = append(errors, fmt.Errorf("kamelet %q does not contain the JSON schema definition", kamelet.Name)) + continue + } + title := kamelet.Kamelet.Spec.Definition.Title + if _, found := usedTitles[title]; found { + errors = append(errors, fmt.Errorf("kamelet %q has duplicate title %q", kamelet.Name, title)) + } + description := kamelet.Kamelet.Spec.Definition.Description + if _, found := usedDescriptions[description]; found { + errors = append(errors, fmt.Errorf("kamelet %q has duplicate description %q", kamelet.Name, description)) + } + usedTitles[title] = true + usedDescriptions[description] = true + } + return errors +} + func verifyDescriptors(kamelets []KameletInfo) (errors []error) { for _, kamelet := range kamelets { if kamelet.Spec.Definition == nil { @@ -134,6 +157,14 @@ func verifyParameters(kamelets []KameletInfo) (errors []error) { } if kamelet.Spec.Definition.Title == "" { errors = append(errors, fmt.Errorf("kamelet %q does not contain title", kamelet.Name)) + } else { + tp := kamelet.Labels["camel.apache.org/kamelet.type"] + if len(tp) > 1 { + expectedSuffix := strings.ToUpper(tp[0:1]) + tp[1:] + if !strings.HasSuffix(kamelet.Spec.Definition.Title, expectedSuffix) { + errors = append(errors, fmt.Errorf("kamelet %q title %q does not ends with %q", kamelet.Name, kamelet.Spec.Definition.Title, expectedSuffix)) + } + } } if kamelet.Spec.Definition.Description == "" { errors = append(errors, fmt.Errorf("kamelet %q does not contain description", kamelet.Name)) diff --git a/value-to-key-action.kamelet.yaml b/value-to-key-action.kamelet.yaml index b24a31ca7..a24621137 100644 --- a/value-to-key-action.kamelet.yaml +++ b/value-to-key-action.kamelet.yaml @@ -10,7 +10,7 @@ metadata: camel.apache.org/kamelet.group: "Actions" spec: definition: - title: "Value to Key action" + title: "Value to Key Action" description: "Replace the Kafka record key with a new key formed from a subset of fields in the body" required: - fields