d291dcdc74
agent_api (HTTP server), agent_log (structured logging), agent_events (event bus), agent_console (GameConsole), agent_replay (snapshots), agent_vision (depth/segmentation), agent_fbx (bone remapping), agent_auth (multi-agent), agent_analytics (feature flags + tracking) All modules compile clean with mono. Binary uploaded to S3 v1.0.0. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
80 lines
1.8 KiB
C++
80 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include "core/object/class_db.h"
|
|
#include "core/object/object.h"
|
|
#include "core/os/mutex.h"
|
|
#include "core/string/ustring.h"
|
|
#include "core/variant/dictionary.h"
|
|
#include "core/variant/array.h"
|
|
|
|
class AgentAuth : public Object {
|
|
GDCLASS(AgentAuth, Object);
|
|
|
|
static AgentAuth *singleton;
|
|
|
|
public:
|
|
static AgentAuth *get_singleton() { return singleton; }
|
|
|
|
enum Permission {
|
|
PERM_READ = 1,
|
|
PERM_WRITE = 2,
|
|
PERM_EXECUTE = 4,
|
|
PERM_ALL = 7,
|
|
};
|
|
|
|
struct AgentSession {
|
|
String agent_id;
|
|
String agent_name;
|
|
String token;
|
|
uint32_t permissions = PERM_ALL;
|
|
uint64_t connected_at = 0;
|
|
uint64_t last_activity = 0;
|
|
int request_count = 0;
|
|
};
|
|
|
|
struct AuditEntry {
|
|
uint64_t timestamp_msec = 0;
|
|
String agent_id;
|
|
String method;
|
|
String path;
|
|
int status_code = 0;
|
|
};
|
|
|
|
private:
|
|
HashMap<String, AgentSession> sessions; // token -> session
|
|
Vector<AuditEntry> audit_log;
|
|
Mutex auth_mutex;
|
|
|
|
int max_requests_per_minute = 600;
|
|
static constexpr int MAX_AUDIT = 10000;
|
|
|
|
String _generate_token();
|
|
|
|
protected:
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
AgentAuth();
|
|
~AgentAuth();
|
|
|
|
// Registration.
|
|
Dictionary register_agent(const String &p_name, uint32_t p_permissions = PERM_ALL);
|
|
void unregister_agent(const String &p_token);
|
|
|
|
// Validation.
|
|
bool validate_token(const String &p_token);
|
|
bool check_permission(const String &p_token, Permission p_perm);
|
|
void record_activity(const String &p_token, const String &p_method, const String &p_path, int p_status);
|
|
|
|
// Rate limiting.
|
|
bool check_rate_limit(const String &p_token);
|
|
void set_max_requests_per_minute(int p_max) { max_requests_per_minute = p_max; }
|
|
|
|
// Query.
|
|
Array get_agents() const;
|
|
Array get_audit_log(int p_count = 100) const;
|
|
Dictionary get_agent_info(const String &p_token) const;
|
|
};
|
|
|
|
VARIANT_ENUM_CAST(AgentAuth::Permission);
|