2021-06-06 07:57:24 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2021-08-03 15:06:19 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-02-02 17:15:17 -08:00
|
|
|
|
2021-06-06 07:57:24 -04:00
|
|
|
package event
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2021-08-03 15:06:19 -04:00
|
|
|
JSONSinkFormat SinkFormat = "cloudevents-json" // JSONSinkFormat means the event is formatted as JSON
|
|
|
|
|
TextSinkFormat SinkFormat = "cloudevents-text" // TextSinkFormat means the event is formmatted as text
|
|
|
|
|
TextHclogSinkFormat SinkFormat = "hclog-text" // TextHclogSinkFormat means the event is formatted as an hclog text entry
|
|
|
|
|
JSONHclogSinkFormat SinkFormat = "hclog-json" // JSONHclogSinkFormat means the event is formated as an hclog json entry
|
2021-06-06 07:57:24 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type SinkFormat string // SinkFormat defines the formatting for a sink in a config file stanza (json)
|
|
|
|
|
|
2021-07-08 15:50:25 -04:00
|
|
|
func (f SinkFormat) Validate() error {
|
|
|
|
|
const op = "event.(SinkFormat).Validate"
|
2021-06-06 07:57:24 -04:00
|
|
|
switch f {
|
2021-07-25 17:40:54 -04:00
|
|
|
case JSONSinkFormat, TextSinkFormat:
|
2021-06-06 07:57:24 -04:00
|
|
|
return nil
|
2021-08-03 15:06:19 -04:00
|
|
|
case TextHclogSinkFormat, JSONHclogSinkFormat:
|
|
|
|
|
return nil
|
2021-06-06 07:57:24 -04:00
|
|
|
default:
|
2021-06-22 16:23:27 -05:00
|
|
|
return fmt.Errorf("%s: '%s' is not a valid sink format: %w", op, f, ErrInvalidParameter)
|
2021-06-06 07:57:24 -04:00
|
|
|
}
|
|
|
|
|
}
|