diff --git a/.gitignore b/.gitignore index 505a3b1..6705668 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,28 @@ -# Python-generated files -__pycache__/ -*.py[oc] -build/ -dist/ -wheels/ -*.egg-info +# Created by https://www.toptal.com/developers/gitignore/api/go +# Edit at https://www.toptal.com/developers/gitignore?templates=go -# Virtual environments -.venv +### Go ### +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +# End of https://www.toptal.com/developers/gitignore/api/go +build/ diff --git a/.python-version b/.python-version deleted file mode 100644 index 24ee5b1..0000000 --- a/.python-version +++ /dev/null @@ -1 +0,0 @@ -3.13 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2bfeca9 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +.PHONY: build-agent +build-agent: + mkdir -p build + go build -o build/lg-agent cmd/agent/main.go + +.PHONY: run-agent +run-agent: build-agent + build/lg-agent diff --git a/agent/README.md b/agent/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/agent/app.py b/agent/app.py deleted file mode 100644 index 16e2e4c..0000000 --- a/agent/app.py +++ /dev/null @@ -1,87 +0,0 @@ -import tomllib -import os - -from flask import Flask, abort, json, jsonify, request -from werkzeug.exceptions import HTTPException -from pybird import PyBird -from dotenv import load_dotenv - -from modules.bird import parse_raw_output - -load_dotenv() - -app = Flask(__name__) - -CONFIG_FILE_PATH = os.getenv('LG_AGENT_CONFIG_PATH', '/etc/m4n5-lg/agent.toml') - -# Load configuration from TOML file -with open(CONFIG_FILE_PATH, "rb") as f: - config = tomllib.load(f) - -CONF_SOCKET_PATH = config['socket_path'] -SHARED_SECRET = config['shared_secret'] - -def is_authenticated(): - if not SHARED_SECRET: - return True - - # Check if the shared secret in the headers matches the configured shared secret - auth_header = request.headers.get("Authorization") - if auth_header and auth_header == f"Bearer {SHARED_SECRET}": - return True - return False - -@app.before_request -def ensure_authenticated(): - if not is_authenticated(): - return jsonify({"error": "Unauthorized access"}), 401 - -@app.errorhandler(HTTPException) -def handle_exception(e): - """Return JSON instead of HTML for HTTP errors.""" - # start with the correct headers and status code from the error - response = e.get_response() - # replace the body with JSON - response.data = json.dumps({ - "code": e.code, - "name": e.name, - "description": e.description, - }) - response.content_type = "application/json" - return response - -def restrict_bird(pb): - output = pb._send_query("restrict") - if not output.find("Access restricted"): - abort(500, "failed to restrict bird session") - -@app.route("/health") -def health(): - return jsonify({"status": "ok"}) - -@app.route("/bird/status") -def bird_status(): - pb = PyBird(CONF_SOCKET_PATH) - restrict_bird(pb) - return jsonify(pb.get_bird_status()) - -@app.route("/bird/peers") -def bird_peers(): - pb = PyBird(CONF_SOCKET_PATH) - restrict_bird(pb) - return jsonify(pb.get_peer_status()) - -@app.route("/bird/prefix/") -def bird_routes(prefix): - pb = PyBird(CONF_SOCKET_PATH) - restrict_bird(pb) - res = pb.get_prefix_info(prefix) - return jsonify(res) - -@app.route("/bird/command/") -def bird_command(cmd): - pb = PyBird(CONF_SOCKET_PATH) - restrict_bird(pb) - output = pb._send_query(cmd) - (status, result) = parse_raw_output(output) - return jsonify({"status": status, "result": result}) diff --git a/agent/modules/bird.py b/agent/modules/bird.py deleted file mode 100644 index ce08dac..0000000 --- a/agent/modules/bird.py +++ /dev/null @@ -1,85 +0,0 @@ -SUCCESS_CODES = { - "0000" : "OK", - "0001" : "Welcome", - "0002" : "Reading configuration", - "0003" : "Reconfigured", - "0004" : "Reconfiguration in progress", - "0005" : "Reconfiguration already in progress, queueing", - "0006" : "Reconfiguration ignored, shutting down", - "0007" : "Shutdown ordered", - "0008" : "Already disabled", - "0009" : "Disabled", - "0010" : "Already enabled", - "0011" : "Enabled", - "0012" : "Restarted", - "0013" : "Status report", - "0014" : "Route count", - "0015" : "Reloading", - "0016" : "Access restricted", -} - -TABLES_ENTRY_CODES = { - "1000" : "BIRD version", - "1001" : "Interface list", - "1002" : "Protocol list", - "1003" : "Interface address", - "1004" : "Interface flags", - "1005" : "Interface summary", - "1006" : "Protocol details", - "1007" : "Route list", - "1008" : "Route details", - "1009" : "Static route list", - "1010" : "Symbol list", - "1011" : "Uptime", - "1012" : "Route extended attribute list", - "1013" : "Show ospf neighbors", - "1014" : "Show ospf", - "1015" : "Show ospf interface", - "1016" : "Show ospf state/topology", - "1017" : "Show ospf lsadb", - "1018" : "Show memory", -} - -ERROR_CODES = { - "8000" : "Reply too long", - "8001" : "Route not found", - "8002" : "Configuration file error", - "8003" : "No protocols match", - "8004" : "Stopped due to reconfiguration", - "8005" : "Protocol is down => cannot dump", - "8006" : "Reload failed", - "8007" : "Access denied", - - "9000" : "Command too long", - "9001" : "Parse error", - "9002" : "Invalid symbol type", -} - -END_CODES = list(ERROR_CODES.keys()) + list(SUCCESS_CODES.keys()) - -def parse_raw_output(input): - code = "7000" # Not used in bird - parsed_string = "" - - lines = input.split("\n")[1:] - - while code not in END_CODES: - for line in lines: - linecode = line[0:4] - iscode = linecode.isdigit() - if iscode: - code = linecode - - if iscode and code in END_CODES and line[4] == " ": - parsed_string += line[5:] + "\n" - break - elif iscode and code in END_CODES: - parsed_string += line[5:] + "\n" - elif iscode: - parsed_string += line[5:] + "\n" - elif code[0] in ["1", "2"]: - parsed_string += line[1:] + "\n" - else: - parsed_string += "<<>>\n"%line - - return code, parsed_string diff --git a/agent/pyproject.toml b/agent/pyproject.toml deleted file mode 100644 index 0cd3513..0000000 --- a/agent/pyproject.toml +++ /dev/null @@ -1,12 +0,0 @@ -[project] -name = "agent" -version = "0.1.0" -description = "Add your description here" -readme = "README.md" -requires-python = ">=3.13" -dependencies = [ - "dotenv>=0.9.9", - "flask>=3.1.1", - #"pybird>=1.2.0", - "pybird@git+https://github.com/mansziesel/pybird.git", -] diff --git a/backend/README.md b/backend/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/backend/app.py b/backend/app.py deleted file mode 100644 index 844b56e..0000000 --- a/backend/app.py +++ /dev/null @@ -1,184 +0,0 @@ -import tomllib -import os -import requests -import logging -import time - -from functools import wraps -from flask import Flask, abort, json, jsonify, request -from dotenv import load_dotenv -from werkzeug.exceptions import HTTPException - -load_dotenv() - -app = Flask(__name__) - -logging.basicConfig(level=logging.INFO) - -CONFIG_FILE_PATH = os.getenv('LG_AGENT_CONFIG_PATH', '/etc/m4n5-lg/backend.toml') - -with open(CONFIG_FILE_PATH, "rb") as f: - config = tomllib.load(f) - print(config) - -RATE_LIMIT_REQUESTS = config['rate_limit']['requests'] -RATE_LIMIT_WINDOW = config['rate_limit']['time_window'] - -# Dictionary to store request timestamps -request_times = {} - -def rate_limit(func): - """ - Rate limit decorator to restrict the number of requests from a single IP address. - - This decorator allows a specified number of requests (RATE_LIMIT_REQUESTS) - from a single IP address within a defined time window in seconds (RATE_LIMIT_WINDOW). - If the limit is exceeded, a 429 status code is returned with an error message. - """ - @wraps(func) - def wrapper(*args, **kwargs): - ip = request.remote_addr - current_time = time.time() - - # Initialize the request log for the IP if it doesn't exist - if ip not in request_times: - request_times[ip] = [] - - # Remove timestamps that are outside the time window - request_times[ip] = [timestamp for timestamp in request_times[ip] if current_time - timestamp < RATE_LIMIT_WINDOW] - - # Check if the rate limit has been exceeded - if len(request_times[ip]) >= RATE_LIMIT_REQUESTS: - return abort(429, "Too many requests, please try again later.") - - # Log the current request timestamp - request_times[ip].append(current_time) - - return func(*args, **kwargs) - - return wrapper - -@app.errorhandler(HTTPException) -def handle_exception(e): - """Return JSON instead of HTML for HTTP errors, only for /api paths.""" - if request.path.startswith('/api'): - # Start with the correct headers and status code from the error - response = e.get_response() - # Replace the body with JSON - response.data = json.dumps({ - "code": e.code, - "name": e.name, - "description": e.description, - }) - response.content_type = "application/json" - return response - # If the path does not start with /api, return the default error response - return e.get_response() # This will return the default HTML response - -def handle_agent_exceptions(func): - """A decorator to handle exceptions when interacting with router agents.""" - @wraps(func) # Preserve the original function's metadata - def wrapper(*args, **kwargs): - try: - return func(*args, **kwargs) - except HTTPException: - # If an HTTPException is raised, we don't want to log it or abort again - raise # Re-raise the HTTPException to let Flask handle it - except ValueError as ve: - logging.error(f"ValueError: {ve}") - abort(400, description=str(ve)) - except requests.exceptions.RequestException as req_err: - logging.error(f"RequestException: {req_err}") - abort(502, description="Bad Gateway: Unable to reach the router agent.") - except Exception as e: - logging.error(f"Unexpected error: {e}") - abort(500, description="Internal Server Error: An unexpected error occurred.") - return wrapper - -@app.route("/health") -def health(): - return jsonify({"status": "ok"}) - -@app.route("/api/routers") -@handle_agent_exceptions -def api_routers(): - routers = [ - { - "name": router_info['code'], - "description": router_info['description'] - } - for router_info in config['routers'].values() - ] - if len(routers) < 1: - abort(500, "failed to retrieve routers") - return jsonify(routers) - -@app.route("/api/bird/status/") -@rate_limit -@handle_agent_exceptions -def api_bird_status(code): - router = get_router_by_code(code) - - if router is None: - abort(404, description="Router not found.") - - status = get_router_status(router['agent']) - return jsonify(status) - -@app.route("/api/bird/routes//") -@rate_limit -@handle_agent_exceptions -def api_bird_routes(code, prefix): - router = get_router_by_code(code) - if router is None: - abort(404, description="Router not found.") - routes = get_router_routes(router['agent'], prefix) - return jsonify(routes) - -def get_router_by_code(code): - if code not in config["routers"]: - return None - return config["routers"][code] - -def _make_agent_request_streaming(host, port, path, method): - url = f"http://{host}:{port}{path}" - try: - if method == "GET": - response = requests.get(url, stream=True) - elif method == "POST": - response = requests.post(url, stream=True) - else: - raise ValueError(f"Method '{method}' is not allowed. Only 'GET' and 'POST' are permitted.") - - return response.iter_content(chunk_size=1024) # Adjust chunk_size as needed - except requests.exceptions.RequestException as e: - logging.error(f"Request failed: {e}") - raise - -def _make_agent_request(host, port, path, method): - url = f"http://{host}:{port}{path}" - try: - if method == "GET": - response = requests.get(url) - elif method == "POST": - response = requests.post(url) - else: - raise ValueError(f"Method '{method}' is not allowed. Only 'GET' and 'POST' are permitted.") - return response - except requests.exceptions.RequestException as e: - logging.error(f"Request failed: {e}") - raise - -def get_router_status(agent): - res = _make_agent_request(host=agent['host'], port=agent['port'], method="GET", path="/bird/status") - if res.status_code != 200: - logging.error(f"Error fetching router status: {res.status_code} - {res.text}") - res.raise_for_status() - return res.json() - -def get_router_routes(agent, prefix): - res = _make_agent_request(host=agent['host'], port=agent['port'], method="GET", path=f"/bird/prefix/{prefix}") - if res.status_code != 200: - logging.error(f"Error fetching router status: {res.status_code} - {res.text}") - res.raise_for_status() - return res.json() diff --git a/backend/pyproject.toml b/backend/pyproject.toml deleted file mode 100644 index bec26ed..0000000 --- a/backend/pyproject.toml +++ /dev/null @@ -1,9 +0,0 @@ -[project] -name = "backend" -version = "0.1.0" -description = "Add your description here" -readme = "README.md" -requires-python = ">=3.13" -dependencies = [ - "requests>=2.32.4", -] diff --git a/cmd/agent/main.go b/cmd/agent/main.go new file mode 100644 index 0000000..32b9e1e --- /dev/null +++ b/cmd/agent/main.go @@ -0,0 +1,233 @@ +package main + +import ( + "bufio" + "encoding/json" + "errors" + "fmt" + "log" + "net" + "net/http" + "os" + "os/exec" + + "git.mziesel.nl/mans/lg/internal/socket" +) + +type LgAgentConfig struct { + Host string `json:"host"` + Port int `json:"port"` + SocketPath string `json:"socket_path"` + SharedSecret string `json:"shared_secret"` +} + +var config LgAgentConfig + +func loadConfig() LgAgentConfig { + // Default configuration + config = LgAgentConfig{ + Host: "localhost", + Port: 3000, + SocketPath: "/var/run/bird/bird.ctl", + SharedSecret: "", // empty = no secret + } + + // Determine the config file path + configPath := "/etc/lg-agent/agent.json" + if envPath := os.Getenv("LG_AGENT_CONFIG_PATH"); envPath != "" { + configPath = envPath + } + + // Open the configuration file + file, err := os.Open(configPath) + if err != nil { + log.Fatalf("Error opening config file: %v.", err) + return config + } + defer file.Close() + + // Decode the JSON configuration + decoder := json.NewDecoder(file) + if err := decoder.Decode(&config); err != nil { + log.Fatalf("Error decoding config file: %v.", err) + } + + return config +} + +func isAuthenticated(r *http.Request) bool { + if config.SharedSecret == "" { + return true + } + + authHeader := r.Header.Get("Authorization") + return authHeader == fmt.Sprintf("Bearer %s", config.SharedSecret) +} + +func ensureAuthenticatedMiddleware(next http.HandlerFunc) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + if !isAuthenticated(r) { + http.Error(w, "Unauthorized access", http.StatusUnauthorized) + return + } + next.ServeHTTP(w, r) + } +} + +func plainTextMiddleware(next http.HandlerFunc) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + next(w, r) + } +} + +func middlewareChain(h http.HandlerFunc) http.HandlerFunc { + return plainTextMiddleware(ensureAuthenticatedMiddleware(h)) +} + +func healthHandler(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + _, err := w.Write([]byte("status: ok")) + if err != nil { + log.Println(err) + } +} + +func birdStatusHandler(w http.ResponseWriter, r *http.Request) { + s := socket.NewBirdSocket(config.SocketPath, 4092, true) + s.Connect() + defer s.Close() + status, _, err := s.Send("show status") + if err != nil { + http.Error(w, "Internal Server Error: failed to query router status", http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusOK) + _, err = w.Write([]byte("status: " + string(status))) + if err != nil { + log.Println(err) + } +} + +func birdCommandHandler(w http.ResponseWriter, r *http.Request) { + command := r.URL.Query().Get("c") + if command == "" { + http.Error(w, "Bad Request: command parameter is required", http.StatusBadRequest) + return + } + + s := socket.NewBirdSocket(config.SocketPath, 4092, true) + s.Connect() + defer s.Close() + output, _, err := s.Send(command) + if err != nil { + http.Error(w, "Internal Server Error: failed to query bird", http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusOK) + _, err = w.Write([]byte(string(output))) + if err != nil { + log.Println(err) + } +} + +func createCommand(tool string, target string) (*exec.Cmd, error) { + commands := map[string][]string{ + "ping": {"ping", "-4", "-c", "4", "--", target}, + "ping6": {"ping", "-6", "-c", "4", "--", target}, + "mtr": {"mtr", "--show-ips", "--aslookup", "--report-wide", "-c", "10", "-4", target}, + "mtr6": {"mtr", "--show-ips", "--aslookup", "--report-wide", "-c", "10", "-6", target}, + "traceroute": {"traceroute", "-n", "-4", "--", target}, + "traceroute6": {"traceroute", "-n", "-6", "--", target}, + } + if cmdArgs, exists := commands[tool]; exists { + path, err := exec.LookPath(cmdArgs[0]) + if err != nil { + return nil, err + } + cmd := exec.Command(path, cmdArgs[1:]...) + return cmd, nil + } + return nil, errors.New("Command is not allowed") +} + +func isValidTarget(target string) error { + addr, err := net.ResolveIPAddr("ip", target) + if err != nil { + return err + } + if addr.IP.IsPrivate() { + return errors.New("RFC 1918 and RFC 4193 address space is not allowed") + } + return nil +} + +func executeStreaming(w http.ResponseWriter, r *http.Request) { + tool := r.URL.Query().Get("tool") + target := r.URL.Query().Get("target") + + err := isValidTarget(target) + + if err != nil { + http.Error(w, fmt.Sprintf("Bad Target: %s", err), http.StatusBadRequest) + return + } + + w.Header().Set("Content-Type", "text/event-stream") + w.Header().Set("Cache-Control", "no-cache") + w.Header().Set("Connection", "keep-alive") + + cmd, err := createCommand(tool, target) + if err != nil { + http.Error(w, "Internal Server Error: failed to create command", http.StatusInternalServerError) + log.Printf("ERROR: Failed to create command: %s\n", err) + return + } + stdout, err := cmd.StdoutPipe() + if err != nil { + http.Error(w, "Internal Server Error: failed to open pipe to CMD output", http.StatusInternalServerError) + log.Printf("ERROR: Failed to open pipe to CMD output: %s\n", err) + return + } + cmd.Stderr = cmd.Stdout + err = cmd.Start() + if err != nil { + http.Error(w, "Internal Server Error: failed to start command", http.StatusInternalServerError) + log.Printf("ERROR: Failed to start command: %s\n", err) + return + } + + scanner := bufio.NewScanner(stdout) + scanner.Split(bufio.ScanLines) + + _, pw, _ := os.Pipe() + cmd.Stdout = pw + cmd.Stdout = pw + + for scanner.Scan() { + fmt.Fprintf(w, "%s\n", scanner.Bytes()) + if f, ok := w.(http.Flusher); ok { + f.Flush() + } + } +} + +func main() { + config := loadConfig() + formattedConfig, err := json.MarshalIndent(config, "", " ") + if err != nil { + log.Fatalf("Error formatting config: %v", err) + } + log.Printf("Loaded configuration: %s\n", formattedConfig) + + mux := http.NewServeMux() + + mux.HandleFunc("/health", middlewareChain(healthHandler)) + mux.HandleFunc("/bird/status", middlewareChain(birdStatusHandler)) + mux.HandleFunc("/bird/command", middlewareChain(birdCommandHandler)) + mux.HandleFunc("/exec", middlewareChain(executeStreaming)) + + log.Printf("starting listner on %s:%d\n", config.Host, config.Port) + + log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", config.Host, config.Port), mux)) +} diff --git a/cmd/backend/main.go b/cmd/backend/main.go new file mode 100644 index 0000000..00a35e4 --- /dev/null +++ b/cmd/backend/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "net/http" + "time" +) + +func greet(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello World! %s", time.Now()) +} + +func main() { + http.HandleFunc("/", greet) + http.ListenAndServe(":8080", nil) +} diff --git a/config/agent.json b/config/agent.json new file mode 100644 index 0000000..3945f31 --- /dev/null +++ b/config/agent.json @@ -0,0 +1,6 @@ +{ + "host": "127.0.0.1", + "port": 4242, + "socket_path": "/var/run/bird/bird.ctl", + "shared_secret": "" +} diff --git a/config/agent.toml b/config/agent.toml deleted file mode 100644 index 6807356..0000000 --- a/config/agent.toml +++ /dev/null @@ -1,4 +0,0 @@ -host = "127.0.0.1" -port = 4242 -socket_path = "/var/run/bird/bird.ctl" -shared_secret = "" diff --git a/config/backend.json b/config/backend.json new file mode 100644 index 0000000..f4bc76d --- /dev/null +++ b/config/backend.json @@ -0,0 +1,31 @@ +{ + "lg": { + "name": "Mans's looking glass" + }, + "rate_limit": { + "requests": 20, + "time_window": 300 + }, + "routers": { + "nur01": { + "code": "nur01", + "description": "BIRD2 router in Wierden", + "ipv4": "127.0.0.1", + "ipv6": "fe80::1", + "agent": { + "host": "127.0.0.1", + "port": "4242" + } + }, + "wie01": { + "code": "wie01", + "description": "BIRD2 router in Nuremberg", + "ipv4": "127.0.0.1", + "ipv6": "fe80::1", + "agent": { + "host": "127.0.0.1", + "port": "4243" + } + } + } +} diff --git a/config/backend.toml b/config/backend.toml deleted file mode 100644 index 95e35c9..0000000 --- a/config/backend.toml +++ /dev/null @@ -1,28 +0,0 @@ -[lg] -name = "Mans's looking glass" - -[rate_limit] -requests = 20 -time_window = 300 - -[routers] - -[routers.nur01] -code = "nur01" -description = "BIRD2 router in Wierden" -ipv4 = "127.0.0.1" -ipv6 = "fe80::1" - -[routers.nur01.agent] -host = "127.0.0.1" -port = "4242" - -[routers.wie01] -code = "wie01" -description = "BIRD2 router in Nuremberg" -ipv4 = "127.0.0.1" -ipv6 = "fe80::1" - -[routers.wie01.agent] -host = "127.0.0.1" -port = "4243" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ae60837 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.mziesel.nl/mans/lg + +go 1.24.4 diff --git a/README.md b/go.sum similarity index 100% rename from README.md rename to go.sum diff --git a/internal/socket/socket.go b/internal/socket/socket.go new file mode 100644 index 0000000..f227d9e --- /dev/null +++ b/internal/socket/socket.go @@ -0,0 +1,173 @@ +package socket + +// taken from, adapted by me +// https://github.com/StatCan/go-birdc/blob/master/socket/socket.go + +import ( + "bufio" + "errors" + "fmt" + "net" + "regexp" + "strings" + "time" +) + +var replyCodeExpr *regexp.Regexp +var contentCodeExpr *regexp.Regexp +var codeExpr *regexp.Regexp + +func init() { + // https://gitlab.nic.cz/labs/bird/-/blob/master/doc/reply_codes + replyCodeExpr = regexp.MustCompile(`(?m)^([089][0-9]{3})`) + contentCodeExpr = regexp.MustCompile(`(?m)^([12][0-9]{3})`) + codeExpr = regexp.MustCompile(`(?m)^([0-9]{4})`) +} + +// BirdSocket represents a socket connection to bird daemon +// +// `path` is the unix socket path +// +// `bufferSize` is the size of the read buffer +// +// `conn` is the actual socket connection +type BirdSocket struct { + path string + bufferSize int + conn net.Conn + restricted bool +} + +// NewBirdSocket creates a new BirdSocket +// +// `path` is the unix socket path +// +// `bufferSize` is the size of the read buffer +func NewBirdSocket(path string, bufferSize int, restricted bool) *BirdSocket { + return &BirdSocket{path: path, bufferSize: bufferSize, restricted: restricted} +} + +// Connect opens the unix socket connection +func (s *BirdSocket) Connect() (err error) { + s.conn, err = net.Dial("unix", s.path) + if err != nil { + return + } + + // throw away the welcome message + buf := make([]byte, s.bufferSize) + _, err = s.conn.Read(buf[:]) + + _, resp_code, err := s.Send("restrict") + if err != nil { + return err + } + if string(resp_code) != "0016" { // access restricted + return errors.New("failed to restrict bird session") + } + + return +} + +// Close closes the unix socket connection +// +// **NOTE** it is important to close the socket connection since, +// in the event that there is still data waiting to be transmitted over the connection, +// close will try to complete the transmission properly +func (s *BirdSocket) Close() { + if s.conn != nil { + s.conn.Close() + } +} + +func (s *BirdSocket) Send(data string) (resp []byte, replyCode []byte, err error) { + err = s.write([]byte(data)) + if err != nil { + return + } + return s.read() +} + +func (s *BirdSocket) write(data []byte) (err error) { + if s.conn == nil { + err = fmt.Errorf("unable to write to socket, connection is not open. Ensure that s.Connect() is called first. %s", s.conn) + return + } + + err = s.conn.SetWriteDeadline(time.Now().Add(30 * time.Second)) + if err != nil { + return + } + _, err = s.conn.Write([]byte(strings.Trim(string(data), "\n") + "\n")) + return +} + +// read reads data from the socket connection and captures the replyCode that indicated the end of transmissions +// and any associated response or error +// +// For more information on reply codes, see https://gitlab.nic.cz/labs/bird/-/blob/master/doc/reply_codes +// +// `resp` is the raw response from BIRD +// +// `replyCode` is the reply code associated with the response +func (s *BirdSocket) read() (resp []byte, code []byte, err error) { + err = s.conn.SetReadDeadline(time.Now().Add(30 * time.Second)) + if err != nil { + return + } + + resp = make([]byte, 0) + code = []byte("7000") + + reader := bufio.NewReader(s.conn) + + for !containsReplyCode(code) { + for { + line, err_inside := reader.ReadBytes('\n') + if err_inside != nil { + return nil, nil, err_inside + } + + linecode := line[0:4] + + isCode := containsCode(linecode) + + if isCode { + code = linecode + } + + // ' ' as 5th char means end of output, otherwise will continue on other line, do not break loop + if isCode && containsReplyCode(code) { + // do not append the last line as it will be another '\n' + resp = append(resp, line[5:len(line)-1]...) + break + } else if isCode { + resp = append(resp, line[5:]...) + } else if containsContentCode(code) { + resp = append(resp, line[1:]...) + } else { + fallback := fmt.Appendf([]byte("<<>>") + resp = append(resp, fallback...) + err = errors.New("unparsable string") + break + } + } + if err != nil { + return + } + } + + return +} + +func containsCode(b []byte) bool { + return codeExpr.Match(b) +} + +func containsContentCode(b []byte) bool { + return contentCodeExpr.Match(b) +} + +func containsReplyCode(b []byte) bool { + return replyCodeExpr.Match(b) +} diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index e85c8c0..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,25 +0,0 @@ -[project] -name = "lg" -version = "0.1.0" -description = "Bird2 looking glass" -readme = "README.md" -requires-python = ">=3.13" -dependencies = [] - -[tool.uv.workspace] -members = ["agent", "backend"] - -[dependency-groups] -dev = [ - "poethepoet>=0.37.0", -] - -[tool.poe.tasks.agent-dev] -cwd = "agent" -cmd = "uv run -- flask run -p 4242 --debug" -help = "run agent dev server" - -[tool.poe.tasks.backend-dev] -cwd = "backend" -cmd = "uv run -- flask run -p 3000 --debug" -help = "run agent dev server" diff --git a/uv.lock b/uv.lock deleted file mode 100644 index cbce899..0000000 --- a/uv.lock +++ /dev/null @@ -1,298 +0,0 @@ -version = 1 -revision = 3 -requires-python = ">=3.13" - -[manifest] -members = [ - "agent", - "backend", - "lg", -] - -[[package]] -name = "agent" -version = "0.1.0" -source = { virtual = "agent" } -dependencies = [ - { name = "dotenv" }, - { name = "flask" }, - { name = "pybird" }, -] - -[package.metadata] -requires-dist = [ - { name = "dotenv", specifier = ">=0.9.9" }, - { name = "flask", specifier = ">=3.1.1" }, - { name = "pybird", git = "https://github.com/mansziesel/pybird.git" }, -] - -[[package]] -name = "backend" -version = "0.1.0" -source = { virtual = "backend" } -dependencies = [ - { name = "requests" }, -] - -[package.metadata] -requires-dist = [{ name = "requests", specifier = ">=2.32.4" }] - -[[package]] -name = "blinker" -version = "1.9.0" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/21/28/9b3f50ce0e048515135495f198351908d99540d69bfdc8c1d15b73dc55ce/blinker-1.9.0.tar.gz", hash = "sha256:b4ce2265a7abece45e7cc896e98dbebe6cead56bcf805a3d23136d145f5445bf", size = 22460, upload-time = "2024-11-08T17:25:47.436Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/10/cb/f2ad4230dc2eb1a74edf38f1a38b9b52277f75bef262d8908e60d957e13c/blinker-1.9.0-py3-none-any.whl", hash = "sha256:ba0efaa9080b619ff2f3459d1d500c57bddea4a6b424b60a91141db6fd2f08bc", size = 8458, upload-time = "2024-11-08T17:25:46.184Z" }, -] - -[[package]] -name = "certifi" -version = "2025.8.3" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/dc/67/960ebe6bf230a96cda2e0abcf73af550ec4f090005363542f0765df162e0/certifi-2025.8.3.tar.gz", hash = "sha256:e564105f78ded564e3ae7c923924435e1daa7463faeab5bb932bc53ffae63407", size = 162386, upload-time = "2025-08-03T03:07:47.08Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/e5/48/1549795ba7742c948d2ad169c1c8cdbae65bc450d6cd753d124b17c8cd32/certifi-2025.8.3-py3-none-any.whl", hash = "sha256:f6c12493cfb1b06ba2ff328595af9350c65d6644968e5d3a2ffd78699af217a5", size = 161216, upload-time = "2025-08-03T03:07:45.777Z" }, -] - -[[package]] -name = "charset-normalizer" -version = "3.4.3" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/83/2d/5fd176ceb9b2fc619e63405525573493ca23441330fcdaee6bef9460e924/charset_normalizer-3.4.3.tar.gz", hash = "sha256:6fce4b8500244f6fcb71465d4a4930d132ba9ab8e71a7859e6a5d59851068d14", size = 122371, upload-time = "2025-08-09T07:57:28.46Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/65/ca/2135ac97709b400c7654b4b764daf5c5567c2da45a30cdd20f9eefe2d658/charset_normalizer-3.4.3-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:14c2a87c65b351109f6abfc424cab3927b3bdece6f706e4d12faaf3d52ee5efe", size = 205326, upload-time = "2025-08-09T07:56:24.721Z" }, - { url = "https://files.pythonhosted.org/packages/71/11/98a04c3c97dd34e49c7d247083af03645ca3730809a5509443f3c37f7c99/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:41d1fc408ff5fdfb910200ec0e74abc40387bccb3252f3f27c0676731df2b2c8", size = 146008, upload-time = "2025-08-09T07:56:26.004Z" }, - { url = "https://files.pythonhosted.org/packages/60/f5/4659a4cb3c4ec146bec80c32d8bb16033752574c20b1252ee842a95d1a1e/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:1bb60174149316da1c35fa5233681f7c0f9f514509b8e399ab70fea5f17e45c9", size = 159196, upload-time = "2025-08-09T07:56:27.25Z" }, - { url = "https://files.pythonhosted.org/packages/86/9e/f552f7a00611f168b9a5865a1414179b2c6de8235a4fa40189f6f79a1753/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:30d006f98569de3459c2fc1f2acde170b7b2bd265dc1943e87e1a4efe1b67c31", size = 156819, upload-time = "2025-08-09T07:56:28.515Z" }, - { url = "https://files.pythonhosted.org/packages/7e/95/42aa2156235cbc8fa61208aded06ef46111c4d3f0de233107b3f38631803/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:416175faf02e4b0810f1f38bcb54682878a4af94059a1cd63b8747244420801f", size = 151350, upload-time = "2025-08-09T07:56:29.716Z" }, - { url = "https://files.pythonhosted.org/packages/c2/a9/3865b02c56f300a6f94fc631ef54f0a8a29da74fb45a773dfd3dcd380af7/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:6aab0f181c486f973bc7262a97f5aca3ee7e1437011ef0c2ec04b5a11d16c927", size = 148644, upload-time = "2025-08-09T07:56:30.984Z" }, - { url = "https://files.pythonhosted.org/packages/77/d9/cbcf1a2a5c7d7856f11e7ac2d782aec12bdfea60d104e60e0aa1c97849dc/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:fdabf8315679312cfa71302f9bd509ded4f2f263fb5b765cf1433b39106c3cc9", size = 160468, upload-time = "2025-08-09T07:56:32.252Z" }, - { url = "https://files.pythonhosted.org/packages/f6/42/6f45efee8697b89fda4d50580f292b8f7f9306cb2971d4b53f8914e4d890/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:bd28b817ea8c70215401f657edef3a8aa83c29d447fb0b622c35403780ba11d5", size = 158187, upload-time = "2025-08-09T07:56:33.481Z" }, - { url = "https://files.pythonhosted.org/packages/70/99/f1c3bdcfaa9c45b3ce96f70b14f070411366fa19549c1d4832c935d8e2c3/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:18343b2d246dc6761a249ba1fb13f9ee9a2bcd95decc767319506056ea4ad4dc", size = 152699, upload-time = "2025-08-09T07:56:34.739Z" }, - { url = "https://files.pythonhosted.org/packages/a3/ad/b0081f2f99a4b194bcbb1934ef3b12aa4d9702ced80a37026b7607c72e58/charset_normalizer-3.4.3-cp313-cp313-win32.whl", hash = "sha256:6fb70de56f1859a3f71261cbe41005f56a7842cc348d3aeb26237560bfa5e0ce", size = 99580, upload-time = "2025-08-09T07:56:35.981Z" }, - { url = "https://files.pythonhosted.org/packages/9a/8f/ae790790c7b64f925e5c953b924aaa42a243fb778fed9e41f147b2a5715a/charset_normalizer-3.4.3-cp313-cp313-win_amd64.whl", hash = "sha256:cf1ebb7d78e1ad8ec2a8c4732c7be2e736f6e5123a4146c5b89c9d1f585f8cef", size = 107366, upload-time = "2025-08-09T07:56:37.339Z" }, - { url = "https://files.pythonhosted.org/packages/8e/91/b5a06ad970ddc7a0e513112d40113e834638f4ca1120eb727a249fb2715e/charset_normalizer-3.4.3-cp314-cp314-macosx_10_13_universal2.whl", hash = "sha256:3cd35b7e8aedeb9e34c41385fda4f73ba609e561faedfae0a9e75e44ac558a15", size = 204342, upload-time = "2025-08-09T07:56:38.687Z" }, - { url = "https://files.pythonhosted.org/packages/ce/ec/1edc30a377f0a02689342f214455c3f6c2fbedd896a1d2f856c002fc3062/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b89bc04de1d83006373429975f8ef9e7932534b8cc9ca582e4db7d20d91816db", size = 145995, upload-time = "2025-08-09T07:56:40.048Z" }, - { url = "https://files.pythonhosted.org/packages/17/e5/5e67ab85e6d22b04641acb5399c8684f4d37caf7558a53859f0283a650e9/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:2001a39612b241dae17b4687898843f254f8748b796a2e16f1051a17078d991d", size = 158640, upload-time = "2025-08-09T07:56:41.311Z" }, - { url = "https://files.pythonhosted.org/packages/f1/e5/38421987f6c697ee3722981289d554957c4be652f963d71c5e46a262e135/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:8dcfc373f888e4fb39a7bc57e93e3b845e7f462dacc008d9749568b1c4ece096", size = 156636, upload-time = "2025-08-09T07:56:43.195Z" }, - { url = "https://files.pythonhosted.org/packages/a0/e4/5a075de8daa3ec0745a9a3b54467e0c2967daaaf2cec04c845f73493e9a1/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:18b97b8404387b96cdbd30ad660f6407799126d26a39ca65729162fd810a99aa", size = 150939, upload-time = "2025-08-09T07:56:44.819Z" }, - { url = "https://files.pythonhosted.org/packages/02/f7/3611b32318b30974131db62b4043f335861d4d9b49adc6d57c1149cc49d4/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:ccf600859c183d70eb47e05a44cd80a4ce77394d1ac0f79dbd2dd90a69a3a049", size = 148580, upload-time = "2025-08-09T07:56:46.684Z" }, - { url = "https://files.pythonhosted.org/packages/7e/61/19b36f4bd67f2793ab6a99b979b4e4f3d8fc754cbdffb805335df4337126/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:53cd68b185d98dde4ad8990e56a58dea83a4162161b1ea9272e5c9182ce415e0", size = 159870, upload-time = "2025-08-09T07:56:47.941Z" }, - { url = "https://files.pythonhosted.org/packages/06/57/84722eefdd338c04cf3030ada66889298eaedf3e7a30a624201e0cbe424a/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:30a96e1e1f865f78b030d65241c1ee850cdf422d869e9028e2fc1d5e4db73b92", size = 157797, upload-time = "2025-08-09T07:56:49.756Z" }, - { url = "https://files.pythonhosted.org/packages/72/2a/aff5dd112b2f14bcc3462c312dce5445806bfc8ab3a7328555da95330e4b/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:d716a916938e03231e86e43782ca7878fb602a125a91e7acb8b5112e2e96ac16", size = 152224, upload-time = "2025-08-09T07:56:51.369Z" }, - { url = "https://files.pythonhosted.org/packages/b7/8c/9839225320046ed279c6e839d51f028342eb77c91c89b8ef2549f951f3ec/charset_normalizer-3.4.3-cp314-cp314-win32.whl", hash = "sha256:c6dbd0ccdda3a2ba7c2ecd9d77b37f3b5831687d8dc1b6ca5f56a4880cc7b7ce", size = 100086, upload-time = "2025-08-09T07:56:52.722Z" }, - { url = "https://files.pythonhosted.org/packages/ee/7a/36fbcf646e41f710ce0a563c1c9a343c6edf9be80786edeb15b6f62e17db/charset_normalizer-3.4.3-cp314-cp314-win_amd64.whl", hash = "sha256:73dc19b562516fc9bcf6e5d6e596df0b4eb98d87e4f79f3ae71840e6ed21361c", size = 107400, upload-time = "2025-08-09T07:56:55.172Z" }, - { url = "https://files.pythonhosted.org/packages/8a/1f/f041989e93b001bc4e44bb1669ccdcf54d3f00e628229a85b08d330615c5/charset_normalizer-3.4.3-py3-none-any.whl", hash = "sha256:ce571ab16d890d23b5c278547ba694193a45011ff86a9162a71307ed9f86759a", size = 53175, upload-time = "2025-08-09T07:57:26.864Z" }, -] - -[[package]] -name = "click" -version = "8.2.1" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "colorama", marker = "sys_platform == 'win32'" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/60/6c/8ca2efa64cf75a977a0d7fac081354553ebe483345c734fb6b6515d96bbc/click-8.2.1.tar.gz", hash = "sha256:27c491cc05d968d271d5a1db13e3b5a184636d9d930f148c50b038f0d0646202", size = 286342, upload-time = "2025-05-20T23:19:49.832Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/85/32/10bb5764d90a8eee674e9dc6f4db6a0ab47c8c4d0d83c27f7c39ac415a4d/click-8.2.1-py3-none-any.whl", hash = "sha256:61a3265b914e850b85317d0b3109c7f8cd35a670f963866005d6ef1d5175a12b", size = 102215, upload-time = "2025-05-20T23:19:47.796Z" }, -] - -[[package]] -name = "colorama" -version = "0.4.6" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" }, -] - -[[package]] -name = "dotenv" -version = "0.9.9" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "python-dotenv" }, -] -wheels = [ - { url = "https://files.pythonhosted.org/packages/b2/b7/545d2c10c1fc15e48653c91efde329a790f2eecfbbf2bd16003b5db2bab0/dotenv-0.9.9-py2.py3-none-any.whl", hash = "sha256:29cf74a087b31dafdb5a446b6d7e11cbce8ed2741540e2339c69fbef92c94ce9", size = 1892, upload-time = "2025-02-19T22:15:01.647Z" }, -] - -[[package]] -name = "flask" -version = "3.1.1" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "blinker" }, - { name = "click" }, - { name = "itsdangerous" }, - { name = "jinja2" }, - { name = "markupsafe" }, - { name = "werkzeug" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/c0/de/e47735752347f4128bcf354e0da07ef311a78244eba9e3dc1d4a5ab21a98/flask-3.1.1.tar.gz", hash = "sha256:284c7b8f2f58cb737f0cf1c30fd7eaf0ccfcde196099d24ecede3fc2005aa59e", size = 753440, upload-time = "2025-05-13T15:01:17.447Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/3d/68/9d4508e893976286d2ead7f8f571314af6c2037af34853a30fd769c02e9d/flask-3.1.1-py3-none-any.whl", hash = "sha256:07aae2bb5eaf77993ef57e357491839f5fd9f4dc281593a81a9e4d79a24f295c", size = 103305, upload-time = "2025-05-13T15:01:15.591Z" }, -] - -[[package]] -name = "idna" -version = "3.10" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/f1/70/7703c29685631f5a7590aa73f1f1d3fa9a380e654b86af429e0934a32f7d/idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9", size = 190490, upload-time = "2024-09-15T18:07:39.745Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3", size = 70442, upload-time = "2024-09-15T18:07:37.964Z" }, -] - -[[package]] -name = "itsdangerous" -version = "2.2.0" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/9c/cb/8ac0172223afbccb63986cc25049b154ecfb5e85932587206f42317be31d/itsdangerous-2.2.0.tar.gz", hash = "sha256:e0050c0b7da1eea53ffaf149c0cfbb5c6e2e2b69c4bef22c81fa6eb73e5f6173", size = 54410, upload-time = "2024-04-16T21:28:15.614Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/04/96/92447566d16df59b2a776c0fb82dbc4d9e07cd95062562af01e408583fc4/itsdangerous-2.2.0-py3-none-any.whl", hash = "sha256:c6242fc49e35958c8b15141343aa660db5fc54d4f13a1db01a3f5891b98700ef", size = 16234, upload-time = "2024-04-16T21:28:14.499Z" }, -] - -[[package]] -name = "jinja2" -version = "3.1.6" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "markupsafe" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/df/bf/f7da0350254c0ed7c72f3e33cef02e048281fec7ecec5f032d4aac52226b/jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d", size = 245115, upload-time = "2025-03-05T20:05:02.478Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899, upload-time = "2025-03-05T20:05:00.369Z" }, -] - -[[package]] -name = "lg" -version = "0.1.0" -source = { virtual = "." } - -[package.dev-dependencies] -dev = [ - { name = "poethepoet" }, -] - -[package.metadata] - -[package.metadata.requires-dev] -dev = [{ name = "poethepoet", specifier = ">=0.37.0" }] - -[[package]] -name = "markupsafe" -version = "3.0.2" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/b2/97/5d42485e71dfc078108a86d6de8fa46db44a1a9295e89c5d6d4a06e23a62/markupsafe-3.0.2.tar.gz", hash = "sha256:ee55d3edf80167e48ea11a923c7386f4669df67d7994554387f84e7d8b0a2bf0", size = 20537, upload-time = "2024-10-18T15:21:54.129Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/83/0e/67eb10a7ecc77a0c2bbe2b0235765b98d164d81600746914bebada795e97/MarkupSafe-3.0.2-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:ba9527cdd4c926ed0760bc301f6728ef34d841f405abf9d4f959c478421e4efd", size = 14274, upload-time = "2024-10-18T15:21:24.577Z" }, - { url = "https://files.pythonhosted.org/packages/2b/6d/9409f3684d3335375d04e5f05744dfe7e9f120062c9857df4ab490a1031a/MarkupSafe-3.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:f8b3d067f2e40fe93e1ccdd6b2e1d16c43140e76f02fb1319a05cf2b79d99430", size = 12352, upload-time = "2024-10-18T15:21:25.382Z" }, - { url = "https://files.pythonhosted.org/packages/d2/f5/6eadfcd3885ea85fe2a7c128315cc1bb7241e1987443d78c8fe712d03091/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:569511d3b58c8791ab4c2e1285575265991e6d8f8700c7be0e88f86cb0672094", size = 24122, upload-time = "2024-10-18T15:21:26.199Z" }, - { url = "https://files.pythonhosted.org/packages/0c/91/96cf928db8236f1bfab6ce15ad070dfdd02ed88261c2afafd4b43575e9e9/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:15ab75ef81add55874e7ab7055e9c397312385bd9ced94920f2802310c930396", size = 23085, upload-time = "2024-10-18T15:21:27.029Z" }, - { url = "https://files.pythonhosted.org/packages/c2/cf/c9d56af24d56ea04daae7ac0940232d31d5a8354f2b457c6d856b2057d69/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f3818cb119498c0678015754eba762e0d61e5b52d34c8b13d770f0719f7b1d79", size = 22978, upload-time = "2024-10-18T15:21:27.846Z" }, - { url = "https://files.pythonhosted.org/packages/2a/9f/8619835cd6a711d6272d62abb78c033bda638fdc54c4e7f4272cf1c0962b/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:cdb82a876c47801bb54a690c5ae105a46b392ac6099881cdfb9f6e95e4014c6a", size = 24208, upload-time = "2024-10-18T15:21:28.744Z" }, - { url = "https://files.pythonhosted.org/packages/f9/bf/176950a1792b2cd2102b8ffeb5133e1ed984547b75db47c25a67d3359f77/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:cabc348d87e913db6ab4aa100f01b08f481097838bdddf7c7a84b7575b7309ca", size = 23357, upload-time = "2024-10-18T15:21:29.545Z" }, - { url = "https://files.pythonhosted.org/packages/ce/4f/9a02c1d335caabe5c4efb90e1b6e8ee944aa245c1aaaab8e8a618987d816/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:444dcda765c8a838eaae23112db52f1efaf750daddb2d9ca300bcae1039adc5c", size = 23344, upload-time = "2024-10-18T15:21:30.366Z" }, - { url = "https://files.pythonhosted.org/packages/ee/55/c271b57db36f748f0e04a759ace9f8f759ccf22b4960c270c78a394f58be/MarkupSafe-3.0.2-cp313-cp313-win32.whl", hash = "sha256:bcf3e58998965654fdaff38e58584d8937aa3096ab5354d493c77d1fdd66d7a1", size = 15101, upload-time = "2024-10-18T15:21:31.207Z" }, - { url = "https://files.pythonhosted.org/packages/29/88/07df22d2dd4df40aba9f3e402e6dc1b8ee86297dddbad4872bd5e7b0094f/MarkupSafe-3.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:e6a2a455bd412959b57a172ce6328d2dd1f01cb2135efda2e4576e8a23fa3b0f", size = 15603, upload-time = "2024-10-18T15:21:32.032Z" }, - { url = "https://files.pythonhosted.org/packages/62/6a/8b89d24db2d32d433dffcd6a8779159da109842434f1dd2f6e71f32f738c/MarkupSafe-3.0.2-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:b5a6b3ada725cea8a5e634536b1b01c30bcdcd7f9c6fff4151548d5bf6b3a36c", size = 14510, upload-time = "2024-10-18T15:21:33.625Z" }, - { url = "https://files.pythonhosted.org/packages/7a/06/a10f955f70a2e5a9bf78d11a161029d278eeacbd35ef806c3fd17b13060d/MarkupSafe-3.0.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:a904af0a6162c73e3edcb969eeeb53a63ceeb5d8cf642fade7d39e7963a22ddb", size = 12486, upload-time = "2024-10-18T15:21:34.611Z" }, - { url = "https://files.pythonhosted.org/packages/34/cf/65d4a571869a1a9078198ca28f39fba5fbb910f952f9dbc5220afff9f5e6/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4aa4e5faecf353ed117801a068ebab7b7e09ffb6e1d5e412dc852e0da018126c", size = 25480, upload-time = "2024-10-18T15:21:35.398Z" }, - { url = "https://files.pythonhosted.org/packages/0c/e3/90e9651924c430b885468b56b3d597cabf6d72be4b24a0acd1fa0e12af67/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c0ef13eaeee5b615fb07c9a7dadb38eac06a0608b41570d8ade51c56539e509d", size = 23914, upload-time = "2024-10-18T15:21:36.231Z" }, - { url = "https://files.pythonhosted.org/packages/66/8c/6c7cf61f95d63bb866db39085150df1f2a5bd3335298f14a66b48e92659c/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d16a81a06776313e817c951135cf7340a3e91e8c1ff2fac444cfd75fffa04afe", size = 23796, upload-time = "2024-10-18T15:21:37.073Z" }, - { url = "https://files.pythonhosted.org/packages/bb/35/cbe9238ec3f47ac9a7c8b3df7a808e7cb50fe149dc7039f5f454b3fba218/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:6381026f158fdb7c72a168278597a5e3a5222e83ea18f543112b2662a9b699c5", size = 25473, upload-time = "2024-10-18T15:21:37.932Z" }, - { url = "https://files.pythonhosted.org/packages/e6/32/7621a4382488aa283cc05e8984a9c219abad3bca087be9ec77e89939ded9/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:3d79d162e7be8f996986c064d1c7c817f6df3a77fe3d6859f6f9e7be4b8c213a", size = 24114, upload-time = "2024-10-18T15:21:39.799Z" }, - { url = "https://files.pythonhosted.org/packages/0d/80/0985960e4b89922cb5a0bac0ed39c5b96cbc1a536a99f30e8c220a996ed9/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:131a3c7689c85f5ad20f9f6fb1b866f402c445b220c19fe4308c0b147ccd2ad9", size = 24098, upload-time = "2024-10-18T15:21:40.813Z" }, - { url = "https://files.pythonhosted.org/packages/82/78/fedb03c7d5380df2427038ec8d973587e90561b2d90cd472ce9254cf348b/MarkupSafe-3.0.2-cp313-cp313t-win32.whl", hash = "sha256:ba8062ed2cf21c07a9e295d5b8a2a5ce678b913b45fdf68c32d95d6c1291e0b6", size = 15208, upload-time = "2024-10-18T15:21:41.814Z" }, - { url = "https://files.pythonhosted.org/packages/4f/65/6079a46068dfceaeabb5dcad6d674f5f5c61a6fa5673746f42a9f4c233b3/MarkupSafe-3.0.2-cp313-cp313t-win_amd64.whl", hash = "sha256:e444a31f8db13eb18ada366ab3cf45fd4b31e4db1236a4448f68778c1d1a5a2f", size = 15739, upload-time = "2024-10-18T15:21:42.784Z" }, -] - -[[package]] -name = "pastel" -version = "0.2.1" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/76/f1/4594f5e0fcddb6953e5b8fe00da8c317b8b41b547e2b3ae2da7512943c62/pastel-0.2.1.tar.gz", hash = "sha256:e6581ac04e973cac858828c6202c1e1e81fee1dc7de7683f3e1ffe0bfd8a573d", size = 7555, upload-time = "2020-09-16T19:21:12.43Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/aa/18/a8444036c6dd65ba3624c63b734d3ba95ba63ace513078e1580590075d21/pastel-0.2.1-py2.py3-none-any.whl", hash = "sha256:4349225fcdf6c2bb34d483e523475de5bb04a5c10ef711263452cb37d7dd4364", size = 5955, upload-time = "2020-09-16T19:21:11.409Z" }, -] - -[[package]] -name = "poethepoet" -version = "0.37.0" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "pastel" }, - { name = "pyyaml" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/a5/f2/273fe54a78dc5c6c8dd63db71f5a6ceb95e4648516b5aeaeff4bde804e44/poethepoet-0.37.0.tar.gz", hash = "sha256:73edf458707c674a079baa46802e21455bda3a7f82a408e58c31b9f4fe8e933d", size = 68570, upload-time = "2025-08-11T18:00:29.103Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/92/1b/5337af1a6a478d25a3e3c56b9b4b42b0a160314e02f4a0498d5322c8dac4/poethepoet-0.37.0-py3-none-any.whl", hash = "sha256:861790276315abcc8df1b4bd60e28c3d48a06db273edd3092f3c94e1a46e5e22", size = 90062, upload-time = "2025-08-11T18:00:27.595Z" }, -] - -[[package]] -name = "pybird" -version = "1.2.0" -source = { git = "https://github.com/mansziesel/pybird.git#d0462df21dd91a6db18868f66a3ba4f9d23879e9" } - -[[package]] -name = "python-dotenv" -version = "1.1.1" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/f6/b0/4bc07ccd3572a2f9df7e6782f52b0c6c90dcbb803ac4a167702d7d0dfe1e/python_dotenv-1.1.1.tar.gz", hash = "sha256:a8a6399716257f45be6a007360200409fce5cda2661e3dec71d23dc15f6189ab", size = 41978, upload-time = "2025-06-24T04:21:07.341Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/5f/ed/539768cf28c661b5b068d66d96a2f155c4971a5d55684a514c1a0e0dec2f/python_dotenv-1.1.1-py3-none-any.whl", hash = "sha256:31f23644fe2602f88ff55e1f5c79ba497e01224ee7737937930c448e4d0e24dc", size = 20556, upload-time = "2025-06-24T04:21:06.073Z" }, -] - -[[package]] -name = "pyyaml" -version = "6.0.2" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/54/ed/79a089b6be93607fa5cdaedf301d7dfb23af5f25c398d5ead2525b063e17/pyyaml-6.0.2.tar.gz", hash = "sha256:d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e", size = 130631, upload-time = "2024-08-06T20:33:50.674Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/ef/e3/3af305b830494fa85d95f6d95ef7fa73f2ee1cc8ef5b495c7c3269fb835f/PyYAML-6.0.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba", size = 181309, upload-time = "2024-08-06T20:32:43.4Z" }, - { url = "https://files.pythonhosted.org/packages/45/9f/3b1c20a0b7a3200524eb0076cc027a970d320bd3a6592873c85c92a08731/PyYAML-6.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:50187695423ffe49e2deacb8cd10510bc361faac997de9efef88badc3bb9e2d1", size = 171679, upload-time = "2024-08-06T20:32:44.801Z" }, - { url = "https://files.pythonhosted.org/packages/7c/9a/337322f27005c33bcb656c655fa78325b730324c78620e8328ae28b64d0c/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ffe8360bab4910ef1b9e87fb812d8bc0a308b0d0eef8c8f44e0254ab3b07133", size = 733428, upload-time = "2024-08-06T20:32:46.432Z" }, - { url = "https://files.pythonhosted.org/packages/a3/69/864fbe19e6c18ea3cc196cbe5d392175b4cf3d5d0ac1403ec3f2d237ebb5/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:17e311b6c678207928d649faa7cb0d7b4c26a0ba73d41e99c4fff6b6c3276484", size = 763361, upload-time = "2024-08-06T20:32:51.188Z" }, - { url = "https://files.pythonhosted.org/packages/04/24/b7721e4845c2f162d26f50521b825fb061bc0a5afcf9a386840f23ea19fa/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70b189594dbe54f75ab3a1acec5f1e3faa7e8cf2f1e08d9b561cb41b845f69d5", size = 759523, upload-time = "2024-08-06T20:32:53.019Z" }, - { url = "https://files.pythonhosted.org/packages/2b/b2/e3234f59ba06559c6ff63c4e10baea10e5e7df868092bf9ab40e5b9c56b6/PyYAML-6.0.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:41e4e3953a79407c794916fa277a82531dd93aad34e29c2a514c2c0c5fe971cc", size = 726660, upload-time = "2024-08-06T20:32:54.708Z" }, - { url = "https://files.pythonhosted.org/packages/fe/0f/25911a9f080464c59fab9027482f822b86bf0608957a5fcc6eaac85aa515/PyYAML-6.0.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:68ccc6023a3400877818152ad9a1033e3db8625d899c72eacb5a668902e4d652", size = 751597, upload-time = "2024-08-06T20:32:56.985Z" }, - { url = "https://files.pythonhosted.org/packages/14/0d/e2c3b43bbce3cf6bd97c840b46088a3031085179e596d4929729d8d68270/PyYAML-6.0.2-cp313-cp313-win32.whl", hash = "sha256:bc2fa7c6b47d6bc618dd7fb02ef6fdedb1090ec036abab80d4681424b84c1183", size = 140527, upload-time = "2024-08-06T20:33:03.001Z" }, - { url = "https://files.pythonhosted.org/packages/fa/de/02b54f42487e3d3c6efb3f89428677074ca7bf43aae402517bc7cca949f3/PyYAML-6.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:8388ee1976c416731879ac16da0aff3f63b286ffdd57cdeb95f3f2e085687563", size = 156446, upload-time = "2024-08-06T20:33:04.33Z" }, -] - -[[package]] -name = "requests" -version = "2.32.4" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "certifi" }, - { name = "charset-normalizer" }, - { name = "idna" }, - { name = "urllib3" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/e1/0a/929373653770d8a0d7ea76c37de6e41f11eb07559b103b1c02cafb3f7cf8/requests-2.32.4.tar.gz", hash = "sha256:27d0316682c8a29834d3264820024b62a36942083d52caf2f14c0591336d3422", size = 135258, upload-time = "2025-06-09T16:43:07.34Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/7c/e4/56027c4a6b4ae70ca9de302488c5ca95ad4a39e190093d6c1a8ace08341b/requests-2.32.4-py3-none-any.whl", hash = "sha256:27babd3cda2a6d50b30443204ee89830707d396671944c998b5975b031ac2b2c", size = 64847, upload-time = "2025-06-09T16:43:05.728Z" }, -] - -[[package]] -name = "urllib3" -version = "2.5.0" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/15/22/9ee70a2574a4f4599c47dd506532914ce044817c7752a79b6a51286319bc/urllib3-2.5.0.tar.gz", hash = "sha256:3fc47733c7e419d4bc3f6b3dc2b4f890bb743906a30d56ba4a5bfa4bbff92760", size = 393185, upload-time = "2025-06-18T14:07:41.644Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/a7/c2/fe1e52489ae3122415c51f387e221dd0773709bad6c6cdaa599e8a2c5185/urllib3-2.5.0-py3-none-any.whl", hash = "sha256:e6b01673c0fa6a13e374b50871808eb3bf7046c4b125b216f6bf1cc604cff0dc", size = 129795, upload-time = "2025-06-18T14:07:40.39Z" }, -] - -[[package]] -name = "werkzeug" -version = "3.1.3" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "markupsafe" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/9f/69/83029f1f6300c5fb2471d621ab06f6ec6b3324685a2ce0f9777fd4a8b71e/werkzeug-3.1.3.tar.gz", hash = "sha256:60723ce945c19328679790e3282cc758aa4a6040e4bb330f53d30fa546d44746", size = 806925, upload-time = "2024-11-08T15:52:18.093Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/52/24/ab44c871b0f07f491e5d2ad12c9bd7358e527510618cb1b803a88e986db1/werkzeug-3.1.3-py3-none-any.whl", hash = "sha256:54b78bf3716d19a65be4fceccc0d1d7b89e608834989dfae50ea87564639213e", size = 224498, upload-time = "2024-11-08T15:52:16.132Z" }, -]