Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Libraries/LambdaSharp.Modules/VersionInfoCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ public static bool IsValidLambdaSharpAssemblyReferenceForToolVersion(VersionInfo
case "net8":
case "net8.0":

// .NET 8 projects require 0.8.5.*
// .NET 8 projects require 0.8.5.* or higher
valid = (libraryVersion.Major == 0)
&& (libraryVersion.Minor == 8)
&& (libraryVersion.Build == 5);
&& (libraryVersion.Build >= 5);
break;
default:
throw new VersionInfoCompatibilityUnsupportedFrameworkException(projectFramework);
Expand Down
10 changes: 10 additions & 0 deletions Modules/LambdaSharp.Core/CommonLib/RollbarApi/Rollbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,13 @@ public class Frame {
[JsonPropertyName("method")]
public string? Method { get; set; }
}

public class RollbarTeam {

//--- Properties ---
[JsonPropertyName("id")]
public int Id { get; set; }

[JsonPropertyName("name")]
public string? Name { get; set; }
}
47 changes: 47 additions & 0 deletions Modules/LambdaSharp.Core/CommonLib/RollbarApi/RollbarClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,52 @@ public async Task<RollbarProjectToken> CreateProjectTokenAsync(int projectId, st
return token;
}

public async Task AssignProjectToEngineeringTeamAsync(int projectId) {
const string ENGINEERING_TEAM_NAME = "Engineering";
LogInfo($"finding team '{ENGINEERING_TEAM_NAME}'");

// Get all teams
var httpResponse = await HttpClient.SendAsync(new HttpRequestMessage {
RequestUri = new Uri("https://api.rollbar.com/api/1/teams?limit=100"),
Method = HttpMethod.Get,
Headers = {{ "X-Rollbar-Access-Token", _accountReadAccessToken }}
});
if(!httpResponse.IsSuccessStatusCode) {
throw new RollbarClientException($"http operation failed: {httpResponse.StatusCode}");
}
var result = Deserialize<RollbarResponse>(await httpResponse.Content.ReadAsStringAsync());
if(result.Error != 0) {
throw new RollbarClientException($"rollbar operation failed (error {result.Error}): {result.Message}");
}

// Parse teams and find Engineering
var teamsJson = Serialize(result.Result);
var teams = Deserialize<List<RollbarTeam>>(teamsJson);
var engineeringTeam = teams?.FirstOrDefault(t =>
t.Name?.Equals(ENGINEERING_TEAM_NAME, StringComparison.OrdinalIgnoreCase) == true
);

if(engineeringTeam == null) {
throw new RollbarClientException($"team '{ENGINEERING_TEAM_NAME}' not found");
}

var teamId = engineeringTeam.Id;
LogInfo($"assigning rollbar project {projectId} to team '{ENGINEERING_TEAM_NAME}' (ID: {teamId})");

httpResponse = await HttpClient.SendAsync(new HttpRequestMessage {
RequestUri = new Uri($"https://api.rollbar.com/api/1/team/{teamId}/project/{projectId}"),
Method = HttpMethod.Put,
Headers = {{ "X-Rollbar-Access-Token", _accountWriteAccessToken }}
});
if(!httpResponse.IsSuccessStatusCode) {
throw new RollbarClientException($"http operation failed: {httpResponse.StatusCode}");
}
result = Deserialize<RollbarResponse>(await httpResponse.Content.ReadAsStringAsync());
if(result.Error != 0) {
throw new RollbarClientException($"rollbar operation failed (error {result.Error}): {result.Message}");
}
LogInfo($"assigned rollbar project {projectId} to team '{ENGINEERING_TEAM_NAME}'");
}

private void LogInfo(string message) => _logInfo?.Invoke(message);
}
22 changes: 19 additions & 3 deletions Modules/LambdaSharp.Core/RegistrationFunction/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,16 @@ public override async Task<Response<RegistrationResourceAttributes>> ProcessUpda

// update module record
LogInfo($"Updating Module: Id={properties.ModuleId}, Info={properties.GetModuleInfo()}");
var owner = PopulateOwnerMetaData(properties);

// get existing owner or create new one
var owner = await Registrations.GetOwnerMetaDataAsync($"M:{properties.ModuleId}");
owner = PopulateOwnerMetaData(properties, owner);
if(RollbarClient.HasTokens) {
var rollbarProject = await RegisterRollbarProject(properties);
owner.RollbarProjectId = rollbarProject.ProjectId;
owner.RollbarAccessToken = rollbarProject.ProjectAccessToken;
}

await Registrations.PutOwnerMetaDataAsync($"M:{properties.ModuleId}", owner);
return Respond(request.PhysicalResourceId);
}
Expand Down Expand Up @@ -418,10 +427,17 @@ private OwnerMetaData PopulateOwnerMetaData(RegistrationResourceProperties prope
}

// find or create Rollbar project
var project = await RollbarClient.FindProjectByNameAsync(name)
?? await RollbarClient.CreateProjectAsync(name);
var existingProject = await RollbarClient.FindProjectByNameAsync(name);
var project = existingProject ?? await RollbarClient.CreateProjectAsync(name);
LogInfo($"Using Rollbar project '{project.Name}' (ID: {project.Id})");

// assign project to Engineering team.
try {
await RollbarClient.AssignProjectToEngineeringTeamAsync(project.Id);
} catch(Exception e) {
LogWarn($"Failed to assign project to Engineering team: {e.Message}");
}

// retrieve or create access token for Rollbar project
var tokens = await RollbarClient.ListProjectTokensAsync(project.Id);
var token = tokens.FirstOrDefault(t => t.Name == "post_server_item")?.AccessToken;
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Set-Lash-Version.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set variables
$env:LAMBDASHARP_VERSION_PREFIX = "0.8.5"
$env:LAMBDASHARP_VERSION_PREFIX = "0.8.5.1"
$env:LAMBDASHARP_VERSION_SUFFIX = ""

# Create full version text
Expand Down
2 changes: 1 addition & 1 deletion Scripts/set-lash-version.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

export LAMBDASHARP_VERSION_PREFIX=0.8.5.0
export LAMBDASHARP_VERSION_PREFIX=0.8.5.1
export LAMBDASHARP_VERSION_SUFFIX=

# create full version text
Expand Down