-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User Tasks is a new resource that contains issues about an integration. For now, User Tasks are only created to register issues related to auto enrolling EC2 instances. Other types of issues will be registered in the future. Users must proactively list User Tasks in order to understand existing issues. For now, this can only be done using `tctl get user_task`. An UI for this new resource will be created, but users still need to navigate to that UI to see what issues exist. This PR creates a new Notification type which is used to explicitly notify the user that the Integration has pending User Tasks. When are users notified about pending User Tasks? When a User Task is created or updated, if its state is OPEN, then a notification is created. Given that we can have dozens of UserTasks for a single integration, we had to ensure only one Notification exists per Integration. To do that, the current Notification ID is stored in the Integration's Status field. This way, when we try to create a new Notification, we ensure the existing one is deleted to prevent showing two (or more) Notifications saying "Your integration needs attention". All of this is protected by a semaphore lock. The DiscoveryService is highly async and multiple UserTasks can be created in parallel, and the locks prevents it.
- Loading branch information
1 parent
904d4f9
commit 3e2803d
Showing
8 changed files
with
1,078 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright 2024 Gravitational, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package notifications | ||
|
||
import ( | ||
"time" | ||
|
||
"google.golang.org/protobuf/types/known/timestamppb" | ||
|
||
headerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1" | ||
notificationsv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/notifications/v1" | ||
"github.com/gravitational/teleport/api/types" | ||
) | ||
|
||
// NewPendingUserTasksIntegrationNotification creates a new GlobalNotification for warning the users about pending UserTasks related to an integration. | ||
func NewPendingUserTasksIntegrationNotification(integrationName string, expires time.Time) *notificationsv1.GlobalNotification { | ||
return ¬ificationsv1.GlobalNotification{ | ||
Spec: ¬ificationsv1.GlobalNotificationSpec{ | ||
Matcher: ¬ificationsv1.GlobalNotificationSpec_ByPermissions{ | ||
ByPermissions: ¬ificationsv1.ByPermissions{ | ||
RoleConditions: []*types.RoleConditions{{ | ||
Rules: []types.Rule{{ | ||
Resources: []string{types.KindIntegration}, | ||
Verbs: []string{types.VerbList, types.VerbRead}, | ||
}}, | ||
}}, | ||
}, | ||
}, | ||
Notification: ¬ificationsv1.Notification{ | ||
Spec: ¬ificationsv1.NotificationSpec{}, | ||
SubKind: types.NotificationPendingUserTaskIntegrationSubKind, | ||
Metadata: &headerv1.Metadata{ | ||
Labels: map[string]string{ | ||
types.NotificationTitleLabel: "Your integration needs attention.", | ||
types.NotificationIntegrationLabel: integrationName, | ||
}, | ||
Expires: timestamppb.New(expires), | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.