mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-12 02:15:01 +00:00
plugins: expand PluginStatusV1 to include runtime status details (#42962)
* plugins: expand `PluginStatusV1` to include runtime status details This PR extends Teleport PluginStatusV1 to include details about the status of the runtime status of a plugin. These details include: - error message - last sync time - number of objects imported in gitlab Signed-off-by: Tiago Silva <[email protected]> * fix field refs --------- Signed-off-by: Tiago Silva <[email protected]>
This commit is contained in:
@@ -6086,6 +6086,28 @@ message PluginOAuth2AuthorizationCodeCredentials {
|
||||
// PluginStatus is the user-facing status for the plugin instance.
|
||||
message PluginStatusV1 {
|
||||
PluginStatusCode code = 1;
|
||||
// error_message is a human-readable error message that can be displayed to the user.
|
||||
string error_message = 2;
|
||||
// last_sync_time is the last time the plugin was run.
|
||||
google.protobuf.Timestamp last_sync_time = 3 [
|
||||
(gogoproto.stdtime) = true,
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
// details contains provider-specific plugin status details.
|
||||
oneof details {
|
||||
// gitlab is the status details for the Gitlab plugin.
|
||||
PluginGitlabStatusV1 gitlab = 4;
|
||||
}
|
||||
}
|
||||
|
||||
// PluginGitlabStatusV1 is the status details for the Gitlab plugin.
|
||||
message PluginGitlabStatusV1 {
|
||||
// imported_users is the number of users imported from Gitlab.
|
||||
uint32 imported_users = 1;
|
||||
// imported_groups is the number of groups imported from Gitlab.
|
||||
uint32 imported_groups = 2;
|
||||
// imported_projects is the number of projects imported from Gitlab.
|
||||
uint32 imported_projects = 3;
|
||||
}
|
||||
|
||||
enum PluginStatusCode {
|
||||
|
||||
+20
-4
@@ -113,6 +113,9 @@ type PluginCredentials interface {
|
||||
// PluginStatus is the plugin status
|
||||
type PluginStatus interface {
|
||||
GetCode() PluginStatusCode
|
||||
GetErrorMessage() string
|
||||
GetLastSyncTime() time.Time
|
||||
GetGitlab() *PluginGitlabStatusV1
|
||||
}
|
||||
|
||||
// NewPluginV1 creates a new PluginV1 resource.
|
||||
@@ -427,7 +430,7 @@ func (p *PluginV1) SetCredentials(creds PluginCredentials) error {
|
||||
|
||||
// GetStatus implements Plugin
|
||||
func (p *PluginV1) GetStatus() PluginStatus {
|
||||
return p.Status
|
||||
return &p.Status
|
||||
}
|
||||
|
||||
// SetStatus implements Plugin
|
||||
@@ -436,10 +439,13 @@ func (p *PluginV1) SetStatus(status PluginStatus) error {
|
||||
p.Status = PluginStatusV1{}
|
||||
return nil
|
||||
}
|
||||
p.Status = PluginStatusV1{
|
||||
Code: status.GetCode(),
|
||||
switch status := status.(type) {
|
||||
case *PluginStatusV1:
|
||||
p.Status = *status
|
||||
return nil
|
||||
default:
|
||||
return trace.BadParameter("unsupported plugin status type %T", status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetGeneration returns the plugin generation.
|
||||
@@ -658,6 +664,16 @@ func (c PluginStatusV1) GetCode() PluginStatusCode {
|
||||
return c.Code
|
||||
}
|
||||
|
||||
// GetErrorMessage returns the error message
|
||||
func (c PluginStatusV1) GetErrorMessage() string {
|
||||
return c.ErrorMessage
|
||||
}
|
||||
|
||||
// GetLastSyncTime returns the last run of the plugin.
|
||||
func (c PluginStatusV1) GetLastSyncTime() time.Time {
|
||||
return c.LastSyncTime
|
||||
}
|
||||
|
||||
// CheckAndSetDefaults checks that the required fields for the Gitlab plugin are set.
|
||||
func (c *PluginGitlabSettings) Validate() error {
|
||||
if c.ApiEndpoint == "" {
|
||||
|
||||
+2149
-1716
File diff suppressed because it is too large
Load Diff
@@ -97,7 +97,7 @@ func TestPluginsCRUD(t *testing.T) {
|
||||
require.IsType(t, trace.AlreadyExists(""), err)
|
||||
|
||||
// Set plugin status.
|
||||
status := types.PluginStatusV1{
|
||||
status := &types.PluginStatusV1{
|
||||
Code: types.PluginStatusCode_OTHER_ERROR,
|
||||
}
|
||||
err = service.SetPluginStatus(ctx, plugin1.GetName(), status)
|
||||
|
||||
Reference in New Issue
Block a user