Skip to content

Commit

Permalink
Removed config for anonymous vs. logged-in calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Whewell committed Jun 25, 2023
1 parent 4795016 commit 078d5b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
4 changes: 2 additions & 2 deletions opensky-to-basestation/CommandRunner_Rebroadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}");
Expand Down Expand Up @@ -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(
Expand Down
19 changes: 2 additions & 17 deletions opensky-to-basestation/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,9 @@ class Options
public bool IsAnonymous => String.IsNullOrWhiteSpace(UserName);

/// <summary>
/// The API root URL for anonymous calls.
/// The API root URL.
/// </summary>
public string AnonRootUrl { get; set; } = "https://opensky-network.org/api";

/// <summary>
/// The API root URL for calls with credentials.
/// </summary>
public string UserRootUrl { get; set; } = "https://{user}:{password}@opensky-network.org/api";

/// <summary>
/// <see cref="UserRootUrl"/> if credentials have been supplied, otherwise <see cref="AnonRootUrl"/>.
/// </summary>
public string RootUrl => IsAnonymous ? AnonRootUrl : UserRootUrl.Replace("{user}", UserName).Replace("{password}", Password);

/// <summary>
/// <see cref="RootUrl"/> with the password replaced with asterisks.
/// </summary>
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";

/// <summary>
/// The number of seconds to wait between fetches when no credentials have been supplied. Do not set this lower
Expand Down
21 changes: 7 additions & 14 deletions opensky-to-basestation/OptionsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -164,8 +158,7 @@ public static void Usage(string message)
Console.WriteLine($"OPENSKY PARAMETERS");
Console.WriteLine($" -user <text> OpenSky network username [{defaults.UserName}]");
Console.WriteLine($" -password <text> OpenSky network password [{defaults.Password}]");
Console.WriteLine($" -anonRootUrl <url> Root URL for anonymous OpenSky API calls [{defaults.AnonRootUrl}]");
Console.WriteLine($" -userRootUrl <url> Root URL for logged-in OpenSky API calls [{defaults.UserRootUrl}]");
Console.WriteLine($" -rootUrl <url> Root URL for OpenSky API calls [{defaults.RootUrl}]");
Console.WriteLine($" -anonInterval <secs> Seconds between fetches for anonymous users [{defaults.AnonIntervalSeconds}]");
Console.WriteLine($" -userInterval <secs> Seconds between fetches for logged-in users [{defaults.UserIntervalSeconds}]");
Console.WriteLine($" -icao24 <hex-list> Hyphen-separated ICAOs to fetch from OpenSky [{String.Join("-", defaults.Icao24s)}]");
Expand Down

0 comments on commit 078d5b2

Please sign in to comment.