Skip to content

Commit

Permalink
moved to ENV vars for some core config fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Radoslav Radev committed May 17, 2024
1 parent 61d5e59 commit 2618132
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 13 deletions.
8 changes: 7 additions & 1 deletion Backend/APIGateway/Auth/OwnAuthHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace OpenVidStreamer.APIGateway.Auth;

public class OwnAuthHandler : AuthenticationHandler<AuthenticationSchemeOptions>
{


private readonly string _jwtSecret;

IConfiguration _configuration;

Expand All @@ -30,6 +33,7 @@ public OwnAuthHandler(IOptionsMonitor<AuthenticationSchemeOptions> options,
: base(options, logger, encoder, clock)

Check warning on line 33 in Backend/APIGateway/Auth/OwnAuthHandler.cs

View workflow job for this annotation

GitHub Actions / build

'AuthenticationHandler<AuthenticationSchemeOptions>.AuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions>, ILoggerFactory, UrlEncoder, ISystemClock)' is obsolete: 'ISystemClock is obsolete, use TimeProvider on AuthenticationSchemeOptions instead.'

Check warning on line 33 in Backend/APIGateway/Auth/OwnAuthHandler.cs

View workflow job for this annotation

GitHub Actions / build

'AuthenticationHandler<AuthenticationSchemeOptions>.AuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions>, ILoggerFactory, UrlEncoder, ISystemClock)' is obsolete: 'ISystemClock is obsolete, use TimeProvider on AuthenticationSchemeOptions instead.'
{
_configuration = configuration;
_jwtSecret = Environment.GetEnvironmentVariable("JwtSecret") ?? configuration["CustomJWT:Secret"];

Check warning on line 36 in Backend/APIGateway/Auth/OwnAuthHandler.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

Check warning on line 36 in Backend/APIGateway/Auth/OwnAuthHandler.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
}


Expand Down Expand Up @@ -63,14 +67,16 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
}
try
{


var validationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidIssuer = _configuration["CustomJWT:Issuer"],
ValidAudience = _configuration["CustomJWT:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["CustomJWT:Secret"]))
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwtSecret))
};

var handler = new JwtSecurityTokenHandler();
Expand Down
3 changes: 2 additions & 1 deletion Backend/Account/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
builder.Services.AddScoped<StripePaymentService>();
builder.Services.AddHealthChecks();

StripeConfiguration.ApiKey = builder.Configuration["Stripe:SecretKey"];
var stripeKey = Environment.GetEnvironmentVariable("StripeSecretKey") ?? builder.Configuration["Stripe:SecretKey"];
StripeConfiguration.ApiKey = stripeKey;


var app = builder.Build();
Expand Down
9 changes: 7 additions & 2 deletions Backend/Account/Services/AuthTokenGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public static class AuthTokenGenerator
{
public static string GenerateOwnAuthToken(string accId, IConfiguration configuration,bool hasActiveSubscription = false)
{
string _jwtSecret = Environment.GetEnvironmentVariable("JwtSecret") ?? configuration["CustomJWT:Secret"];
string _jwtExpiration = Environment.GetEnvironmentVariable("JwtExpiration") ??
configuration["CustomJWT:ExpirationInHours"];


// Define token claims
var claims = new List<Claim>
{
Expand All @@ -27,14 +32,14 @@ public static string GenerateOwnAuthToken(string accId, IConfiguration configura


// Generate token
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["CustomJWT:Secret"]));
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwtSecret));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

var token = new JwtSecurityToken(
issuer: configuration["CustomJWT:Issuer"],
audience: configuration["CustomJWT:Audience"],
claims: claims,
expires: DateTime.Now.AddMinutes(Convert.ToInt32(configuration["CustomJWT:ExpirationInHours"])), // Token expiry time
expires: DateTime.Now.AddMinutes(Convert.ToInt32(_jwtExpiration)), // Token expiry time
signingCredentials: creds);

return new JwtSecurityTokenHandler().WriteToken(token);
Expand Down
7 changes: 6 additions & 1 deletion Backend/Account/Services/StripePaymentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
namespace Account.Services;
public class StripePaymentService
{

private readonly string _stripeRedirectUrl;

private readonly DatabaseContext _accountDbContext;
private readonly IAsyncPolicy<PaymentIntent> _retryPolicy = Policy
.HandleResult<PaymentIntent>(paymentIntent => paymentIntent.Status == "requires_action" || paymentIntent.Status == "requires_payment_method")
Expand All @@ -22,6 +25,8 @@ public StripePaymentService(DatabaseContext accountDbContext, IConfiguration con
{
_accountDbContext = accountDbContext;
_configuration = configuration;
_stripeRedirectUrl = Environment.GetEnvironmentVariable("StripeRedirectUrl") ??
_configuration.GetValue<string>("Stripe:RedirectUrl");
}

public async Task<PaymentIntent> ProcessPaymentAsync(IncomingPaymentDTO incomingPayment, string accId)
Expand Down Expand Up @@ -50,7 +55,7 @@ public async Task<PaymentIntent> ProcessPaymentAsync(IncomingPaymentDTO incoming
Description = $"OpenVidStreamer - Payment of monthly subscription for AccountNumber: {accId}",
Confirm = true,
UseStripeSdk = true,
ReturnUrl = _configuration.GetValue<string>("Stripe:RedirectUrl"),
ReturnUrl = _stripeRedirectUrl,
Customer = customer.Id
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const UploadPage = () => {
onUploadProgress: progressEvent => {
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
setUploadPercentage(percentCompleted);
console.log("Upload progress: " + percentCompleted + "%")
}
});
alert('Video uploaded successfully!');
Expand Down
2 changes: 1 addition & 1 deletion K6Tests/StreamVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export let options = {
export default function () {
const params = {
headers: {
'Authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cG4iOiIwOGRjNDIwNy1mZWMwLTRlOTctOGY4MC0zYWU1MDUyYTMwNWEiLCJzdWIiOiIwOGRjNDIwNy1mZWMwLTRlOTctOGY4MC0zYWU1MDUyYTMwNWEiLCJqdGkiOiIyNWYwNjgxZC04NzMwLTQ4ZDgtODIyMC0xMzYyMzAwNGVhMmIiLCJleHAiOjE3MTQ1NzE3MTAsImlzcyI6Ik9wZW5WaWRTdHJlYW1lckFjY291bnRTZXJ2aWNlIiwiYXVkIjoiT3BlblZpZFN0cmVhbWVyRkUifQ.LV4iObB6OXV66kdx9caprcWawHbgAHG0HmyYEvuuxmk'
'Authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cG4iOiIwOGRjNDIwNy1mZWMwLTRlOTctOGY4MC0zYWU1MDUyYTMwNWEiLCJzdWIiOiIwOGRjNDIwNy1mZWMwLTRlOTctOGY4MC0zYWU1MDUyYTMwNWEiLCJqdGkiOiIwNWEyM2JiMS02NThhLTRjODMtOTgyNS1lMzM4MWZjNGViOTQiLCJleHAiOjE3MTQ5ODY2MTAsImlzcyI6Ik9wZW5WaWRTdHJlYW1lckFjY291bnRTZXJ2aWNlIiwiYXVkIjoiT3BlblZpZFN0cmVhbWVyRkUifQ.j5DQGFXBZovCMj_vQVmOyd9fv0DwtyiMhbZ0pe6wwok'
}

};
Expand Down
10 changes: 9 additions & 1 deletion OpenVidStreamerKubernetesFiles/account-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ spec:
fieldPath: status.podIP
- name: servicePort
value: "8081"

# CHANGE ALL ENV VARS BELLOW !!!!!
- name: StripeSecretKey
value: "sk_test_51J4J7sk_test_51OpbAqLhuzbscNjkorQ4sXh7YsruJX0mYn3seAyim6fAaxZ2vnawug50BZknBpdbKCLOTNu1eT3pXWG84bDKLhab00kyOhVEW2"
- name: StripeRedirectUrl
value: "http://145.220.74.148:3000/paymentProcessed"
- name: JwtSecret
value: "rxio0SNqgU2yYEvOyZJ1greSMC75JBU0D6IxBZBxIXm+xzSr2ZZ+ZV/PHoV7sNYg7f9PCHulGu+QHG5qaSNpTQ=="
- name: JwtExpiration
value: "72"
6 changes: 3 additions & 3 deletions OpenVidStreamerKubernetesFiles/apigateway-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ kind: Service
metadata:
name: apigateway-service
spec:
type: LoadBalancer
type: NodePort
selector:
app: apigateway
ports:
- protocol: TCP
port: 8000
- port: 8000
targetPort: 8000
nodePort: 31800
3 changes: 1 addition & 2 deletions OpenVidStreamerKubernetesFiles/render-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
kind: Deployment
metadata:
name: render-deployment
spec:
replicas: 2
spec:
selector:
matchLabels:
app: render
Expand Down
2 changes: 1 addition & 1 deletion OpenVidStreamerKubernetesFiles/render-hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ spec:
name: cpu
target:
type: Utilization
averageUtilization: 95
averageUtilization: 10

0 comments on commit 2618132

Please sign in to comment.