GetIntegrationInfo handles the integration info request
(c *gin.Context)
| 29 | |
| 30 | // GetIntegrationInfo handles the integration info request |
| 31 | func (s *Server) GetIntegrationInfo(c *gin.Context) { |
| 32 | key := c.Query("key") |
| 33 | if key == "" { |
| 34 | response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, "Proxy key is required")) |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | path := c.Request.URL.Path |
| 39 | isGroupSpecific := strings.HasPrefix(path, "/proxy/") |
| 40 | |
| 41 | var groupsToCheck []*models.Group |
| 42 | |
| 43 | if isGroupSpecific { |
| 44 | parts := strings.Split(strings.TrimPrefix(path, "/proxy/"), "/") |
| 45 | if len(parts) == 0 || parts[0] == "" { |
| 46 | response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, "Invalid group path")) |
| 47 | return |
| 48 | } |
| 49 | |
| 50 | groupName := parts[0] |
| 51 | |
| 52 | // Get group from GroupManager cache (already has ProxyKeysMap parsed) |
| 53 | group, err := s.GroupManager.GetGroupByName(groupName) |
| 54 | if err != nil { |
| 55 | response.Error(c, app_errors.NewAPIError(app_errors.ErrResourceNotFound, "Group not found")) |
| 56 | return |
| 57 | } |
| 58 | |
| 59 | groupsToCheck = []*models.Group{group} |
| 60 | } else { |
| 61 | // Get all groups |
| 62 | groups, err := s.GroupService.ListGroups(c.Request.Context()) |
| 63 | if err != nil { |
| 64 | response.Error(c, app_errors.NewAPIError(app_errors.ErrInternalServer, "Internal server error")) |
| 65 | return |
| 66 | } |
| 67 | |
| 68 | // Convert to pointer slice and load from cache to get ProxyKeysMap |
| 69 | for i := range groups { |
| 70 | cachedGroup, err := s.GroupManager.GetGroupByName(groups[i].Name) |
| 71 | if err != nil { |
| 72 | logrus.Warnf("Failed to get group %s from cache: %v", groups[i].Name, err) |
| 73 | continue |
| 74 | } |
| 75 | groupsToCheck = append(groupsToCheck, cachedGroup) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | var result []IntegrationGroupInfo |
| 80 | for _, group := range groupsToCheck { |
| 81 | if hasProxyKeyPermission(group, key) { |
| 82 | channelType := getEffectiveChannelType(group) |
| 83 | path := buildPath(isGroupSpecific, group.Name, channelType, group.ValidationEndpoint) |
| 84 | |
| 85 | result = append(result, IntegrationGroupInfo{ |
| 86 | Name: group.Name, |
| 87 | DisplayName: group.DisplayName, |
| 88 | ChannelType: channelType, |
no test coverage detected