From 078d5b2bfbd9a5b5fa108e3693700f6293075afe Mon Sep 17 00:00:00 2001 From: Andrew Whewell Date: Sun, 25 Jun 2023 15:10:21 +0100 Subject: [PATCH] Removed config for anonymous vs. logged-in calls --- .../CommandRunner_Rebroadcast.cs | 4 ++-- opensky-to-basestation/Options.cs | 19 ++--------------- opensky-to-basestation/OptionsParser.cs | 21 +++++++------------ 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/opensky-to-basestation/CommandRunner_Rebroadcast.cs b/opensky-to-basestation/CommandRunner_Rebroadcast.cs index 1fe0397..564e613 100644 --- a/opensky-to-basestation/CommandRunner_Rebroadcast.cs +++ b/opensky-to-basestation/CommandRunner_Rebroadcast.cs @@ -37,7 +37,7 @@ public override bool Run() { Console.WriteLine($"Rebroadcast OpenSky state"); Console.WriteLine($"User: {(Options.IsAnonymous ? "Anonymous" : Options.UserName)}"); - Console.WriteLine($"Root URL: {Options.ObsfucatedRootUrl}"); + Console.WriteLine($"Root URL: {Options.RootUrl}"); Console.WriteLine($"Interval: Every {Options.IntervalSeconds} seconds"); Console.WriteLine($"Icao24s: {(Options.Icao24s.Count == 0 ? "all" : String.Join("-", Options.Icao24s))}"); Console.WriteLine($"Bounds: {(!Options.HasBoundingBox ? "World" : Options.BoundsDescription)}"); @@ -80,7 +80,7 @@ private void NetworkListener_Error(Task task) private void StartCallingOpenSkyApi() { _HttpClient = new HttpClient(); - if(!String.IsNullOrEmpty(Options.UserName) && !String.IsNullOrEmpty(Options.Password)) { + if(!Options.IsAnonymous) { _HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Basic", Convert.ToBase64String( diff --git a/opensky-to-basestation/Options.cs b/opensky-to-basestation/Options.cs index 6dff00a..b124099 100644 --- a/opensky-to-basestation/Options.cs +++ b/opensky-to-basestation/Options.cs @@ -34,24 +34,9 @@ class Options public bool IsAnonymous => String.IsNullOrWhiteSpace(UserName); /// - /// The API root URL for anonymous calls. + /// The API root URL. /// - public string AnonRootUrl { get; set; } = "https://opensky-network.org/api"; - - /// - /// The API root URL for calls with credentials. - /// - public string UserRootUrl { get; set; } = "https://{user}:{password}@opensky-network.org/api"; - - /// - /// if credentials have been supplied, otherwise . - /// - public string RootUrl => IsAnonymous ? AnonRootUrl : UserRootUrl.Replace("{user}", UserName).Replace("{password}", Password); - - /// - /// with the password replaced with asterisks. - /// - public string ObsfucatedRootUrl => IsAnonymous ? AnonRootUrl : UserRootUrl.Replace("{user}", UserName).Replace("{password}", new String('*', Password?.Length ?? 0)); + public string RootUrl { get; set; } = "https://opensky-network.org/api"; /// /// The number of seconds to wait between fetches when no credentials have been supplied. Do not set this lower diff --git a/opensky-to-basestation/OptionsParser.cs b/opensky-to-basestation/OptionsParser.cs index 6e94803..ffb2210 100644 --- a/opensky-to-basestation/OptionsParser.cs +++ b/opensky-to-basestation/OptionsParser.cs @@ -46,12 +46,6 @@ public static Options Parse(string[] args) case "--?": Usage(null); break; - case "-anoninterval": - result.AnonIntervalSeconds = ParseInt(UseNextArg(arg, nextArg, ref i)); - break; - case "-anonrooturl": - result.AnonRootUrl = UseNextArg(arg, nextArg, ref i); - break; case "-icao24": result .Icao24s.AddRange( @@ -79,9 +73,15 @@ public static Options Parse(string[] args) case "-password": result.Password = UseNextArg(arg, nextArg, ref i); break; + case "-port": + result.Port = ParseInt(UseNextArg(arg, nextArg, ref i)); + break; case "-rebroadcast": result.Command = ParseCommand(result, Command.Rebroadcast); break; + case "-rooturl": + result.RootUrl = UseNextArg(arg, nextArg, ref i); + break; case "-ticklesecs": result.TickleIntervalSeconds = ParseInt(UseNextArg(arg, nextArg, ref i)); break; @@ -91,12 +91,6 @@ public static Options Parse(string[] args) case "-userinterval": result.UserIntervalSeconds = ParseInt(UseNextArg(arg, nextArg, ref i)); break; - case "-userrooturl": - result.UserRootUrl = UseNextArg(arg, nextArg, ref i); - break; - case "-port": - result.Port = ParseInt(UseNextArg(arg, nextArg, ref i)); - break; default: Usage($"Invalid argument {arg}"); break; @@ -164,8 +158,7 @@ public static void Usage(string message) Console.WriteLine($"OPENSKY PARAMETERS"); Console.WriteLine($" -user OpenSky network username [{defaults.UserName}]"); Console.WriteLine($" -password OpenSky network password [{defaults.Password}]"); - Console.WriteLine($" -anonRootUrl Root URL for anonymous OpenSky API calls [{defaults.AnonRootUrl}]"); - Console.WriteLine($" -userRootUrl Root URL for logged-in OpenSky API calls [{defaults.UserRootUrl}]"); + Console.WriteLine($" -rootUrl Root URL for OpenSky API calls [{defaults.RootUrl}]"); Console.WriteLine($" -anonInterval Seconds between fetches for anonymous users [{defaults.AnonIntervalSeconds}]"); Console.WriteLine($" -userInterval Seconds between fetches for logged-in users [{defaults.UserIntervalSeconds}]"); Console.WriteLine($" -icao24 Hyphen-separated ICAOs to fetch from OpenSky [{String.Join("-", defaults.Icao24s)}]");