Skip to content

Commit

Permalink
chore: add checks for duplicate titles and descriptions and fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro authored and oscerd committed May 6, 2021
1 parent 4e37167 commit 505934a
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 33 deletions.
2 changes: 1 addition & 1 deletion aws-sns-fifo-sink.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 59 additions & 0 deletions docs/modules/ROOT/assets/images/kamelets/extract-field-action.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/aws-sns-fifo-sink.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/insert-field-action.adoc
Original file line number Diff line number Diff line change
@@ -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"*

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/insert-header-action.adoc
Original file line number Diff line number Diff line change
@@ -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"*

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/kafka-not-secured-sink.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/kafka-not-secured-source.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/replace-field-action.adoc
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/value-to-key-action.adoc
Original file line number Diff line number Diff line change
@@ -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"*

Expand Down
2 changes: 1 addition & 1 deletion extract-field-action.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion insert-field-action.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion insert-header-action.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion kafka-not-secured-sink.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion kafka-not-secured-source.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions replace-field-action.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions script/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion value-to-key-action.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 505934a

Please sign in to comment.