Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garmin auth tweak - use internal OAuthV1 implementation #708

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@ configuration.local.json
/src/ClientUI/ClientUI.csproj.user

# docs
/mkdocs/site
/mkdocs/site

# emacs backup files
**/*~
**/*.*~
16 changes: 10 additions & 6 deletions docker/Dockerfile.api
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
FROM mcr.microsoft.com/dotnet/aspnet:7.0 as final

RUN apt-get update \
&& apt-get -y install bash tzdata \
&& apt-get purge -y -f --force-yes $EXT_BUILD_DEPS \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& apt-get -y install bash tzdata \
&& apt-get purge -y -f --force-yes $EXT_BUILD_DEPS \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN groupadd -g 1015 p2g && useradd -g p2g -u 1015 p2g

WORKDIR /app

RUN mkdir -m770 {output,data,working}
RUN mkdir -m770 working
RUN mkdir -m770 data
RUN mkdir -m770 output
# this last is for optionally mounting a directory for configuration
RUN mkdir -m770 mounted-config

###################
# BUILD LAYER
Expand Down
18 changes: 11 additions & 7 deletions docker/Dockerfile.console
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
###################
# CREATE FINAL LAYER
###################
FROM mcr.microsoft.com/dotnet/aspnet:7.0 as final
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS final

RUN apt-get update \
&& apt-get -y install bash tzdata \
&& apt-get purge -y -f --force-yes $EXT_BUILD_DEPS \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& apt-get -y install bash tzdata \
&& apt-get purge -y -f --force-yes $EXT_BUILD_DEPS \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN groupadd -g 1015 p2g && useradd -g p2g -u 1015 p2g

WORKDIR /app

RUN mkdir -m770 {output,data,working}
RUN mkdir -m770 working
RUN mkdir -m770 data
RUN mkdir -m770 output
# this last is for optionally mounting a directory for configuration
RUN mkdir -m770 mounted-config

###################
# BUILD LAYER
Expand Down
1 change: 1 addition & 0 deletions docker/headless/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ services:
volumes:
- ./configuration.local.json:/app/configuration.local.json
- ./output:/app/output
- ./data:/app/data
11 changes: 11 additions & 0 deletions src/Common/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Common.Extensions;

public static class ExtensionMethods
{
public static string Truncate(this string value, int maxLength)
{
if (string.IsNullOrEmpty(value)) return value;
return value.Length <= maxLength ? value : value.Substring(0, maxLength);
}
}

130 changes: 66 additions & 64 deletions src/Common/Observe/Logging.cs
Original file line number Diff line number Diff line change
@@ -1,67 +1,69 @@
using Common.Dto;
using Common.Stateful;
using Common.Dto;
using Common.Stateful;
using Serilog;
using Serilog.Sinks.File;
using Serilog.Sinks.File.Header;
using System.IO;
using System.Text;
using Serilog.Sinks.File;
using Serilog.Sinks.File.Header;
using System.IO;
using System.Text;

namespace Common.Observe;

public class LogContext
{
public static ILogger ForClass<T>() => Log.Logger.ForContext(Serilog.Core.Constants.SourceContextPropertyName, typeof(T).Name);
public static ILogger ForStatic(string name) => Log.Logger.ForContext(Serilog.Core.Constants.SourceContextPropertyName, name);
}

public static class Logging
{
public static string CurrentFilePath { get; set; }

public static void LogSystemInformation()
{
Log.Information("*********************************************");
Log.Information("P2G Version: {@AppName} {@Version}", Statics.AppType, Constants.AppVersion);
Log.Information("Operating System: {@Os}", SystemInformation.OS);
Log.Information("OS Version: {@OsVersion}", SystemInformation.OSVersion);
Log.Information("DotNet Runtime: {@DotnetRuntime}", SystemInformation.RunTimeVersion);
Log.Information("Docker Deployment: {@IsDocker}", SystemInformation.RunningInDocker);
Log.Information("Config path: {@ConfigPath}", Statics.ConfigPath);
Log.Information("*********************************************");
}

public static string GetSystemInformationLogMessage()
{
return $@"
*********************************************
P2G Version: {Statics.AppType} {Constants.AppVersion}
Operating System: {SystemInformation.OS}
OS Version: {SystemInformation.OSVersion}
DotNet Runtime: {SystemInformation.RunTimeVersion}
Docker Deployment: {SystemInformation.RunningInDocker}
Config path: {Statics.ConfigPath}
*********************************************";
}
}

public class CaptureFilePathHook : FileLifecycleHooks
{
private HeaderWriter _headerHook;

public CaptureFilePathHook()
{
_headerHook = new HeaderWriter(Logging.GetSystemInformationLogMessage);
}

public override Stream OnFileOpened(string path, Stream underlyingStream, Encoding encoding)
{
Logging.CurrentFilePath = path;

return _headerHook.OnFileOpened(path, underlyingStream, encoding);
}

public override void OnFileDeleting(string path)
{
_headerHook.OnFileDeleting(path);
}

public class LogContext
{
public static ILogger ForClass<T>() => Log.Logger.ForContext(Serilog.Core.Constants.SourceContextPropertyName, typeof(T).Name);
public static ILogger ForStatic(string name) => Log.Logger.ForContext(Serilog.Core.Constants.SourceContextPropertyName, name);
}

public static class Logging
{
public static string CurrentFilePath { get; set; }

public static void LogSystemInformation()
{
Log.Information("*********************************************");
Log.Information("P2G Version: {@AppName} {@Version}", Statics.AppType, Constants.AppVersion);
Log.Information("Operating System: {@Os}", SystemInformation.OS);
Log.Information("OS Version: {@OsVersion}", SystemInformation.OSVersion);
Log.Information("DotNet Runtime: {@DotnetRuntime}", SystemInformation.RunTimeVersion);
Log.Information("Docker Deployment: {@IsDocker}", SystemInformation.RunningInDocker);
Log.Information("Config path: {@ConfigPath}", Statics.ConfigPath);
Log.Information("Data Directory: {@DataDirectory} ", App.DataDirectory);
Log.Information("*********************************************");
}

public static string GetSystemInformationLogMessage()
{
return $@"
*********************************************
P2G Version: {Statics.AppType} {Constants.AppVersion}
Operating System: {SystemInformation.OS}
OS Version: {SystemInformation.OSVersion}
DotNet Runtime: {SystemInformation.RunTimeVersion}
Docker Deployment: {SystemInformation.RunningInDocker}
Config path: {Statics.ConfigPath}
Data Directory: {App.DataDirectory}
*********************************************";
}
}

public class CaptureFilePathHook : FileLifecycleHooks
{
private HeaderWriter _headerHook;

public CaptureFilePathHook()
{
_headerHook = new HeaderWriter(Logging.GetSystemInformationLogMessage);
}

public override Stream OnFileOpened(string path, Stream underlyingStream, Encoding encoding)
{
Logging.CurrentFilePath = path;

return _headerHook.OnFileOpened(path, underlyingStream, encoding);
}

public override void OnFileDeleting(string path)
{
_headerHook.OnFileDeleting(path);
}
}
9 changes: 7 additions & 2 deletions src/ConsoleClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using IHost host = CreateHostBuilder(args).Build();
await host.RunAsync();


static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
Expand All @@ -38,7 +39,11 @@ static IHostBuilder CreateHostBuilder(string[] args)
configBuilder.Sources.Clear();

var configPath = Environment.CurrentDirectory;
if (args.Length > 0) configPath = args[0];
String envSpecifiedConfigPath = Environment.GetEnvironmentVariable($"{Constants.EnvironmentVariablePrefix}_CONFIG");
if (!String.IsNullOrEmpty(envSpecifiedConfigPath))
{
configPath = envSpecifiedConfigPath;
}

Statics.ConfigPath = Path.Join(configPath, "configuration.local.json");

Expand Down Expand Up @@ -112,4 +117,4 @@ static IHostBuilder CreateHostBuilder(string[] args)

services.AddHostedService<Startup>();
});
}
}
4 changes: 2 additions & 2 deletions src/ConsoleClient/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private async Task RunAsync(CancellationToken cancelToken)
settings.Peloton.NumWorkoutsToDownload = num;
}

if (settings.Garmin.Upload
if (settings.Garmin.Upload
&& settings.Garmin.TwoStepVerificationEnabled
&& !(await _garminAuthService.GarminAuthTokenExistsAndIsValidAsync()))
{
Expand Down Expand Up @@ -171,7 +171,7 @@ private async Task RunAsync(CancellationToken cancelToken)
finally
{
_logger.Information("Done.");
Console.ReadLine();
//Console.ReadLine();
Environment.Exit(exitCode);
}
}
Expand Down
Loading