Skip to content

Commit

Permalink
Show S3 status even if orcasite doesn't know about the node (#149)
Browse files Browse the repository at this point in the history
* Show S3 status even if orcasite doesn't know about the node

Fixes #134

Signed-off-by: Dave Thaler <[email protected]>

* Show Unauthorized as an S3 stream status

Signed-off-by: Dave Thaler <[email protected]>

---------

Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler authored Oct 9, 2024
1 parent 92ae753 commit 913bb88
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
15 changes: 11 additions & 4 deletions OrcanodeMonitor/Core/Fetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class Fetcher
private static string _orcaHelloHydrophonesUrl = "https://aifororcasdetections2.azurewebsites.net/api/hydrophones";
private static DateTime _unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
private static string _iftttServiceKey = Environment.GetEnvironmentVariable("IFTTT_SERVICE_KEY") ?? "<unknown>";
private static string _defaultS3Bucket = "streaming-orcasound-net";
private static string _defaultProdS3Bucket = "audio-orcasound-net";
private static string _defaultDevS3Bucket = "dev-streaming-orcasound-net";
public static string IftttServiceKey => _iftttServiceKey;

/// <summary>
Expand Down Expand Up @@ -365,12 +366,12 @@ public async static Task UpdateDataplicityDataAsync(OrcanodeMonitorContext conte
string dataplicityName = name.ToString();
node.DataplicityName = dataplicityName;

if (node.S3Bucket.IsNullOrEmpty())
if (node.S3Bucket.IsNullOrEmpty() || (node.OrcasoundStatus == OrcanodeOnlineStatus.Absent))
{
node.S3Bucket = _defaultS3Bucket;
node.S3Bucket = dataplicityName.ToLower().StartsWith("dev") ? _defaultDevS3Bucket : _defaultProdS3Bucket;
}

if (node.S3NodeName.IsNullOrEmpty())
if (node.S3NodeName.IsNullOrEmpty() || (node.OrcasoundStatus == OrcanodeOnlineStatus.Absent))
{
// Fill in a non-authoritative default S3 node name.
// Orcasound is authoritative here since our default is
Expand Down Expand Up @@ -747,6 +748,12 @@ public async static Task UpdateS3DataAsync(OrcanodeMonitorContext context, Orcan
node.LatestRecordedUtc = null;
return;
}
if (response.StatusCode == HttpStatusCode.Forbidden)
{
// Access denied.
node.LatestRecordedUtc = DateTime.MinValue;
return;
}
if (!response.IsSuccessStatusCode)
{
return;
Expand Down
5 changes: 5 additions & 0 deletions OrcanodeMonitor/Models/Orcanode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum OrcanodeOnlineStatus
Online,
Unintelligible,
Hidden,
Unauthorized,
}
public enum OrcanodeUpgradeStatus
{
Expand Down Expand Up @@ -287,6 +288,10 @@ public OrcanodeOnlineStatus S3StreamStatus
{
return OrcanodeOnlineStatus.Absent;
}
if (LatestRecordedUtc == DateTime.MinValue)
{
return OrcanodeOnlineStatus.Unauthorized;
}
if (!ManifestUpdatedUtc.HasValue || !LastCheckedUtc.HasValue)
{
return OrcanodeOnlineStatus.Absent;
Expand Down
2 changes: 1 addition & 1 deletion OrcanodeMonitor/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
else
{
<td style="background-color: @Model.NodeS3BackgroundColor(item)">
<a href="https://open.quiltdata.com/b/audio-orcasound-net/tree/@item.S3NodeName/" style="color: @Model.NodeS3TextColor(item)" target="_blank">
<a href="https://open.quiltdata.com/b/@item.S3Bucket/tree/@item.S3NodeName/" style="color: @Model.NodeS3TextColor(item)" target="_blank">
@Html.DisplayFor(modelItem => item.S3StreamStatus)
</a>
</td>
Expand Down

0 comments on commit 913bb88

Please sign in to comment.