github.com/QuangHoangHao/kafka-go@v0.4.36/describeconfigs.go (about) 1 package kafka 2 3 import ( 4 "context" 5 "fmt" 6 "net" 7 "time" 8 9 "github.com/QuangHoangHao/kafka-go/protocol/describeconfigs" 10 ) 11 12 // DescribeConfigsRequest represents a request sent to a kafka broker to describe configs. 13 type DescribeConfigsRequest struct { 14 // Address of the kafka broker to send the request to. 15 Addr net.Addr 16 17 // List of resources to update. 18 Resources []DescribeConfigRequestResource 19 20 // Ignored if API version is less than v1 21 IncludeSynonyms bool 22 23 // Ignored if API version is less than v3 24 IncludeDocumentation bool 25 } 26 27 type DescribeConfigRequestResource struct { 28 // Resource Type 29 ResourceType ResourceType 30 31 // Resource Name 32 ResourceName string 33 34 // ConfigNames is a list of configurations to update. 35 ConfigNames []string 36 } 37 38 // DescribeConfigsResponse represents a response from a kafka broker to a describe config request. 39 type DescribeConfigsResponse struct { 40 // The amount of time that the broker throttled the request. 41 Throttle time.Duration 42 43 // Resources 44 Resources []DescribeConfigResponseResource 45 } 46 47 // DescribeConfigResponseResource. 48 type DescribeConfigResponseResource struct { 49 // Resource Type 50 ResourceType int8 51 52 // Resource Name 53 ResourceName string 54 55 // Error 56 Error error 57 58 // ConfigEntries 59 ConfigEntries []DescribeConfigResponseConfigEntry 60 } 61 62 // DescribeConfigResponseConfigEntry. 63 type DescribeConfigResponseConfigEntry struct { 64 ConfigName string 65 ConfigValue string 66 ReadOnly bool 67 68 // Ignored if API version is greater than v0 69 IsDefault bool 70 71 // Ignored if API version is less than v1 72 ConfigSource int8 73 74 IsSensitive bool 75 76 // Ignored if API version is less than v1 77 ConfigSynonyms []DescribeConfigResponseConfigSynonym 78 79 // Ignored if API version is less than v3 80 ConfigType int8 81 82 // Ignored if API version is less than v3 83 ConfigDocumentation string 84 } 85 86 // DescribeConfigResponseConfigSynonym. 87 type DescribeConfigResponseConfigSynonym struct { 88 // Ignored if API version is less than v1 89 ConfigName string 90 91 // Ignored if API version is less than v1 92 ConfigValue string 93 94 // Ignored if API version is less than v1 95 ConfigSource int8 96 } 97 98 // DescribeConfigs sends a config altering request to a kafka broker and returns the 99 // response. 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 }