-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create annotator package * Add schema metadata to jsonschemas * Write schema metadata as headers/attributes to kafka/pubsub respectively
- Loading branch information
Showing
37 changed files
with
250 additions
and
118 deletions.
There are no files selected for viewing
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 +1 @@ | ||
v0.1.43 | ||
v0.1.44 |
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package annotator | ||
|
||
import ( | ||
"github.com/rs/zerolog/log" | ||
"github.com/silverton-io/honeypot/pkg/cache" | ||
"github.com/silverton-io/honeypot/pkg/envelope" | ||
"github.com/silverton-io/honeypot/pkg/protocol" | ||
"github.com/silverton-io/honeypot/pkg/validator" | ||
"github.com/tidwall/gjson" | ||
) | ||
|
||
func getMetadataFromSchema(schema []byte) envelope.EventMetadata { | ||
schemaContents := gjson.ParseBytes(schema) | ||
vendor := schemaContents.Get("self.vendor").String() | ||
primaryNamespace := schemaContents.Get("self.primaryNamespace").String() | ||
secondaryNamespace := schemaContents.Get("self.secondaryNamespace").String() | ||
tertiaryNamespace := schemaContents.Get("self.tertiaryNamespace").String() | ||
name := schemaContents.Get("self.name").String() | ||
version := schemaContents.Get("self.version").String() | ||
format := schemaContents.Get("self.format").String() | ||
path := schemaContents.Get("title").String() | ||
return envelope.EventMetadata{ | ||
Vendor: vendor, | ||
PrimaryNamespace: primaryNamespace, | ||
SecondaryNamespace: secondaryNamespace, | ||
TertiaryNamespace: tertiaryNamespace, | ||
Name: name, | ||
Version: version, | ||
Format: format, | ||
Path: path, | ||
} | ||
} | ||
|
||
func Annotate(envelopes []envelope.Envelope, cache *cache.SchemaCache) []envelope.Envelope { | ||
var e []envelope.Envelope | ||
for _, envelope := range envelopes { | ||
log.Debug().Msg("annotating event") | ||
switch envelope.EventProtocol { | ||
case protocol.WEBHOOK: | ||
var schema []byte | ||
eventMetadata := getMetadataFromSchema(schema) | ||
envelope.EventMetadata = &eventMetadata | ||
e = append(e, envelope) | ||
case protocol.RELAY: | ||
e = append(e, envelope) // Don't annotate | ||
default: | ||
isValid, validationError, schemaContents := validator.ValidateEvent(envelope.Payload, cache) | ||
envelope.IsValid = &isValid | ||
envelope.ValidationError = &validationError | ||
eventMetadata := getMetadataFromSchema(schemaContents) | ||
envelope.EventMetadata = &eventMetadata | ||
e = append(e, envelope) | ||
} | ||
} | ||
return e | ||
} |
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
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
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
Oops, something went wrong.