Posts

Showing posts from September, 2024

AWS Cognito Error on Sign Up

I was exploring AWS Cognito for authentication. It works great, but I got the following error message after I tested the sign up process: An error was encountered with the requested page. I found out later that I misunderstood the AutoVerifiedAttributes field in my CloudFormation. I thought it would mark an email or phone number as verified without actually verifying them. Apparently, it means it will try to verify either email or phone number. So, when I set it to email, it sent a verification email and the sign up process went without error.

ASP.NET Application Crashed without Error Message

I encountered a strange error with ASP.NET Web API application. It runs fine locally, but when we deployed to Kubernetes cluster, it crashed as soon as it starts. And no error message was thrown. So, I pulled the application to my local and it crashed as well no matter how I run it, dotnet cli, Docker Desktop, Visual Studio debug. The only one that runs fine is the version from the repo. At this point, there are only two possibilities, either the environment is the issue or the application is the issue, so I decided to deploy it to a different environment and it's still not working, so it must be something with the application. Since it is the application, I tried to change the log level to Trace to get more information but no new error message that provides a hint on what's going on. Memory dump didn't work as the collector didn't have enough time to collect before the application crashed. At the end, I decided to approach this the hard way. So, in my local, there are ...

JWT is not well formed in ASP.NET Web API JwtBearer .NET 8

 It never caused a problem for me to implement JwtBearer token validator, but this time it is really take my time to troubleshoot what's going on. Long story short, there's a breaking change going to .NET 8 and on top of that, the default package version doesn't solve the issue. Here's how I implement my service: services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options => ...removed for brevity); services.AddAuthorization(); ... app.UseAuthentication(); app.UseAuthorization(); But checking the bearer token, it was a completely valid token. I retrieved the token using a quick custom middleware. app.Use(async (context, next) => { await next.Invoke(); Debug.WriteLine(context.Request.Headers.Authorization); }); app.UseAuthentication(); ... Then I validate the token in  https://jwt.io . The error that I received contains: IDX14100: JWT is not well formed, there are no dots (.). Th...

Swagger .NET 8 Error

Swashbuckle CLI was able to output schema of my API before, but this time, it throws this error message: System.InvalidOperationException: A type named 'StartupProduction' or 'Startup' could not be found in assembly I used top level statement with minimal API on .NET 8 and nothing is changed on that, so I was not able to find anything to do with Startup type. After I investigate further by commenting line by line, I found out that the issue is on my switch statement. So it looks like the following: return config.Section?.Key switch { Value1 => services.AddSingleton<Handler1>(), Value2 => services.AddSingleton<Handler2>(), _ => throw new InvalidOperationException(); } Problem is the Section is pulled from appsettings.json and when the CLI runs, it doesn't have value, so it never returned the services object. Changing the above to the following fixed the issue: return config.Section == null ? services : config.Section.Key switch { Value1 =...

Background Image on WordPress Editor

I realized that I don't have the Layout option under Styles menu in the Editor. I found out later that I have a bare minimum theme.json. And adding appearanceTools: true field cause it to show up. My theme.json became: { "version": 3, "$schema": "https://schemas.wp.org/wp/6.6/theme.json", "settings": { "appearanceTools": true } }

WordPress Create Block Theme Plugin

 I'm working on a custom WordPress theme and I saw a very helpful plugin called "Create Block Theme" which is supposed to help developer create the theme. So, for starting, I tried to edit one of my templates, but when I hit "Save Changes" under "Save Changes to Theme" section, I expected it to overwrite my template html file, but it didn't. I was checking permissions and potential bugs, but seems like everything is good. After playing around a little, apparently, I need to hit "Save" first, so it records the customization in the database and then click the "Save Changes to Theme" will use the value from the database and modified the html file itself.

Delete Git Branches by Days Ago

Often my branches piled up and I need a way to automatically delete them based on how many days ago. I can't find an easy way online, so I ended up writing my own scripts in PowerShell and Bash. In this repo, I have the script to clean up branches that are 90 days or older based on last committed date. Repo:  https://github.com/nik-yo/DeleteGitBranchesByDaysAgo

Rename PySpark Result File

 Due to the distributed nature of Apache Spark, when writing result, we can't specify name for the result file. This makes the result file hard to predict which I need for my process orchestration. In my case, I need to write the result to S3 and I finally found a way to do this within a reasonable amount of time by utilizing aws wrangler, Panda, and optionally Arrow. I basically feed Spark dataframe to aws wrangler and have it write to S3 using a specific name. Here's link to my sample:  https://github.com/nik-yo/PySparkFilename

Connecting Pod in Minikube to Kafka or any Services Running in Docker Desktop

I'm working on a demo where I need to subscribe my application to Kafka locally in Docker Desktop. I have 3 use cases: Connecting from a different container in Docker desktop, so in the same network as the Kafka container. Connecting from the application running on the host, so outside of Docker desktop for debugging purposes. Connecting from a pod inside Minikube running in Docker Desktop. Same Docker Network On the first case, I actually need to connect AKHQ container to Kafka, my Kafka container env variable for advertised listeners looks like the following: environment: KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092 , ... (removed for brevity) Since AKHQ running in Docker desktop as well, it can use kafka:29092. From the Host (my computer) Outside of Docker Network Next is my application that runs outside of Docker desktop, since it won't resolve the kafka host, it has to use the 2nd entry of the advertised listener. In my case, I had to change the port from 9092 t...

Multiple BackgroundService or IHostedServices but Only One Works

 In my worker app, I attempted to add multiple hosted services as follow: builder.Services .addSingleton(HostedService1) .addSingleton(HostedService2) .addSingleton(HostedService3); All the hosted services are added, but when the application run, only 1 is executing. Thanks to Stephen Cleary, apparently issue with synchronous call.  https://blog.stephencleary.com/2020/05/backgroundservice-gotcha-startup.html . I ended up using Task.Run for code that executes for a long time. Inside the ExecuteAsync: await Task.Run(async () => await LongRunningProcess());

Use Multiple Git Accounts on One Computer

I was looking for a way to use two git accounts in a single machine. Apparently, there are multiple ways to do that: Use different protocols for different accounts. One account can use HTTP, another account uses SSH. Use different SSH keys. One per account. Use HTTP and PAT. This might be GitHub specific but per my experience with PAT in Azure DevOps, this is not feasible as PAT has expiration and needs to be renewed.  https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-your-personal-account/managing-multiple-accounts I ended up using different protocols since that will save me effort in configuring one of the accounts. First, I need to create an ssh key.  https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key . Since I'm in Windows, I can use Git Bash. Launch Git Bash Run: ssh-keygen -t ed25519 -C "your_email@example.com...