(ctx context.Context)
| 4724 | } |
| 4725 | |
| 4726 | func homeQueryCredentialFromContext(ctx context.Context) (string, bool) { |
| 4727 | if ctx == nil { |
| 4728 | return "", false |
| 4729 | } |
| 4730 | if queryCtx, ok := ctx.Value("gin").(interface{ Query(string) string }); ok && queryCtx != nil { |
| 4731 | if apiKey := strings.TrimSpace(queryCtx.Query("key")); apiKey != "" { |
| 4732 | return apiKey, true |
| 4733 | } |
| 4734 | if apiKey := strings.TrimSpace(queryCtx.Query("auth_token")); apiKey != "" { |
| 4735 | return apiKey, true |
| 4736 | } |
| 4737 | } |
| 4738 | ginCtx, ok := ctx.Value("gin").(interface{ Get(string) (any, bool) }) |
| 4739 | if !ok || ginCtx == nil { |
| 4740 | return "", false |
| 4741 | } |
| 4742 | rawMetadata, ok := ginCtx.Get("accessMetadata") |
| 4743 | if !ok { |
| 4744 | return "", false |
| 4745 | } |
| 4746 | source := accessMetadataSource(rawMetadata) |
| 4747 | if source != "query-key" && source != "query-auth-token" { |
| 4748 | return "", false |
| 4749 | } |
| 4750 | rawAPIKey, ok := ginCtx.Get("userApiKey") |
| 4751 | if !ok { |
| 4752 | return "", false |
| 4753 | } |
| 4754 | apiKey := contextStringValue(rawAPIKey) |
| 4755 | if apiKey == "" { |
| 4756 | return "", false |
| 4757 | } |
| 4758 | return apiKey, true |
| 4759 | } |
| 4760 | |
| 4761 | func accessMetadataSource(raw any) string { |
| 4762 | switch v := raw.(type) { |
no test coverage detected