3 Commits

Author SHA1 Message Date
9fae3b978f Modified ClaimNameAttribute to support multiple claim names depending on environment
All checks were successful
ci/woodpecker/tag/api_build Pipeline was successful
ci/woodpecker/tag/api_uploadimage Pipeline was successful
Environment name will be pulled from environment variable: ASPNETCORE_ENVIRONMENT
2024-04-07 20:18:53 -05:00
822a8379aa Merge pull request 'Created Woodpecker CI/CD deployment' (#38) from feature/CreateCIPlans into develop
All checks were successful
ci/woodpecker/push/api_build Pipeline was successful
Reviewed-on: #38
2024-04-07 15:20:05 -05:00
a5d5ed048f Created Woodpecker CI/CD deployment
- Created Dockerfile for packing up API and Web projects as Docker image
2024-04-07 14:51:28 -05:00
8 changed files with 49 additions and 15 deletions

View File

@ -18,7 +18,9 @@ steps:
- rm -f tags.txt
- echo ${CI_COMMIT_TAG} | sed -e "s/^WEB-//" >> tags.txt
- echo "latest" >> tags.txt
- name: (YABA.Web) Package and Upload Docker Image
- name: (YABA.Web) Package and Upload Docker Image (dev)
when:
- ref: refs/tags/WEBDEV-*
image: woodpeckerci/plugin-docker-buildx
settings:
repo: gitea.iwanaga.moe/cjtibule/yaba/web
@ -32,3 +34,19 @@ steps:
registry: gitea.iwanaga.moe
build_args:
from_secret: DEV1_BUILDARGS
- name: (YABA.Web) Package and Upload Docker Image (prod)
when:
- ref: refs/tags/WEB-*
image: woodpeckerci/plugin-docker-buildx
settings:
repo: gitea.iwanaga.moe/cjtibule/yaba/web
context: ./Web
dockerfile: ./Web/Dockerfile
tags_file: tags.txt
username:
from_secret: gitea_yaba_registry_username
password:
from_secret: gitea_yaba_registry_password
registry: gitea.iwanaga.moe
build_args:
from_secret: PROD_BUILDARGS

View File

@ -13,7 +13,9 @@ ENV ASPNETCORE_Authentication__Auth0__Domain=
ENV ASPNETCORE_Authentication__Auth0__Identifier=
ENV ASPNETCORE_ConnectionStrings__YABAReadOnlyDbConnectionString=
ENV ASPNETCORE_ConnectionStrings__YABAReadWriteDbConnectionString=
ENV ASPNETCORE_WebClient__Url=
ENV WebClient__Url=
ENV Serilog__WriteTo__1__Args__Uri=
ENV Serilog__WriteTo__1__Args__Labels__1__Value=
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
WORKDIR /src

View File

@ -2,6 +2,7 @@
using YABA.API.Extensions;
using YABA.Common.Extensions;
using YABA.Common.Lookups;
using YABA.Common.Utils;
using YABA.Service.Interfaces;
namespace YABA.API.Middlewares
@ -31,7 +32,7 @@ namespace YABA.API.Middlewares
userId = registedUser.Id;
}
httpContext.User.Identities.FirstOrDefault().AddClaim(new Claim(ClaimsLookup.UserId.GetClaimName(), userId.ToString()));
httpContext.User.Identities.FirstOrDefault().AddClaim(new Claim(ClaimsLookup.UserId.GetClaimName(EnvironmentUtils.IsDevelopmentEnvironment()), userId.ToString()));
}
}

View File

@ -4,11 +4,13 @@ namespace YABA.Common.Attributes
{
public class ClaimNameAttribute : Attribute
{
public string Name { get; private set; }
public string DevClaimName { get; private set; }
public string ProdClaimName { get; private set; }
public ClaimNameAttribute(string name)
public ClaimNameAttribute(string devClaimName, string prodClaimName)
{
this.Name = name;
this.DevClaimName = devClaimName;
ProdClaimName = prodClaimName;
}
}
}

View File

@ -28,9 +28,9 @@ namespace YABA.Common.Extensions
return enumValue.GetAttribute<DisplayAttribute>().Name;
}
public static string GetClaimName(this ClaimsLookup claimLookup)
public static string GetClaimName(this ClaimsLookup claimLookup, bool isDevelopmentEnvironment)
{
return claimLookup.GetAttribute<ClaimNameAttribute>().Name;
return isDevelopmentEnvironment ? claimLookup.GetAttribute<ClaimNameAttribute>().DevClaimName : claimLookup.GetAttribute<ClaimNameAttribute>().ProdClaimName;
}
public static bool IsCrudResultSuccessful(this CrudResultLookup importStatusLookup) => SuccessfulCrudStatuses.Contains(importStatusLookup);

View File

@ -1,6 +1,8 @@
using System.Security.Claims;
using System;
using System.Security.Claims;
using System.Security.Principal;
using YABA.Common.Lookups;
using YABA.Common.Utils;
namespace YABA.Common.Extensions
{
@ -12,7 +14,7 @@ namespace YABA.Common.Extensions
public static string GetCustomClaim(this IIdentity identity, ClaimsLookup claim)
{
var claimsIdentity = identity as ClaimsIdentity;
return claimsIdentity.FindFirst(claim.GetClaimName())?.Value.ToString();
return claimsIdentity.FindFirst(claim.GetClaimName(EnvironmentUtils.IsDevelopmentEnvironment()))?.Value.ToString();
}
}
}

View File

@ -4,19 +4,19 @@ namespace YABA.Common.Lookups
{
public enum ClaimsLookup
{
[ClaimNameAttribute("https://dev.iwanaga.moe/api/auth_provider_id")]
[ClaimName("https://auth.dev.iwanaga.moe/api/auth_provider_id", "https://auth.iwanaga.moe/api/auth_provider_id")]
AuthProviderId = 1,
[ClaimNameAttribute("https://dev.iwanaga.moe/api/email_address")]
[ClaimName("https://auth.dev.iwanaga.moe/api/email_address", "https://auth.iwanaga.moe/api/email_address")]
UserEmail = 2,
[ClaimNameAttribute("https://dev.iwanaga.moe/api/email_verified")]
[ClaimName("https://auth.dev.iwanaga.moe/api/email_verified", "https://auth.iwanaga.moe/api/email_verified")]
IsEmailConfirmed = 3,
[ClaimNameAttribute("https://dev.iwanaga.moe/api/username")]
[ClaimName("https://auth.dev.iwanaga.moe/api/username", "https://auth.iwanaga.moe/api/username")]
Username = 4,
[ClaimNameAttribute("https://dev.iwanaga.moe/api/id")]
[ClaimName("https://auth.dev.iwanaga.moe/api/id", "https://auth.iwanaga.moe/api/id")]
UserId = 5
}
}

View File

@ -0,0 +1,9 @@
using System;
namespace YABA.Common.Utils
{
public static class EnvironmentUtils
{
public static bool IsDevelopmentEnvironment() => Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development";
}
}