|
8 | 8 | using OptimaJet.DWKit.StarterApplication.Models;
|
9 | 9 | using OptimaJet.DWKit.StarterApplication.Services;
|
10 | 10 | using OptimaJet.DWKit.StarterApplication.Services.BuildEngine;
|
| 11 | +using Serilog; |
11 | 12 |
|
12 | 13 | namespace OptimaJet.DWKit.StarterApplication.Controllers
|
13 | 14 | {
|
@@ -39,38 +40,86 @@ public async Task<IActionResult> GetProjectToken(int id)
|
39 | 40 | {
|
40 | 41 | return NotFound($"Project id={id} not found");
|
41 | 42 | }
|
| 43 | + Log.Debug($"GetProjectToken: id={id}, OwnerId={project.OwnerId}, User.Id={CurrentUser.Id}"); |
42 | 44 |
|
43 | 45 | if (project.WorkflowProjectUrl == null)
|
44 | 46 | {
|
45 | 47 | return NotFound($"Project id={id}: WorkflowProjectUrl is null");
|
46 | 48 | }
|
| 49 | + Log.Debug($"WorkflowProjectUrl={project.WorkflowAppProjectUrl}"); |
47 | 50 |
|
48 | 51 | var role = await ProjectService.GetUserRoleForProject(project, CurrentUser.Id);
|
| 52 | + Log.Debug($"role: roleId={role.RoleId}, roleName={role.RoleName}, orgId={role.OrganizationId}"); |
| 53 | + |
49 | 54 | bool readOnly;
|
50 | 55 | if (CurrentUser.Id == project.OwnerId)
|
51 | 56 | {
|
| 57 | + Log.Debug("READONLY: current user so false"); |
52 | 58 | 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 |
61 | 60 | {
|
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 | + } |
63 | 81 | }
|
64 | 82 |
|
| 83 | + Log.Debug($"Requesting Token: project.id={id}, readOnly={readOnly}"); |
65 | 84 | var token = await BuildEngineProjectService.GetProjectTokenAsync(id, readOnly);
|
| 85 | + Log.Debug("Received Token"); |
66 | 86 | if (token == null)
|
67 | 87 | {
|
| 88 | + Log.Debug($"Project id={id}: GetProjectToken returned null"); |
68 | 89 | return NotFound($"Project id={id}: GetProjectToken returned null");
|
69 | 90 | }
|
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)) |
71 | 99 | {
|
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"); |
73 | 102 | }
|
| 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}"); |
74 | 123 | var projectToken = new ProjectToken
|
75 | 124 | {
|
76 | 125 | Id = id,
|
|
0 commit comments