Skip to content

Commit 55c888f

Browse files
committed
Add Logging for Token issue
1 parent 75b65ee commit 55c888f

File tree

3 files changed

+65
-11
lines changed

3 files changed

+65
-11
lines changed

source/OptimaJet.DWKit.StarterApplication/Controllers/ProjectsController.cs

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using OptimaJet.DWKit.StarterApplication.Models;
99
using OptimaJet.DWKit.StarterApplication.Services;
1010
using OptimaJet.DWKit.StarterApplication.Services.BuildEngine;
11+
using Serilog;
1112

1213
namespace OptimaJet.DWKit.StarterApplication.Controllers
1314
{
@@ -39,38 +40,86 @@ public async Task<IActionResult> GetProjectToken(int id)
3940
{
4041
return NotFound($"Project id={id} not found");
4142
}
43+
Log.Debug($"GetProjectToken: id={id}, OwnerId={project.OwnerId}, User.Id={CurrentUser.Id}");
4244

4345
if (project.WorkflowProjectUrl == null)
4446
{
4547
return NotFound($"Project id={id}: WorkflowProjectUrl is null");
4648
}
49+
Log.Debug($"WorkflowProjectUrl={project.WorkflowAppProjectUrl}");
4750

4851
var role = await ProjectService.GetUserRoleForProject(project, CurrentUser.Id);
52+
Log.Debug($"role: roleId={role.RoleId}, roleName={role.RoleName}, orgId={role.OrganizationId}");
53+
4954
bool readOnly;
5055
if (CurrentUser.Id == project.OwnerId)
5156
{
57+
Log.Debug("READONLY: current user so false");
5258
readOnly = false;
53-
} else if (role != null && role.RoleName == RoleName.OrganizationAdmin)
54-
{
55-
readOnly = true;
56-
}
57-
else if (CurrentUser.HasRole(RoleName.SuperAdmin)) {
58-
readOnly = true;
59-
}
60-
else
59+
} else
6160
{
62-
return NotFound($"Project id={id}, user={CurrentUser.Name} does not have permission");
61+
Log.Debug("READONLY: Not Owner ... next check");
62+
if (role != null && role.RoleName == RoleName.OrganizationAdmin)
63+
{
64+
Log.Debug("READONLY: Org Admin so true");
65+
readOnly = true;
66+
}
67+
else
68+
{
69+
Log.Debug("READONLY: Not Org Admin ... next check");
70+
if (CurrentUser.HasRole(RoleName.SuperAdmin))
71+
{
72+
Log.Debug("READONLY: Super Admin so true");
73+
readOnly = true;
74+
}
75+
else
76+
{
77+
Log.Debug("READONLY: No permission so return early");
78+
return NotFound($"Project id={id}, user={CurrentUser.Name} does not have permission");
79+
}
80+
}
6381
}
6482

83+
Log.Debug($"Requesting Token: project.id={id}, readOnly={readOnly}");
6584
var token = await BuildEngineProjectService.GetProjectTokenAsync(id, readOnly);
85+
Log.Debug("Received Token");
6686
if (token == null)
6787
{
88+
Log.Debug($"Project id={id}: GetProjectToken returned null");
6889
return NotFound($"Project id={id}: GetProjectToken returned null");
6990
}
70-
if (token.SecretAccessKey == null)
91+
Log.Debug("Token is not null");
92+
if (String.IsNullOrEmpty(token.SecretAccessKey))
93+
{
94+
Log.Debug($"Project id={id}: Token.SecretAccessKey is null or empty");
95+
return NotFound($"Project id={id}: Token.SecretAccessKey is null or empty");
96+
}
97+
Log.Debug("Token.SecretAccessKey is not null or empty");
98+
if (String.IsNullOrEmpty(token.AccessKeyId))
7199
{
72-
return NotFound($"Project id={id}: Token.SecretAccessKey is null");
100+
Log.Debug($"Project id={id}: Token.AccessKeyId is null or empty");
101+
return NotFound($"Project id={id}: Token.AccessKeyId is null or empty");
73102
}
103+
Log.Debug("Token.AccessKeyId is not null or empty");
104+
if (String.IsNullOrEmpty(token.Expiration))
105+
{
106+
Log.Debug($"Project id={id}: Token.Expiration is null or empty");
107+
return NotFound($"Project id={id}: Token.Expiration is null or empty");
108+
}
109+
Log.Debug("Token.Expiration is not null or empty");
110+
if (String.IsNullOrEmpty(token.Region))
111+
{
112+
Log.Debug($"Project id={id}: Token.Region is null or empty");
113+
return NotFound($"Project id={id}: Token.Region is null or empty");
114+
}
115+
Log.Debug("Token.Region is not null or empty");
116+
117+
Log.Debug($"token: sessionToken={token.SessionToken}");
118+
Log.Debug($"token: secretAccessKey={token.SecretAccessKey}");
119+
Log.Debug($"token: accessKeyId={token.AccessKeyId}");
120+
Log.Debug($"token: expire={token.Expiration}");
121+
Log.Debug($"token: readOnly={token.ReadOnly}");
122+
Log.Debug($"token: region={token.Region}");
74123
var projectToken = new ProjectToken
75124
{
76125
Id = id,

source/OptimaJet.DWKit.StarterApplication/Services/BuildEngine/BuildEngineProjectService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Job = Hangfire.Common.Job;
1313
using Project = OptimaJet.DWKit.StarterApplication.Models.Project;
1414
using static OptimaJet.DWKit.StarterApplication.Utility.EnvironmentHelpers;
15+
using Serilog;
1516

1617
namespace OptimaJet.DWKit.StarterApplication.Services.BuildEngine
1718
{
@@ -59,7 +60,9 @@ public async Task<TokenResponse> GetProjectTokenAsync(int projectId, bool readOn
5960
Name = name,
6061
ReadOnly = readOnly
6162
};
63+
Log.Debug($"GetProjectToken: name={name}, readOnly={readOnly}, workflowProjectId={project.WorkflowProjectId}");
6264
var tokenResponse = BuildEngineApi.GetProjectAccessToken(project.WorkflowProjectId, tokenRequest);
65+
Log.Debug($"GetProjectToken: response={tokenResponse}");
6366
return tokenResponse;
6467
}
6568
}

source/OptimaJet.DWKit.StarterApplication/Services/BuildEngine/BuildEngineServiceBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using OptimaJet.DWKit.StarterApplication.Repositories;
99
using SIL.AppBuilder.BuildEngineApiClient;
1010
using static OptimaJet.DWKit.StarterApplication.Utility.EnvironmentHelpers;
11+
using Serilog;
1112

1213
namespace OptimaJet.DWKit.StarterApplication.Services.BuildEngine
1314
{
@@ -50,6 +51,7 @@ protected bool SetBuildEngineEndpoint(Organization organization)
5051
{
5152
var endpoint = GetBuildEngineEndpoint(organization);
5253
if (!endpoint.IsValid()) { return false; }
54+
Log.Debug($"SetBuildEngineEndpoint: Organization={organization.Name}, Endpoint.Url={endpoint.Url}, Endpoint.Token={endpoint.ApiAccessToken}");
5355
BuildEngineApi.SetEndpoint(endpoint.Url, endpoint.ApiAccessToken);
5456
return true;
5557
}

0 commit comments

Comments
 (0)