NewTopicConfigEntry creates a new instance for a TopicConfigEntry. The function is in charge of computing additional properties based on existing other properties, as well as enriching the giving describe configs response with properties from our own config extensions.
( cfg kmsg.DescribeConfigsResponseResourceConfig, extension ConfigEntryExtension, )
| 49 | // properties, as well as enriching the giving describe configs response with |
| 50 | // properties from our own config extensions. |
| 51 | func NewTopicConfigEntry( |
| 52 | cfg kmsg.DescribeConfigsResponseResourceConfig, |
| 53 | extension ConfigEntryExtension, |
| 54 | ) *TopicConfigEntry { |
| 55 | isDefaultValue := false |
| 56 | innerEntries := make([]TopicConfigSynonym, len(cfg.ConfigSynonyms)) |
| 57 | for j, innerCfg := range cfg.ConfigSynonyms { |
| 58 | innerEntries[j] = TopicConfigSynonym{ |
| 59 | Name: innerCfg.Name, |
| 60 | Value: innerCfg.Value, |
| 61 | Source: innerCfg.Source.String(), |
| 62 | } |
| 63 | if innerCfg.Source == kmsg.ConfigSourceDefaultConfig { |
| 64 | isDefaultValue = derefString(cfg.Value) == derefString(innerCfg.Value) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | var isExplicitlySet bool |
| 69 | if cfg.Source == kmsg.ConfigSourceUnknown { |
| 70 | // Kafka <v1.1 uses the IsDefault property. Since then, it's been replaced by ConfigSource and defaults |
| 71 | // to false. Thus, we only consider it if cfg.Source is not set / unknown. |
| 72 | isExplicitlySet = !cfg.IsDefault |
| 73 | } else { |
| 74 | isExplicitlySet = cfg.Source == kmsg.ConfigSourceDynamicTopicConfig |
| 75 | } |
| 76 | |
| 77 | documentation := cfg.Documentation |
| 78 | if documentation == nil { |
| 79 | documentation = extension.Documentation |
| 80 | } |
| 81 | configType := cfg.ConfigType |
| 82 | if configType == kmsg.ConfigTypeUnknown { |
| 83 | configType = extension.Type |
| 84 | } |
| 85 | extension.FrontendFormat = FrontendFormatFromValueType(configType, extension.FrontendFormat) |
| 86 | |
| 87 | return &TopicConfigEntry{ |
| 88 | Name: cfg.Name, |
| 89 | Value: cfg.Value, |
| 90 | Source: cfg.Source.String(), |
| 91 | Type: configType.String(), |
| 92 | IsExplicitlySet: isExplicitlySet, |
| 93 | IsDefaultValue: isDefaultValue, |
| 94 | IsSensitive: cfg.IsSensitive, |
| 95 | IsReadOnly: cfg.ReadOnly, |
| 96 | Documentation: documentation, |
| 97 | Synonyms: innerEntries, |
| 98 | ConfigEntryExtension: extension, |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // TopicConfigSynonym is a synonym for a topic configuration. |
| 103 | type TopicConfigSynonym struct { |
no test coverage detected
searching dependent graphs…