Skip to content

Commit

Permalink
rename from user integration task to user task
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoandredinis committed Sep 18, 2024
1 parent ce33251 commit 83228d6
Show file tree
Hide file tree
Showing 34 changed files with 746 additions and 750 deletions.
12 changes: 6 additions & 6 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ import (
"github.com/gravitational/teleport/api/client/scim"
"github.com/gravitational/teleport/api/client/secreport"
statichostuserclient "github.com/gravitational/teleport/api/client/statichostuser"
userintegrationtaskapi "github.com/gravitational/teleport/api/client/userintegrationtask"
"github.com/gravitational/teleport/api/client/userloginstate"
usertaskapi "github.com/gravitational/teleport/api/client/usertask"
"github.com/gravitational/teleport/api/constants"
"github.com/gravitational/teleport/api/defaults"
accesslistv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/accesslist/v1"
Expand All @@ -87,10 +87,10 @@ import (
samlidppb "github.com/gravitational/teleport/api/gen/proto/go/teleport/samlidp/v1"
secreportsv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/secreports/v1"
trustpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/trust/v1"
userintegrationtaskv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/userintegrationtasks/v1"
userloginstatev1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/userloginstate/v1"
userprovisioningpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/userprovisioning/v2"
userspb "github.com/gravitational/teleport/api/gen/proto/go/teleport/users/v1"
usertaskv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/usertasks/v1"
"github.com/gravitational/teleport/api/gen/proto/go/teleport/vnet/v1"
userpreferencespb "github.com/gravitational/teleport/api/gen/proto/go/userpreferences/v1"
"github.com/gravitational/teleport/api/internalutils/stream"
Expand Down Expand Up @@ -4669,12 +4669,12 @@ func (c *Client) UserLoginStateClient() *userloginstate.Client {
return userloginstate.NewClient(userloginstatev1.NewUserLoginStateServiceClient(c.conn))
}

// UserIntegrationTasksServiceClient returns a UserIntegrationTask client.
// Clients connecting to older Teleport versions, still get a UserIntegrationTask client
// UserTasksServiceClient returns a UserTask client.
// Clients connecting to older Teleport versions, still get a UserTask client
// when calling this method, but all RPCs will return "not implemented" errors
// (as per the default gRPC behavior).
func (c *Client) UserIntegrationTasksServiceClient() *userintegrationtaskapi.Client {
return userintegrationtaskapi.NewClient(userintegrationtaskv1.NewUserIntegrationTaskServiceClient(c.conn))
func (c *Client) UserTasksServiceClient() *usertaskapi.Client {
return usertaskapi.NewClient(usertaskv1.NewUserTaskServiceClient(c.conn))
}

// GetCertAuthority retrieves a CA by type and domain.
Expand Down
10 changes: 5 additions & 5 deletions api/client/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
kubewaitingcontainerpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/kubewaitingcontainer/v1"
machineidv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/machineid/v1"
notificationsv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/notifications/v1"
userintegrationtasksv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/userintegrationtasks/v1"
userprovisioningpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/userprovisioning/v2"
usertasksv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/usertasks/v1"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/api/types/accesslist"
accesslistv1conv "github.com/gravitational/teleport/api/types/accesslist/convert/v1"
Expand Down Expand Up @@ -100,9 +100,9 @@ func EventToGRPC(in types.Event) (*proto.Event, error) {
out.Resource = &proto.Event_StaticHostUserV2{
StaticHostUserV2: r,
}
case *userintegrationtasksv1.UserIntegrationTask:
out.Resource = &proto.Event_UserIntegrationTask{
UserIntegrationTask: r,
case *usertasksv1.UserTask:
out.Resource = &proto.Event_UserTask{
UserTask: r,
}
default:
return nil, trace.BadParameter("resource type %T is not supported", r)
Expand Down Expand Up @@ -547,7 +547,7 @@ func EventFromGRPC(in *proto.Event) (*types.Event, error) {
} else if r := in.GetStaticHostUserV2(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else if r := in.GetUserIntegrationTask(); r != nil {
} else if r := in.GetUserTask(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else {
Expand Down
106 changes: 0 additions & 106 deletions api/client/userintegrationtask/userintegrationtask.go

This file was deleted.

106 changes: 106 additions & 0 deletions api/client/usertask/usertask.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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 usertask

import (
"context"

"github.com/gravitational/trace"

usertaskv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/usertasks/v1"
)

// Client is a client for the User Task API.
type Client struct {
grpcClient usertaskv1.UserTaskServiceClient
}

// NewClient creates a new User Task client.
func NewClient(grpcClient usertaskv1.UserTaskServiceClient) *Client {
return &Client{
grpcClient: grpcClient,
}
}

// ListUserTasks returns a list of User Tasks.
func (c *Client) ListUserTasks(ctx context.Context, pageSize int64, nextToken string) ([]*usertaskv1.UserTask, string, error) {
resp, err := c.grpcClient.ListUserTasks(ctx, &usertaskv1.ListUserTasksRequest{
PageSize: pageSize,
PageToken: nextToken,
})
if err != nil {
return nil, "", trace.Wrap(err)
}

return resp.UserTasks, resp.NextPageToken, nil
}

// CreateUserTask creates a new User Task.
func (c *Client) CreateUserTask(ctx context.Context, req *usertaskv1.UserTask) (*usertaskv1.UserTask, error) {
rsp, err := c.grpcClient.CreateUserTask(ctx, &usertaskv1.CreateUserTaskRequest{
UserTask: req,
})
if err != nil {
return nil, trace.Wrap(err)
}
return rsp, nil
}

// GetUserTask returns a User Task by name.
func (c *Client) GetUserTask(ctx context.Context, name string) (*usertaskv1.UserTask, error) {
rsp, err := c.grpcClient.GetUserTask(ctx, &usertaskv1.GetUserTaskRequest{
Name: name,
})
if err != nil {
return nil, trace.Wrap(err)
}
return rsp, nil
}

// UpdateUserTask updates an existing User Task.
func (c *Client) UpdateUserTask(ctx context.Context, req *usertaskv1.UserTask) (*usertaskv1.UserTask, error) {
rsp, err := c.grpcClient.UpdateUserTask(ctx, &usertaskv1.UpdateUserTaskRequest{
UserTask: req,
})
if err != nil {
return nil, trace.Wrap(err)
}
return rsp, nil
}

// UpsertUserTask upserts a User Task.
func (c *Client) UpsertUserTask(ctx context.Context, req *usertaskv1.UserTask) (*usertaskv1.UserTask, error) {
rsp, err := c.grpcClient.UpsertUserTask(ctx, &usertaskv1.UpsertUserTaskRequest{
UserTask: req,
})
if err != nil {
return nil, trace.Wrap(err)
}
return rsp, nil
}

// DeleteUserTask deletes a User Task.
func (c *Client) DeleteUserTask(ctx context.Context, name string) error {
_, err := c.grpcClient.DeleteUserTask(ctx, &usertaskv1.DeleteUserTaskRequest{
Name: name,
})
return trace.Wrap(err)
}

// DeleteAllUserTasks deletes all User Tasks.
// Not implemented. Added to satisfy the interface.
func (c *Client) DeleteAllUserTasks(_ context.Context) error {
return trace.NotImplemented("DeleteAllUserTasks is not implemented")
}
4 changes: 2 additions & 2 deletions api/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ const (
// KindIntegration is a connection to a 3rd party system API.
KindIntegration = "integration"

// KindUserIntegrationTask is a task representing an issue with an integration.
KindUserIntegrationTask = "user_integration_task"
// KindUserTask is a task representing an issue with some other resource.
KindUserTask = "user_task"

// KindClusterMaintenanceConfig determines maintenance times for the cluster.
KindClusterMaintenanceConfig = "cluster_maintenance_config"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,57 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package userintegrationtasks
package usertasks

import (
"github.com/gravitational/trace"

headerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1"
userintegrationtasksv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/userintegrationtasks/v1"
usertasksv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/usertasks/v1"
"github.com/gravitational/teleport/api/types"
)

// NewUserIntegrationTask creates a new UserIntegrationTask object.
// NewUserTask creates a new UserTask object.
// It validates the object before returning it.
func NewUserIntegrationTask(name string, spec *userintegrationtasksv1.UserIntegrationTaskSpec) (*userintegrationtasksv1.UserIntegrationTask, error) {
cj := &userintegrationtasksv1.UserIntegrationTask{
Kind: types.KindUserIntegrationTask,
func NewUserTask(name string, spec *usertasksv1.UserTaskSpec) (*usertasksv1.UserTask, error) {
cj := &usertasksv1.UserTask{
Kind: types.KindUserTask,
Version: types.V1,
Metadata: &headerv1.Metadata{
Name: name,
},
Spec: spec,
}

if err := ValidateUserIntegrationTask(cj); err != nil {
if err := ValidateUserTask(cj); err != nil {
return nil, trace.Wrap(err)
}

return cj, nil
}

const (
// TaskTypeDiscoverEC2 identifies a User Integration Tasks that is created
// TaskTypeDiscoverEC2 identifies a User Tasks that is created
// when an auto-enrollment of an EC2 instance fails.
// UserIntegrationTasks that have this Task Type must include the DiscoverEC2 field.
// UserTasks that have this Task Type must include the DiscoverEC2 field.
TaskTypeDiscoverEC2 = "discover-ec2"
)

// ValidateUserIntegrationTask validates the UserIntegrationTask object without modifying it.
func ValidateUserIntegrationTask(uit *userintegrationtasksv1.UserIntegrationTask) error {
// ValidateUserTask validates the UserTask object without modifying it.
func ValidateUserTask(uit *usertasksv1.UserTask) error {
switch {
case uit.GetKind() != types.KindUserIntegrationTask:
case uit.GetKind() != types.KindUserTask:
return trace.BadParameter("invalid kind")
case uit.GetVersion() != types.V1:
return trace.BadParameter("invalid version")
case uit.GetSubKind() != "":
return trace.BadParameter("invalid sub kind, must be empty")
case uit.GetMetadata() == nil:
return trace.BadParameter("user integration task metadata is nil")
return trace.BadParameter("user task metadata is nil")
case uit.Metadata.GetName() == "":
return trace.BadParameter("user integration task name is empty")
return trace.BadParameter("user task name is empty")
case uit.GetSpec() == nil:
return trace.BadParameter("user integration task spec is nil")
return trace.BadParameter("user task spec is nil")
case uit.GetSpec().Integration == "":
return trace.BadParameter("integration is required")
}
Expand All @@ -83,7 +83,7 @@ func ValidateUserIntegrationTask(uit *userintegrationtasksv1.UserIntegrationTask
return nil
}

func validateDiscoverEC2TaskType(uit *userintegrationtasksv1.UserIntegrationTask) error {
func validateDiscoverEC2TaskType(uit *usertasksv1.UserTask) error {
if uit.Spec.DiscoverEc2 == nil {
return trace.BadParameter("%s requires the discover_ec2 field", TaskTypeDiscoverEC2)
}
Expand Down
Loading

0 comments on commit 83228d6

Please sign in to comment.