How can I run a Google API inside a Docker Container?

I'm making a worker service that interacts with the Gmail API. Currently, I use OAuth 2.0 Client for the credentials:
public static class GmailApiHelper
{
public static GmailService GetGmailService(string credentialsPath, string accessTokenPath)
{
using var stream = new FileStream(credentialsPath, FileMode.Open, FileAccess.Read);

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.FromStream(stream).Secrets,
new[] { GmailService.Scope.GmailReadonly, GmailService.Scope.GmailModify },
"user",
CancellationToken.None,
new FileDataStore(accessTokenPath, true)).Result;

return new GmailService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "Gmail API Sample",
});
}
}
public static class GmailApiHelper
{
public static GmailService GetGmailService(string credentialsPath, string accessTokenPath)
{
using var stream = new FileStream(credentialsPath, FileMode.Open, FileAccess.Read);

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.FromStream(stream).Secrets,
new[] { GmailService.Scope.GmailReadonly, GmailService.Scope.GmailModify },
"user",
CancellationToken.None,
new FileDataStore(accessTokenPath, true)).Result;

return new GmailService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "Gmail API Sample",
});
}
}
It works fine until I run it on a Docker Container:
2024-02-16 19:08:21 [11:08:21 ERR] [Microsoft.Extensions.Hosting.Internal.Host] - BackgroundService failed
2024-02-16 19:08:21 System.InvalidOperationException: At least one client secrets (Installed or Web) should be set
2024-02-16 19:08:21 at Google.Apis.Auth.OAuth2.GoogleClientSecrets.get_Secrets()
2024-02-16 19:08:21 [11:08:21 ERR] [Microsoft.Extensions.Hosting.Internal.Host] - BackgroundService failed
2024-02-16 19:08:21 System.InvalidOperationException: At least one client secrets (Installed or Web) should be set
2024-02-16 19:08:21 at Google.Apis.Auth.OAuth2.GoogleClientSecrets.get_Secrets()
I've search through this on the internet and it wants me to use a Service Account. But I couldn't get it to work. I also tried using a normal API key but it says that it has limited access. I hope someone can help me with this. 😇
330 Replies
The Fog from Human Resources
isnt the google api just a bunch of endpoints?
Anu6is
Anu6is10mo ago
that just looks like it can't find you secret in the path you provided
Keswiik
Keswiik10mo ago
Error makes it sound like you're failing to read your credentials from whatever file you're saving them in. Are you mounting the file into your container (or copying it into the container)?
dabirbswerenoisyaround
Yes I am mounting it
dabirbswerenoisyaround
Usually, it looks for that credentials.json, and it looks for an access token on the FileDataStore, if no access token found, it opens a browser to authenticate and once authenticated, it creates it. I must provide the credentials.json. I think the browser authentication was the problem here since theres no UI for Docker It's actually my first time using Docker in a project
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
That's why I searched it and it wants me to use a Service Account which I couldn't make it work.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Sorry I'm not following You mean constructor?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX10mo ago
TLDR on async/await: * every .net API that is suffixed with Async (eg: .Read() and .ReadAsync()) => use the Async version * if the API name ends with Async => await it * if the API returns a Task => await it * if you have to await in a method: * that method must have the async keyword (you could even suffix your function name with Async, up to you) * if it was returning T (eg:string) => it should now return Task<T> (eg: Task<string>) * APIs to ban and associated fix:
var r = t.Result; /* ===> */ var r = await t;
t.Wait(); /* ===> */ await t;
var r = t.GetAwaiter().GetResult(); /* ===> */ var r = await t;
Task.WaitAll(t1, t2); /* ===> */ await Task.WhenAll(t1, t2);
var r = t.Result; /* ===> */ var r = await t;
t.Wait(); /* ===> */ await t;
var r = t.GetAwaiter().GetResult(); /* ===> */ var r = await t;
Task.WaitAll(t1, t2); /* ===> */ await Task.WhenAll(t1, t2);
dabirbswerenoisyaround
Oh yeah I didn't notice it
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
But why it works fine on a real computer?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Yeah I'm putting await now
dabirbswerenoisyaround
Wait wut?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Oh my god my brain isn't working right now hold up I just woke up
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Yeah it's a school project
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Wanna see the repo?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I hope I didn't commit something sensitive tho
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
GitHub
GitHub - dkroderos/mail at dockerize
Merr Mail. Contribute to dkroderos/mail development by creating an account on GitHub.
dabirbswerenoisyaround
But I don't think you can run it since I use .env files
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Go ahead please
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I always commit them 😄 And sometimes it's sensitive
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Like path to something
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Ohhhh
dabirbswerenoisyaround
GitHub
GitHub - tonerdo/dotnet-env: A .NET library to load environment var...
A .NET library to load environment variables from .env files - tonerdo/dotnet-env
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Lmao
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Thanks I'll try it out
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Nah I only know C#
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Bro I'm still a student I have a lot to learn
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Thanks for it tho I learned something new
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
You working already?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Real work On a company or smth?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Sheesh I still have a lot to learn Did you saw the code?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I've just commited another one since I forgot to update the one that calls that func
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Only one
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Just started it 2 weeks ago
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Wanna call?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Yeah I do think thats better
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Hihi You can send a PR on the main repo I'll merge it
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
DotNetEnv(); It does traverse search Until it finds the .env
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
LMAO
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
ar? Nope, I just think I might use another configuration format 😄
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Just paths to the sensitive files actually
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
OAUTH_CLIENT_CREDENTIALS_PATH=C:\GmailAPI\credentials.json
DATABASE_CONNECTION=hahahaha
ACCESS_TOKEN_PATH=C:\GmailAPI\token
OAUTH_CLIENT_CREDENTIALS_PATH=C:\GmailAPI\credentials.json
DATABASE_CONNECTION=hahahaha
ACCESS_TOKEN_PATH=C:\GmailAPI\token
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I'm always seeing it actually
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Yes
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
We can call right now and review my shitty code 😄
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I'm still knowing how to use the client secrets
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
On appsettings.json
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
So how do i not commit this?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Just .gitignore it?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
So this is appsettings.json?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Wait so many stuff to do I need guidance
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Lemme clone it again I got so many files already
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Yep
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
It's in the home folder right?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Windows Currently
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Where? Btw I just use student license I'm not rich
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Oh ok
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
There we go
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Are you starting to understand the project structure now?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Wait
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I tried to use clean architecture but I don't know if I properly implemented the separation of concerns Seeing that "hahahaha" once again still got me laughing
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Then I use jsonserializer right?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Just ok here?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
{
"OAuthClientCredentialPath": "C:\\GmailAPI\\credentials.json",
"DatabaseConnection": "hahahaha",
"AccessTokenPath": "C:\\GmailAPI\\token",
"HostAddress": "[email protected]",
}
{
"OAuthClientCredentialPath": "C:\\GmailAPI\\credentials.json",
"DatabaseConnection": "hahahaha",
"AccessTokenPath": "C:\\GmailAPI\\token",
"HostAddress": "[email protected]",
}
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
This is on domain right? Domain/Models?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I gotta try it first before I roast it 😄
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Could you send a pr?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
:blushowo:
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I'll do the thing you suggested later builder.services.blabla
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Done
MODiX
MODiX10mo ago
TeBeCo
- var builder = Host.CreateDefaultBuilder(args)
- .ConfigureServices((_, services) =>
- {
- services.AddHostedService<MerrMailWorker>();

- services.AddSingleton<HttpClient>();
- services.AddSingleton<IConfigurationSettings, EnvironmentVariables>();

- services.AddSingleton<IApplicationService, ApplicationService>();
- services.AddSingleton<IEmailApiService, GmailApiService>();
- services.AddSingleton<IConfigurationReader, EnvConfigurationReader>();
- services.AddSingleton<IOAuthClientCredentialsReader, GoogleOAuthClientCredentialsReader>();
- })
- .UseSerilog();

+ var builder = Host.CreateApplicationBuilder(args);
+ builder.Services.AddSerilog();
+ builder.Services.AddHostedService<MerrMailWorker>();

- builder.Services.AddSingleton<HttpClient>();
+ builder.Services.AddHttpClient();
+ builder.Services.AddSingleton<IConfigurationSettings, EnvironmentVariables>();

+ builder.Services.AddSingleton<IApplicationService, ApplicationService>();
+ builder.Services.AddSingleton<IEmailApiService, GmailApiService>();
+ builder.Services.AddSingleton<IConfigurationReader, EnvConfigurationReader>();
+ builder.Services.AddSingleton<IOAuthClientCredentialsReader, GoogleOAuthClientCredentialsReader>();
- var builder = Host.CreateDefaultBuilder(args)
- .ConfigureServices((_, services) =>
- {
- services.AddHostedService<MerrMailWorker>();

- services.AddSingleton<HttpClient>();
- services.AddSingleton<IConfigurationSettings, EnvironmentVariables>();

- services.AddSingleton<IApplicationService, ApplicationService>();
- services.AddSingleton<IEmailApiService, GmailApiService>();
- services.AddSingleton<IConfigurationReader, EnvConfigurationReader>();
- services.AddSingleton<IOAuthClientCredentialsReader, GoogleOAuthClientCredentialsReader>();
- })
- .UseSerilog();

+ var builder = Host.CreateApplicationBuilder(args);
+ builder.Services.AddSerilog();
+ builder.Services.AddHostedService<MerrMailWorker>();

- builder.Services.AddSingleton<HttpClient>();
+ builder.Services.AddHttpClient();
+ builder.Services.AddSingleton<IConfigurationSettings, EnvironmentVariables>();

+ builder.Services.AddSingleton<IApplicationService, ApplicationService>();
+ builder.Services.AddSingleton<IEmailApiService, GmailApiService>();
+ builder.Services.AddSingleton<IConfigurationReader, EnvConfigurationReader>();
+ builder.Services.AddSingleton<IOAuthClientCredentialsReader, GoogleOAuthClientCredentialsReader>();
React with ❌ to remove this embed.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Ye You removed the HttpClient?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
OHHH OK Wait when did you do .AddHttpClient?
using Merrsoft.MerrMail.Application.Contracts;
using Merrsoft.MerrMail.Application.Services;
using Merrsoft.MerrMail.Domain.Contracts;
using Merrsoft.MerrMail.Domain.Models;
using Merrsoft.MerrMail.Infrastructure.External;
using Merrsoft.MerrMail.Infrastructure.Services;
using Merrsoft.MerrMail.Presentation;
using Serilog;
using Serilog.Events;

try
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console(
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] - {Message:lj}{NewLine}{Exception}")
.CreateLogger();

Log.Information("Starting Merr Mail");
Log.Information("Configuring Services");

var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSerilog();
builder.Services.AddHostedService<MerrMailWorker>();

// builder.Services.AddSingleton<HttpClient>();
builder.Services.AddHttpClient();
builder.Services.AddSingleton<IConfigurationSettings, EnvironmentVariables>();

builder.Services.AddSingleton<IApplicationService, ApplicationService>();
builder.Services.AddSingleton<IEmailApiService, GmailApiService>();
builder.Services.AddSingleton<IConfigurationReader, EnvConfigurationReader>();
builder.Services.AddSingleton<IOAuthClientCredentialsReader, GoogleOAuthClientCredentialsReader>();

var host = builder.Build();

host.Run();
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.ToString());
}
finally
{
Log.Information("Stopping Merr Mail");
Log.CloseAndFlush();
}
using Merrsoft.MerrMail.Application.Contracts;
using Merrsoft.MerrMail.Application.Services;
using Merrsoft.MerrMail.Domain.Contracts;
using Merrsoft.MerrMail.Domain.Models;
using Merrsoft.MerrMail.Infrastructure.External;
using Merrsoft.MerrMail.Infrastructure.Services;
using Merrsoft.MerrMail.Presentation;
using Serilog;
using Serilog.Events;

try
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console(
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] - {Message:lj}{NewLine}{Exception}")
.CreateLogger();

Log.Information("Starting Merr Mail");
Log.Information("Configuring Services");

var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSerilog();
builder.Services.AddHostedService<MerrMailWorker>();

// builder.Services.AddSingleton<HttpClient>();
builder.Services.AddHttpClient();
builder.Services.AddSingleton<IConfigurationSettings, EnvironmentVariables>();

builder.Services.AddSingleton<IApplicationService, ApplicationService>();
builder.Services.AddSingleton<IEmailApiService, GmailApiService>();
builder.Services.AddSingleton<IConfigurationReader, EnvConfigurationReader>();
builder.Services.AddSingleton<IOAuthClientCredentialsReader, GoogleOAuthClientCredentialsReader>();

var host = builder.Build();

host.Run();
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.ToString());
}
finally
{
Log.Information("Stopping Merr Mail");
Log.CloseAndFlush();
}
Ok I saw it now So what now? I think I haven't read the secrets
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Oh wait haven't i done this already?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
In all who needs it?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Is ApplicationOptions the common name for it?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Ohh
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Do you know a fast way to change every IConfigurationSettings configurationSettings to ApplicationOptions applicationOptions? As well as the one who calls the properties? Alright noted So why empty string?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Ohh nice separation
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
If theres no another {} then its everything in here?
No description
dabirbswerenoisyaround
The ""
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Alright I'm starting to get it
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
public class ApplicationOptions
{
public string OAuthClientCredentialsPath { get; set; } = string.Empty;
public string AccessTokenPath { get; set; } = string.Empty;
public string DatabaseConnection { get; set; } = string.Empty;
public string HostAddress { get; set; } = string.Empty;
}
public class ApplicationOptions
{
public string OAuthClientCredentialsPath { get; set; } = string.Empty;
public string AccessTokenPath { get; set; } = string.Empty;
public string DatabaseConnection { get; set; } = string.Empty;
public string HostAddress { get; set; } = string.Empty;
}
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Alright
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
public class ApplicationOptions
{
public required string OAuthClientCredentialsPath { get; set; }
public required string AccessTokenPath { get; set; }
public required string DatabaseConnection { get; set; }
public required string HostAddress { get; set; }
}
public class ApplicationOptions
{
public required string OAuthClientCredentialsPath { get; set; }
public required string AccessTokenPath { get; set; }
public required string DatabaseConnection { get; set; }
public required string HostAddress { get; set; }
}
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I'll comment this for now
dabirbswerenoisyaround
Save it for later
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Why double required? I actually haven't used [Required] before I'm just seeing it Bro im still copying 😭
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Thanks I'll check it out
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Bro you're helping me so much thank you
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Bookmarked it
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX10mo ago
appsettings.json:
{
"My": {
"Foo": {
"Kix": 5
}
}
}
{
"My": {
"Foo": {
"Kix": 5
}
}
}
src/Foo/FooOptions.cs:
public class FooOptions
{
public const string SectionName = "My:Foo";

public string Bar {get;set;} = "default value for bar";
public int Kix {get;set;} = -1;
public DateTime? Pouet {get;set;} = default;
}
public class FooOptions
{
public const string SectionName = "My:Foo";

public string Bar {get;set;} = "default value for bar";
public int Kix {get;set;} = -1;
public DateTime? Pouet {get;set;} = default;
}
src/Foo/FooServiceCollectionExtensions.cs:
namespace Microsoft.Extensions.DependencyInjection; // <==== recommanded for service.Add so that you don't clutter Startup file

public class FooServiceCollectionExtensions
{
public static IServiceCollection AddFoo(this IServiceCollection services) =>
services
.AddOptions<FooOptions>()
.BindConfiguration(FooOptions.SectionName)
.Validate(options => options.Kix >= 0, $"The configuration key '{FooOptions.SectionName}:{nameof(Kix)}' cannot be negative")
;

public static IServiceCollection AddFoo(this IServiceCollection services, Action<FooOptions> configure) =>
services
.AddFoo()
.Configure(configure);
namespace Microsoft.Extensions.DependencyInjection; // <==== recommanded for service.Add so that you don't clutter Startup file

public class FooServiceCollectionExtensions
{
public static IServiceCollection AddFoo(this IServiceCollection services) =>
services
.AddOptions<FooOptions>()
.BindConfiguration(FooOptions.SectionName)
.Validate(options => options.Kix >= 0, $"The configuration key '{FooOptions.SectionName}:{nameof(Kix)}' cannot be negative")
;

public static IServiceCollection AddFoo(this IServiceCollection services, Action<FooOptions> configure) =>
services
.AddFoo()
.Configure(configure);
Program.cs / Startup.cs:
services.AddFoo();
// or
services.AddFoo(fooOptions => fooOptions.Kix = 12);
services.AddFoo();
// or
services.AddFoo(fooOptions => fooOptions.Kix = 12);
Bar.cs:
public class Bar
{
private readonly FooOptions _fooOptions;

// .Value in ctor is fine only if it's always ever a non-changing value (no reload and/or no scoped resolution)
public Bar(IOptions<FooOptions> fooOptions)
=> _fooOptions = fooOptions.Value;
}
public class Bar
{
private readonly FooOptions _fooOptions;

// .Value in ctor is fine only if it's always ever a non-changing value (no reload and/or no scoped resolution)
public Bar(IOptions<FooOptions> fooOptions)
=> _fooOptions = fooOptions.Value;
}
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I didn't know there features like that on this server Where do you live? Its 11 pm right now here but I don't think I'll be able to sleep this night since I've just woken up Btw are you a senior dev?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Talking about perfect timing
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I also just got back, i'm currently renaming stuff On the 'dockerize branch'? I got back to the main branch and did the refactorings you suggested, i havent commit yet Wait
dabirbswerenoisyaround
GitHub
GitHub - dkroderos/mail at test
Merr Mail. Contribute to dkroderos/mail development by creating an account on GitHub.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Noted
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Btw i didnt used that
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Before implementing the gmail api i did that and i just realized its not needed
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Yeah i forgot that class Wait Lemme commit wat
dabirbswerenoisyaround
Look at this
No description
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Thats trash too Oh wait you refactored it?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Isn't record an init?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Look
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Yeah but i added the secrets
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
My bad i covered the first value
{
"OAuthClientCredentialPath": "C:\\GmailAPI\\credentials.json",
"DatabaseConnection": "hahahaha",
"AccessTokenPath": "C:\\GmailAPI\\token",
"HostAddress": "[email protected]"
}
{
"OAuthClientCredentialPath": "C:\\GmailAPI\\credentials.json",
"DatabaseConnection": "hahahaha",
"AccessTokenPath": "C:\\GmailAPI\\token",
"HostAddress": "[email protected]"
}
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
using System.ComponentModel.DataAnnotations;

namespace Merrsoft.MerrMail.Domain.Models;

public class ApplicationOptions
{
[Required]
public required string OAuthClientCredentialsPath { get; set; }

[Required]
public required string AccessTokenPath { get; set; }

[Required]
public required string DatabaseConnection { get; set; }

[Required]
public required string HostAddress { get; set; }
}
using System.ComponentModel.DataAnnotations;

namespace Merrsoft.MerrMail.Domain.Models;

public class ApplicationOptions
{
[Required]
public required string OAuthClientCredentialsPath { get; set; }

[Required]
public required string AccessTokenPath { get; set; }

[Required]
public required string DatabaseConnection { get; set; }

[Required]
public required string HostAddress { get; set; }
}
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
HAHAHAHAHAHAHAHAHAHAHA Oh my god typical dev stuff IT WORKED
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Thank you so much Thanks a lot again! I learned a lot tonight So
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I'll clean it up tomorrow Also On the startAsync
dabirbswerenoisyaround
I'm always checking if there is an internet
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
emails is [] ? balbal?
emails is [] ? logger.LogInformation("No new emails found. Waiting for new emails..."); : foreach
emails is [] ? logger.LogInformation("No new emails found. Waiting for new emails..."); : foreach
Like that?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Where is the
logger.LogInformation("No new emails found. Waiting for new emails...");
logger.LogInformation("No new emails found. Waiting for new emails...");
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I don't want my main logic on the worker itself Is that fine?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Go ahead please
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Alright i get it Make sense
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Should I also refactor the architecture?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
private async Task<bool> CheckInternetConnectionAsync() { try { using var response = await httpClient.GetAsync("https://www.google.com"); return response.IsSuccessStatusCode; } catch { return false; } } Is this redundant?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Pinging
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Since .AddHttpClient() is added its logging the ping now
dabirbswerenoisyaround
If i delete this it will loop the ping log. What do you think?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Actually when i started this project i wanted to test out clean architecture and see if it's better But then i realize that you can only test the architecture once other people try to understand your code
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Right now my benefit in this architecture is that I can convince someone that I know how to use it 😄 For resume mabye Its not done yet tho
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I will still have to implement nlp to check on the database if there are matched emails and reply to it So how do you structure your project?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Natural language processing
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Thanks ill check it out If you take a look at the repo i think my groupmate placed a pdf file in the docs folder, you can see the project proposals I hate school tho never learned something new there
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I guess im gonna create another help post Thanks again
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Dockerizing google api
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
HAHAHAHAHAH
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Im thinking of dockerizing as a way of publishing it Idk
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Does a container able to open browsers?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I think thats my current problem
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I dont mean ports tho
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
When using this api key it needs to authenticate on the browser and accept the terms and stuff I guess ill try it again My current task is to move this secrets.json to the container
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Hmmm
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Yeah i bookmarked it
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
But i still can do
dotnet run
dotnet run
right?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Mounting it?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Actually its my first using docker 😄
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
School sucks that I learned all of these things by myself
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Noted
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
DOTNET_ is required?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Thanks
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Oh thats nice So it seems like I dont need to add more ignored files and folders to the .gitignore
dabirbswerenoisyaround
This is the authentication im talking about So if my environent variables are paths, i still need to mount it Right?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
This doesnt 😄 So i cannot have a default docker-compose template? Or i just suggest to put the paths to the secrets folder inside the repo? If what im saying make sense 😄
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
services:
merrmail:
image: merrmail
build:
context: .
dockerfile: src/Presentation/Dockerfile
volumes:
- ./sample.env:/.env
- ./secrets:/secrets
services:
merrmail:
image: merrmail
build:
context: .
dockerfile: src/Presentation/Dockerfile
volumes:
- ./sample.env:/.env
- ./secrets:/secrets
My current docker compose file
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Havent touched it since the refactoring
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Yeah ill read it
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Yeah I just showed it to you
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/Presentation/Presentation.csproj", "src/Presentation/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
RUN dotnet restore "src/Presentation/Presentation.csproj"
COPY . .
WORKDIR "/src/src/Presentation"
RUN dotnet build "Presentation.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "Presentation.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Presentation.dll"]
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/Presentation/Presentation.csproj", "src/Presentation/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
RUN dotnet restore "src/Presentation/Presentation.csproj"
COPY . .
WORKDIR "/src/src/Presentation"
RUN dotnet build "Presentation.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "Presentation.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Presentation.dll"]
My current dockerfile I'll read the docs tomorrow Or ill guess later since its 2 am here
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
Oh wow Since 2012 Thank you so much again I guess I'll rest now :blushowo:
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
This one is already impressive
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
dabirbswerenoisyaround
I'm just cleaning up my desk and ill sleep now
Want results from more Discord servers?
Add your server