| 1 |
package kafka |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"fmt" |
| 6 |
"net" |
| 7 |
"time" |
| 8 |
|
| 9 |
"github.com/segmentio/kafka-go/protocol/describeconfigs" |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
type DescribeConfigsRequest struct { |
| 14 |
|
| 15 |
Addr net.Addr |
| 16 |
|
| 17 |
|
| 18 |
Resources []DescribeConfigRequestResource |
| 19 |
|
| 20 |
|
| 21 |
IncludeSynonyms bool |
| 22 |
|
| 23 |
|
| 24 |
IncludeDocumentation bool |
| 25 |
} |
| 26 |
|
| 27 |
type DescribeConfigRequestResource struct { |
| 28 |
|
| 29 |
ResourceType ResourceType |
| 30 |
|
| 31 |
|
| 32 |
ResourceName string |
| 33 |
|
| 34 |
|
| 35 |
ConfigNames []string |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
type DescribeConfigsResponse struct { |
| 40 |
|
| 41 |
Throttle time.Duration |
| 42 |
|
| 43 |
|
| 44 |
Resources []DescribeConfigResponseResource |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
type DescribeConfigResponseResource struct { |
| 49 |
|
| 50 |
ResourceType int8 |
| 51 |
|
| 52 |
|
| 53 |
ResourceName string |
| 54 |
|
| 55 |
|
| 56 |
Error error |
| 57 |
|
| 58 |
|
| 59 |
ConfigEntries []DescribeConfigResponseConfigEntry |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
type DescribeConfigResponseConfigEntry struct { |
| 64 |
ConfigName string |
| 65 |
ConfigValue string |
| 66 |
ReadOnly bool |
| 67 |
|
| 68 |
|
| 69 |
IsDefault bool |
| 70 |
|
| 71 |
|
| 72 |
ConfigSource int8 |
| 73 |
|
| 74 |
IsSensitive bool |
| 75 |
|
| 76 |
|
| 77 |
ConfigSynonyms []DescribeConfigResponseConfigSynonym |
| 78 |
|
| 79 |
|
| 80 |
ConfigType int8 |
| 81 |
|
| 82 |
|
| 83 |
ConfigDocumentation string |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
type DescribeConfigResponseConfigSynonym struct { |
| 88 |
|
| 89 |
ConfigName string |
| 90 |
|
| 91 |
|
| 92 |
ConfigValue string |
| 93 |
|
| 94 |
|
| 95 |
ConfigSource int8 |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
func (c *Client) DescribeConfigs(ctx context.Context, req *DescribeConfigsRequest) (*DescribeConfigsResponse, error) { |
| 101 |
resources := make([]describeconfigs.RequestResource, len(req.Resources)) |
| 102 |
|
| 103 |
for i, t := range req.Resources { |
| 104 |
resources[i] = describeconfigs.RequestResource{ |
| 105 |
ResourceType: int8(t.ResourceType), |
| 106 |
ResourceName: t.ResourceName, |
| 107 |
ConfigNames: t.ConfigNames, |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
m, err := c.roundTrip(ctx, req.Addr, &describeconfigs.Request{ |
| 112 |
Resources: resources, |
| 113 |
IncludeSynonyms: req.IncludeSynonyms, |
| 114 |
IncludeDocumentation: req.IncludeDocumentation, |
| 115 |
}) |
| 116 |
if err != nil { |
| 117 |
return nil, fmt.Errorf("kafka.(*Client).DescribeConfigs: %w", err) |
| 118 |
} |
| 119 |
|
| 120 |
res := m.(*describeconfigs.Response) |
| 121 |
ret := &DescribeConfigsResponse{ |
| 122 |
Throttle: makeDuration(res.ThrottleTimeMs), |
| 123 |
Resources: make([]DescribeConfigResponseResource, len(res.Resources)), |
| 124 |
} |
| 125 |
|
| 126 |
for i, t := range res.Resources { |
| 127 |
|
| 128 |
configEntries := make([]DescribeConfigResponseConfigEntry, len(t.ConfigEntries)) |
| 129 |
for j, v := range t.ConfigEntries { |
| 130 |
|
| 131 |
configSynonyms := make([]DescribeConfigResponseConfigSynonym, len(v.ConfigSynonyms)) |
| 132 |
for k, cs := range v.ConfigSynonyms { |
| 133 |
configSynonyms[k] = DescribeConfigResponseConfigSynonym{ |
| 134 |
ConfigName: cs.ConfigName, |
| 135 |
ConfigValue: cs.ConfigValue, |
| 136 |
ConfigSource: cs.ConfigSource, |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
configEntries[j] = DescribeConfigResponseConfigEntry{ |
| 141 |
ConfigName: v.ConfigName, |
| 142 |
ConfigValue: v.ConfigValue, |
| 143 |
ReadOnly: v.ReadOnly, |
| 144 |
ConfigSource: v.ConfigSource, |
| 145 |
IsDefault: v.IsDefault, |
| 146 |
IsSensitive: v.IsSensitive, |
| 147 |
ConfigSynonyms: configSynonyms, |
| 148 |
ConfigType: v.ConfigType, |
| 149 |
ConfigDocumentation: v.ConfigDocumentation, |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
ret.Resources[i] = DescribeConfigResponseResource{ |
| 154 |
ResourceType: t.ResourceType, |
| 155 |
ResourceName: t.ResourceName, |
| 156 |
Error: makeError(t.ErrorCode, t.ErrorMessage), |
| 157 |
ConfigEntries: configEntries, |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
return ret, nil |
| 162 |
} |