remove unused functions

This commit is contained in:
Anthony Rubick
2025-07-19 21:44:56 -07:00
parent 39b5da36d9
commit f9e51bfd27
2 changed files with 1 additions and 56 deletions

View File

@@ -92,19 +92,6 @@ func (m *APIKeyManager) ValidateAPIKeyForEndpoint(endpoint string, method string
return nil, fmt.Errorf("endpoint not permitted for this API key")
}
// RevokeAPIKey revokes an API key
func (m *APIKeyManager) RevokeAPIKey(apiKey string) error {
m.mutex.Lock()
defer m.mutex.Unlock()
if _, exists := m.keys[apiKey]; !exists {
return fmt.Errorf("API key not found")
}
delete(m.keys, apiKey)
return nil
}
// RevokeAPIKeysForPlugin revokes all API keys for a specific plugin
func (m *APIKeyManager) RevokeAPIKeysForPlugin(pluginID string) error {
m.mutex.Lock()
@@ -123,30 +110,3 @@ func (m *APIKeyManager) RevokeAPIKeysForPlugin(pluginID string) error {
return nil
}
// GetAPIKeyForPlugin returns the API key for a plugin (if exists)
func (m *APIKeyManager) GetAPIKeyForPlugin(pluginID string) (*PluginAPIKey, error) {
m.mutex.RLock()
defer m.mutex.RUnlock()
for _, pluginAPIKey := range m.keys {
if pluginAPIKey.PluginID == pluginID {
return pluginAPIKey, nil
}
}
return nil, fmt.Errorf("no API key found for plugin")
}
// ListAPIKeys returns all API keys (for debugging purposes)
func (m *APIKeyManager) ListAPIKeys() []*PluginAPIKey {
m.mutex.RLock()
defer m.mutex.RUnlock()
keys := make([]*PluginAPIKey, 0, len(m.keys))
for _, pluginAPIKey := range m.keys {
keys = append(keys, pluginAPIKey)
}
return keys
}

View File

@@ -19,11 +19,6 @@ func NewPluginAuthMiddleware(apiKeyManager *APIKeyManager) *PluginAuthMiddleware
}
}
// ValidatePluginAPIRequest validates an API request with plugin API key for a specific endpoint
func (m *PluginAuthMiddleware) ValidatePluginAPIRequest(endpoint string, method string, apiKey string) (*PluginAPIKey, error) {
return m.apiKeyManager.ValidateAPIKeyForEndpoint(endpoint, method, apiKey)
}
// WrapHandler wraps an HTTP handler with plugin authentication middleware
func (m *PluginAuthMiddleware) WrapHandler(endpoint string, handler http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
@@ -50,7 +45,7 @@ func (m *PluginAuthMiddleware) WrapHandler(endpoint string, handler http.Handler
apiKey := strings.TrimPrefix(authHeader, "Bearer ")
// Validate the API key for this endpoint
pluginAPIKey, err := m.ValidatePluginAPIRequest(endpoint, r.Method, apiKey)
pluginAPIKey, err := m.apiKeyManager.ValidateAPIKeyForEndpoint(endpoint, r.Method, apiKey)
if err != nil {
// Invalid API key or endpoint not permitted
http.Error(w, "Unauthorized: Invalid API key or endpoint not permitted", http.StatusUnauthorized)
@@ -65,13 +60,3 @@ func (m *PluginAuthMiddleware) WrapHandler(endpoint string, handler http.Handler
handler(w, r)
}
}
// GetPluginIDFromRequest extracts the plugin ID from the request if authenticated via plugin API key
func GetPluginIDFromRequest(r *http.Request) string {
return r.Header.Get("X-Plugin-ID")
}
// IsPluginAuthenticated checks if the request is authenticated via plugin API key
func IsPluginAuthenticated(r *http.Request) bool {
return r.Header.Get("X-Plugin-Auth") == "true"
}