github.com/streamdal/segmentio-kafka-go@v0.4.47-streamdal/deleteacls.go (about) 1 package kafka 2 3 import ( 4 "context" 5 "fmt" 6 "net" 7 "time" 8 9 "github.com/segmentio/kafka-go/protocol/deleteacls" 10 ) 11 12 // DeleteACLsRequest represents a request sent to a kafka broker to delete 13 // ACLs. 14 type DeleteACLsRequest struct { 15 // Address of the kafka broker to send the request to. 16 Addr net.Addr 17 18 // List of ACL filters to use for deletion. 19 Filters []DeleteACLsFilter 20 } 21 22 type DeleteACLsFilter struct { 23 ResourceTypeFilter ResourceType 24 ResourceNameFilter string 25 ResourcePatternTypeFilter PatternType 26 PrincipalFilter string 27 HostFilter string 28 Operation ACLOperationType 29 PermissionType ACLPermissionType 30 } 31 32 // DeleteACLsResponse represents a response from a kafka broker to an ACL 33 // deletion request. 34 type DeleteACLsResponse struct { 35 // The amount of time that the broker throttled the request. 36 Throttle time.Duration 37 38 // List of the results from the deletion request. 39 Results []DeleteACLsResult 40 } 41 42 type DeleteACLsResult struct { 43 Error error 44 MatchingACLs []DeleteACLsMatchingACLs 45 } 46 47 type DeleteACLsMatchingACLs struct { 48 Error error 49 ResourceType ResourceType 50 ResourceName string 51 ResourcePatternType PatternType 52 Principal string 53 Host string 54 Operation ACLOperationType 55 PermissionType ACLPermissionType 56 } 57 58 // DeleteACLs sends ACLs deletion request to a kafka broker and returns the 59 // response. 60 func (c *Client) DeleteACLs(ctx context.Context, req *DeleteACLsRequest) (*DeleteACLsResponse, error) { 61 filters := make([]deleteacls.RequestFilter, 0, len(req.Filters)) 62 63 for _, filter := range req.Filters { 64 filters = append(filters, deleteacls.RequestFilter{ 65 ResourceTypeFilter: int8(filter.ResourceTypeFilter), 66 ResourceNameFilter: filter.ResourceNameFilter, 67 ResourcePatternTypeFilter: int8(filter.ResourcePatternTypeFilter), 68 PrincipalFilter: filter.PrincipalFilter, 69 HostFilter: filter.HostFilter, 70 Operation: int8(filter.Operation), 71 PermissionType: int8(filter.PermissionType), 72 }) 73 } 74 75 m, err := c.roundTrip(ctx, req.Addr, &deleteacls.Request{ 76 Filters: filters, 77 }) 78 if err != nil { 79 return nil, fmt.Errorf("kafka.(*Client).DeleteACLs: %w", err) 80 } 81 82 res := m.(*deleteacls.Response) 83 84 results := make([]DeleteACLsResult, 0, len(res.FilterResults)) 85 86 for _, result := range res.FilterResults { 87 matchingACLs := make([]DeleteACLsMatchingACLs, 0, len(result.MatchingACLs)) 88 89 for _, matchingACL := range result.MatchingACLs { 90 matchingACLs = append(matchingACLs, DeleteACLsMatchingACLs{ 91 Error: makeError(matchingACL.ErrorCode, matchingACL.ErrorMessage), 92 ResourceType: ResourceType(matchingACL.ResourceType), 93 ResourceName: matchingACL.ResourceName, 94 ResourcePatternType: PatternType(matchingACL.ResourcePatternType), 95 Principal: matchingACL.Principal, 96 Host: matchingACL.Host, 97 Operation: ACLOperationType(matchingACL.Operation), 98 PermissionType: ACLPermissionType(matchingACL.PermissionType), 99 }) 100 } 101 102 results = append(results, DeleteACLsResult{ 103 Error: makeError(result.ErrorCode, result.ErrorMessage), 104 MatchingACLs: matchingACLs, 105 }) 106 } 107 108 ret := &DeleteACLsResponse{ 109 Throttle: makeDuration(res.ThrottleTimeMs), 110 Results: results, 111 } 112 113 return ret, nil 114 }