diff --git a/client/client.go b/client/client.go index b46ae33..92f3aeb 100644 --- a/client/client.go +++ b/client/client.go @@ -14,6 +14,7 @@ import ( "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/keepalive" + "google.golang.org/grpc/metadata" ) // Config holds configuration for the client connection. @@ -104,9 +105,22 @@ func (c *Client) CheckAndReconnect() error { return nil } +func attachAuthHeaders(ctx context.Context, auth *gen.Auth) context.Context { + md := metadata.Pairs() + if auth != nil { + if auth.AuthToken != nil && *auth.AuthToken != "" { + md.Set("Authorization", "Bearer "+*auth.AuthToken) + } + if auth.WorkspaceToken != nil && *auth.WorkspaceToken != "" { + md.Set("x-workspace-token", "Bearer "+*auth.WorkspaceToken) + } + } + + return metadata.NewOutgoingContext(ctx, md) +} + // SendCommands sends a list of commands to the server func (c *Client) SendCommands(commands []*gen.Command, auth *gen.Auth) error { - if err := c.CheckAndReconnect(); err != nil { return fmt.Errorf("failed to reconnect: %w", err) } @@ -121,6 +135,7 @@ func (c *Client) SendCommands(commands []*gen.Command, auth *gen.Auth) error { ctx, cancel := context.WithTimeout(context.Background(), c.timeout) defer cancel() + ctx = attachAuthHeaders(ctx, auth) _, err := client.SendCommands(ctx, req) if err != nil { c.logger.Error().Err(err).Msg("Failed to send commands") @@ -131,7 +146,6 @@ func (c *Client) SendCommands(commands []*gen.Command, auth *gen.Auth) error { // SendProcesses sends a list of processes to the server func (c *Client) SendProcesses(processes []*gen.Process, auth *gen.Auth) error { - if err := c.CheckAndReconnect(); err != nil { return fmt.Errorf("failed to reconnect: %w", err) } @@ -146,6 +160,7 @@ func (c *Client) SendProcesses(processes []*gen.Process, auth *gen.Auth) error { ctx, cancel := context.WithTimeout(context.Background(), c.timeout) defer cancel() + ctx = attachAuthHeaders(ctx, auth) _, err := client.SendProcesses(ctx, req) if err != nil { c.logger.Error().Err(err).Msg("Failed to send processes") diff --git a/collector/collector.go b/collector/collector.go index e8f3ee8..8b2144d 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" "sync" + "time" "github.com/devzero-inc/oda/client" gen "github.com/devzero-inc/oda/gen/api/v1" @@ -14,8 +15,6 @@ import ( "github.com/devzero-inc/oda/util" "github.com/rs/zerolog" - - "time" ) // TODO move this to /var/run or other appropriate location based on OS, @@ -46,10 +45,12 @@ type IntervalConfig struct { // AuthConfig contains the configuration for the command processing and authentication type AuthConfig struct { - TeamID string - UserID string - WorkspaceID string - UserEmail string + TeamID string + UserID string + WorkspaceID string + UserEmail string + AuthToken string + WorkspaceToken string } // collectionConfig contains the configuration for the collection process @@ -72,7 +73,6 @@ type collectionConfig struct { // NewCollector creates a new collector instance func NewCollector(socketPath string, client *client.Client, logger zerolog.Logger, config IntervalConfig, auth AuthConfig, excludeRegex string, excludeCommands []string, process process.SystemProcess) *Collector { - collector := &Collector{ socketPath: socketPath, client: client, @@ -93,6 +93,7 @@ func NewCollector(socketPath string, client *client.Client, logger zerolog.Logge TeamId: auth.TeamID, WorkspaceId: &auth.WorkspaceID, UserEmail: auth.UserEmail, + AuthToken: &auth.AuthToken, } } @@ -155,7 +156,6 @@ func (c *Collector) collectSystemInformation(ctx context.Context, initialDuratio } func (c *Collector) collectOnce() error { - c.logger.Debug().Msg("Collecting process") processes, err := c.collectionConfig.process.Collect() @@ -171,7 +171,6 @@ func (c *Collector) collectOnce() error { if c.client != nil { var processMetrics []*gen.Process for _, p := range processes { - processMetrics = append( processMetrics, process.MapProcessToProto(p), @@ -201,8 +200,7 @@ func (c *Collector) onStartCommand() { // If the collection is not running, start it with a timeout if !c.collectionConfig.isCollectionRunning { c.logger.Debug().Msg("Starting collection") - c.collectionConfig.collectionContext, c.collectionConfig.collectionCancelFunc = - context.WithTimeout(context.Background(), c.intervalConfig.MaxDuration) + c.collectionConfig.collectionContext, c.collectionConfig.collectionCancelFunc = context.WithTimeout(context.Background(), c.intervalConfig.MaxDuration) go c.collectSystemInformation( c.collectionConfig.collectionContext, c.intervalConfig.CommandInterval, @@ -344,7 +342,6 @@ func (c *Collector) handleStartCommand(parts []string) error { } func (c *Collector) handleEndCommand(parts []string) error { - if !IsCommandAcceptable(parts[1], c.excludeRegex, c.excludeCommands) { c.logger.Debug().Msg("Command is not acceptable") return fmt.Errorf("command is not acceptable") diff --git a/gen/api/v1/collector.pb.go b/gen/api/v1/collector.pb.go index 6d66463..aecdaa9 100644 --- a/gen/api/v1/collector.pb.go +++ b/gen/api/v1/collector.pb.go @@ -7,12 +7,11 @@ package gen import ( - reflect "reflect" - sync "sync" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" ) const ( @@ -28,10 +27,12 @@ type Auth struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // Unique identifer for user that is processing the data - TeamId string `protobuf:"bytes,2,opt,name=team_id,json=teamId,proto3" json:"team_id,omitempty"` // Unique identifier for users team - WorkspaceId *string `protobuf:"bytes,3,opt,name=workspace_id,json=workspaceId,proto3,oneof" json:"workspace_id,omitempty"` // Unique identifier of the Workspace that is running the request - UserEmail string `protobuf:"bytes,4,opt,name=user_email,json=userEmail,proto3" json:"user_email,omitempty"` // Unique identifier of user that is processing the data + UserId string `protobuf:"bytes,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // Unique identifer for user that is processing the data + TeamId string `protobuf:"bytes,2,opt,name=team_id,json=teamId,proto3" json:"team_id,omitempty"` // Unique identifier for users team + WorkspaceId *string `protobuf:"bytes,3,opt,name=workspace_id,json=workspaceId,proto3,oneof" json:"workspace_id,omitempty"` // Unique identifier of the Workspace that is running the request + UserEmail string `protobuf:"bytes,4,opt,name=user_email,json=userEmail,proto3" json:"user_email,omitempty"` // Unique identifier of user that is processing the data + AuthToken *string `protobuf:"bytes,5,opt,name=auth_token,json=authToken,proto3,oneof" json:"auth_token,omitempty"` + WorkspaceToken *string `protobuf:"bytes,6,opt,name=workspace_token,json=workspaceToken,proto3,oneof" json:"workspace_token,omitempty"` } func (x *Auth) Reset() { @@ -94,7 +95,22 @@ func (x *Auth) GetUserEmail() string { return "" } -// Define a message representing a command, including its metadata and timing information. +func (x *Auth) GetAuthToken() string { + if x != nil && x.AuthToken != nil { + return *x.AuthToken + } + return "" +} + +func (x *Auth) GetWorkspaceToken() string { + if x != nil && x.WorkspaceToken != nil { + return *x.WorkspaceToken + } + return "" +} + +// Define a message representing a command, including its metadata and timing +// information. type Command struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -230,7 +246,8 @@ func (x *Command) GetPid() int64 { return 0 } -// Define a message representing a process, including its metadata and resource usage. +// Define a message representing a process, including its metadata and resource +// usage. type Process struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -484,7 +501,7 @@ var file_api_v1_collector_proto_rawDesc = []byte{ 0x0a, 0x16, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x90, 0x01, + 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x85, 0x02, 0x0a, 0x04, 0x41, 0x75, 0x74, 0x68, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x65, 0x61, 0x6d, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, @@ -492,78 +509,86 @@ var file_api_v1_collector_proto_rawDesc = []byte{ 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x42, - 0x0f, 0x0a, 0x0d, 0x5f, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, - 0x22, 0xc4, 0x02, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x0e, 0x0a, 0x02, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, - 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, - 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, - 0x61, 0x6e, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, - 0x6e, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, - 0x6f, 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, - 0x74, 0x6f, 0x72, 0x79, 0x12, 0x25, 0x0a, 0x0e, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, - 0x6e, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x65, 0x78, - 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x73, - 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x6e, - 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x65, 0x6e, - 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, - 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x16, 0x0a, - 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, - 0x6f, 0x72, 0x79, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, 0x65, 0x70, 0x6f, 0x73, - 0x69, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x70, 0x69, 0x64, 0x18, 0x0c, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x03, 0x70, 0x69, 0x64, 0x22, 0xc4, 0x02, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x63, - 0x65, 0x73, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x70, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x03, 0x70, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, - 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, - 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x5f, 0x74, - 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x73, 0x74, 0x6f, 0x72, 0x65, - 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x02, 0x6f, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, - 0x6d, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, - 0x6d, 0x12, 0x27, 0x0a, 0x0f, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x5f, 0x66, 0x61, - 0x6d, 0x69, 0x6c, 0x79, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x70, 0x6c, 0x61, 0x74, - 0x66, 0x6f, 0x72, 0x6d, 0x46, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x70, - 0x75, 0x5f, 0x75, 0x73, 0x61, 0x67, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x01, 0x52, 0x08, 0x63, - 0x70, 0x75, 0x55, 0x73, 0x61, 0x67, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x65, 0x6d, 0x6f, 0x72, - 0x79, 0x5f, 0x75, 0x73, 0x61, 0x67, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0b, 0x6d, - 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x55, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x70, - 0x69, 0x64, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x70, 0x70, 0x69, 0x64, 0x22, 0x72, - 0x0a, 0x13, 0x53, 0x65, 0x6e, 0x64, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2b, 0x0a, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, - 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, - 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, - 0x64, 0x73, 0x12, 0x25, 0x0a, 0x04, 0x61, 0x75, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x0c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x48, 0x00, - 0x52, 0x04, 0x61, 0x75, 0x74, 0x68, 0x88, 0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x61, 0x75, - 0x74, 0x68, 0x22, 0x75, 0x0a, 0x14, 0x53, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, - 0x73, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2d, 0x0a, 0x09, 0x70, 0x72, - 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x52, 0x09, - 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x25, 0x0a, 0x04, 0x61, 0x75, 0x74, - 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, - 0x2e, 0x41, 0x75, 0x74, 0x68, 0x48, 0x00, 0x52, 0x04, 0x61, 0x75, 0x74, 0x68, 0x88, 0x01, 0x01, - 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x61, 0x75, 0x74, 0x68, 0x32, 0x9e, 0x01, 0x0a, 0x10, 0x43, 0x6f, - 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x43, - 0x0a, 0x0c, 0x53, 0x65, 0x6e, 0x64, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x12, 0x1b, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x43, 0x6f, 0x6d, 0x6d, - 0x61, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x12, 0x45, 0x0a, 0x0d, 0x53, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x63, 0x65, - 0x73, 0x73, 0x65, 0x73, 0x12, 0x1c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, - 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x39, 0x0a, 0x0a, 0x67, 0x65, - 0x6e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x50, 0x01, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x65, 0x76, 0x7a, 0x65, 0x72, 0x6f, 0x2d, 0x69, - 0x6e, 0x63, 0x2f, 0x6f, 0x64, 0x61, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, - 0x31, 0x3b, 0x67, 0x65, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, + 0x22, 0x0a, 0x0a, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, + 0x88, 0x01, 0x01, 0x12, 0x2c, 0x0a, 0x0f, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, + 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x02, 0x52, 0x0e, + 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x88, 0x01, + 0x01, 0x42, 0x0f, 0x0a, 0x0d, 0x5f, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, + 0x69, 0x64, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x42, 0x12, 0x0a, 0x10, 0x5f, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0xc4, 0x02, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, + 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, + 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, 0x18, 0x0a, + 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x64, + 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x25, 0x0a, 0x0e, 0x65, 0x78, 0x65, + 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x0d, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65, + 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x07, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, + 0x19, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x07, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, + 0x6c, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0a, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x65, + 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x70, 0x69, + 0x64, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x70, 0x69, 0x64, 0x22, 0xc4, 0x02, 0x0a, + 0x07, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x70, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x70, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, + 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x63, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x6f, + 0x72, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, + 0x73, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x73, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x6f, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, + 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, + 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x27, 0x0a, 0x0f, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, + 0x72, 0x6d, 0x5f, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0e, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x46, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x12, + 0x1b, 0x0a, 0x09, 0x63, 0x70, 0x75, 0x5f, 0x75, 0x73, 0x61, 0x67, 0x65, 0x18, 0x0a, 0x20, 0x01, + 0x28, 0x01, 0x52, 0x08, 0x63, 0x70, 0x75, 0x55, 0x73, 0x61, 0x67, 0x65, 0x12, 0x21, 0x0a, 0x0c, + 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x5f, 0x75, 0x73, 0x61, 0x67, 0x65, 0x18, 0x0b, 0x20, 0x01, + 0x28, 0x01, 0x52, 0x0b, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x55, 0x73, 0x61, 0x67, 0x65, 0x12, + 0x12, 0x0a, 0x04, 0x70, 0x70, 0x69, 0x64, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x70, + 0x70, 0x69, 0x64, 0x22, 0x72, 0x0a, 0x13, 0x53, 0x65, 0x6e, 0x64, 0x43, 0x6f, 0x6d, 0x6d, 0x61, + 0x6e, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2b, 0x0a, 0x08, 0x63, 0x6f, + 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x08, 0x63, + 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x12, 0x25, 0x0a, 0x04, 0x61, 0x75, 0x74, 0x68, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x41, + 0x75, 0x74, 0x68, 0x48, 0x00, 0x52, 0x04, 0x61, 0x75, 0x74, 0x68, 0x88, 0x01, 0x01, 0x42, 0x07, + 0x0a, 0x05, 0x5f, 0x61, 0x75, 0x74, 0x68, 0x22, 0x75, 0x0a, 0x14, 0x53, 0x65, 0x6e, 0x64, 0x50, + 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x2d, 0x0a, 0x09, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x63, + 0x65, 0x73, 0x73, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x25, + 0x0a, 0x04, 0x61, 0x75, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x48, 0x00, 0x52, 0x04, 0x61, 0x75, + 0x74, 0x68, 0x88, 0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x61, 0x75, 0x74, 0x68, 0x32, 0x9e, + 0x01, 0x0a, 0x10, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x43, 0x0a, 0x0c, 0x53, 0x65, 0x6e, 0x64, 0x43, 0x6f, 0x6d, 0x6d, 0x61, + 0x6e, 0x64, 0x73, 0x12, 0x1b, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x6e, + 0x64, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x45, 0x0a, 0x0d, 0x53, 0x65, 0x6e, 0x64, + 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x1c, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x76, 0x31, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, + 0x39, 0x0a, 0x0a, 0x67, 0x65, 0x6e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x50, 0x01, 0x5a, + 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x65, 0x76, 0x7a, + 0x65, 0x72, 0x6f, 0x2d, 0x69, 0x6e, 0x63, 0x2f, 0x6f, 0x64, 0x61, 0x2f, 0x67, 0x65, 0x6e, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x67, 0x65, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/gen/api/v1/collector_grpc.pb.go b/gen/api/v1/collector_grpc.pb.go index 7707074..914435a 100644 --- a/gen/api/v1/collector_grpc.pb.go +++ b/gen/api/v1/collector_grpc.pb.go @@ -8,7 +8,6 @@ package gen import ( context "context" - grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" diff --git a/gen/api/v1/genconnect/collector.connect.go b/gen/api/v1/genconnect/collector.connect.go index 5884efb..433533b 100644 --- a/gen/api/v1/genconnect/collector.connect.go +++ b/gen/api/v1/genconnect/collector.connect.go @@ -5,14 +5,13 @@ package genconnect import ( + connect "connectrpc.com/connect" context "context" errors "errors" - http "net/http" - strings "strings" - - connect "connectrpc.com/connect" v1 "github.com/devzero-inc/oda/gen/api/v1" emptypb "google.golang.org/protobuf/types/known/emptypb" + http "net/http" + strings "strings" ) // This is a compile-time assertion to ensure that this generated file and the connect package are diff --git a/proto/api/v1/collector.proto b/proto/api/v1/collector.proto index a0053b3..6b142e8 100644 --- a/proto/api/v1/collector.proto +++ b/proto/api/v1/collector.proto @@ -10,59 +10,70 @@ option java_package = "gen.api.v1"; // Define a message representing an auth information about user and team. message Auth { - string user_id = 1; // Unique identifer for user that is processing the data - string team_id = 2; // Unique identifier for users team - optional string workspace_id = 3; // Unique identifier of the Workspace that is running the request - string user_email = 4; // Unique identifier of user that is processing the data + string user_id = 1; // Unique identifer for user that is processing the data + string team_id = 2; // Unique identifier for users team + optional string workspace_id = + 3; // Unique identifier of the Workspace that is running the request + string user_email = + 4; // Unique identifier of user that is processing the data + optional string auth_token = 5; + optional string workspace_token = 6; } -// Define a message representing a command, including its metadata and timing information. +// Define a message representing a command, including its metadata and timing +// information. message Command { - int64 id = 1; // Unique identifier for the command. - string category = 2; // Category of the command (e.g., system, user). - string command = 3; // The actual command string. - string user = 4; // The user who executed the command. - string directory = 5; // The directory from which the command was executed. - int64 execution_time = 6; // Execution time of the command in milliseconds. - int64 start_time = 7; // Start time of the command execution (Unix timestamp). - int64 end_time = 8; // End time of the command execution (Unix timestamp). - string result = 9; // Result of executed command => success/failure - string status = 10; // Status of executed command - string repository = 11; // Repository is repository where commands are executed - int64 pid = 12; // PID of the command + int64 id = 1; // Unique identifier for the command. + string category = 2; // Category of the command (e.g., system, user). + string command = 3; // The actual command string. + string user = 4; // The user who executed the command. + string directory = 5; // The directory from which the command was executed. + int64 execution_time = 6; // Execution time of the command in milliseconds. + int64 start_time = + 7; // Start time of the command execution (Unix timestamp). + int64 end_time = 8; // End time of the command execution (Unix timestamp). + string result = 9; // Result of executed command => success/failure + string status = 10; // Status of executed command + string repository = + 11; // Repository is repository where commands are executed + int64 pid = 12; // PID of the command } -// Define a message representing a process, including its metadata and resource usage. +// Define a message representing a process, including its metadata and resource +// usage. message Process { - int64 id = 1; // Unique identifier for the process. - int64 pid = 2; // Process ID. - string name = 3; // Process name. - string status = 4; // Current status of the process (e.g., running, sleeping). - int64 created_time = 5; // Creation time of the process (Unix timestamp). - int64 stored_time = 6; // Time at which the process information was stored (Unix timestamp). - string os = 7; // Operating system the process is running on. - string platform = 8; // Platform information (e.g., Linux, Windows). - string platform_family = 9; // More detailed platform family information. - double cpu_usage = 10; // CPU usage percentage by the process. - double memory_usage = 11; // Memory usage by the process in megabytes. - int64 ppid = 12; // Parent process ID. + int64 id = 1; // Unique identifier for the process. + int64 pid = 2; // Process ID. + string name = 3; // Process name. + string status = + 4; // Current status of the process (e.g., running, sleeping). + int64 created_time = 5; // Creation time of the process (Unix timestamp). + int64 stored_time = + 6; // Time at which the process information was stored (Unix timestamp). + string os = 7; // Operating system the process is running on. + string platform = 8; // Platform information (e.g., Linux, Windows). + string platform_family = 9; // More detailed platform family information. + double cpu_usage = 10; // CPU usage percentage by the process. + double memory_usage = 11; // Memory usage by the process in megabytes. + int64 ppid = 12; // Parent process ID. } // Requests to send collections of commands and processes. // Defines a request for sending a collection of commands. message SendCommandsRequest { - repeated Command commands = 1; // A list of commands. - optional Auth auth = 2; // Optional auth configuration + repeated Command commands = 1; // A list of commands. + optional Auth auth = 2; // Optional auth configuration } // Defines a request for sending a collection of processes. message SendProcessesRequest { - repeated Process processes = 1; // A list of processes. - optional Auth auth = 2; // Optional auth configuration + repeated Process processes = 1; // A list of processes. + optional Auth auth = 2; // Optional auth configuration } -// Defines the service that provides RPC methods for sending command and process collections. +// Defines the service that provides RPC methods for sending command and process +// collections. service CollectorService { // RPC method for sending command data. rpc SendCommands(SendCommandsRequest) returns (google.protobuf.Empty); diff --git a/user/user.go b/user/user.go index c5690c3..c147459 100644 --- a/user/user.go +++ b/user/user.go @@ -284,17 +284,19 @@ func GetStoragePath(os config.OSType, home string) (string, error) { // ReadDZWorkspaceConfig reads the DevZero workspace configuration func ReadDZWorkspaceConfig() (collector.AuthConfig, error) { const ( - devzeroConfigPath = "/etc/devzero/configs" - devzeroTeamFile = "DEVZERO_TEAM_ID" - devzeroUserFile = "DEVZERO_USER_ID" - devzeroWorkspaceFile = "DEVZERO_WORKSPACE_ID" - devzeroEmailFile = "DEVZERO_WORKSPACE_OWNER_EMAIL" + devzeroConfigPath = "/etc/devzero/configs" + devzeroTeamFile = "DEVZERO_TEAM_ID" + devzeroUserFile = "DEVZERO_USER_ID" + devzeroWorkspaceFile = "DEVZERO_WORKSPACE_ID" + devzeroEmailFile = "DEVZERO_WORKSPACE_OWNER_EMAIL" + devzeroWorkspaceTokenFile = "WORKSPACE_TOKEN" ) userId := "" userEmail := "" teamId := "" workspaceId := "" + workspaceToken := "" teamPath := filepath.Join(devzeroConfigPath, devzeroTeamFile) if util.FileExists(teamPath) { @@ -328,11 +330,20 @@ func ReadDZWorkspaceConfig() (collector.AuthConfig, error) { } } + workspaceTokenPath := filepath.Join(devzeroConfigPath, devzeroWorkspaceTokenFile) + if util.FileExists(workspaceTokenPath) { + data, err := os.ReadFile(workspaceTokenPath) + if err == nil && len(data) > 0 { + workspaceToken = string(data) + } + } + return collector.AuthConfig{ - UserID: userId, - TeamID: teamId, - WorkspaceID: workspaceId, - UserEmail: userEmail, + UserID: userId, + TeamID: teamId, + WorkspaceID: workspaceId, + UserEmail: userEmail, + WorkspaceToken: workspaceToken, }, nil } @@ -348,6 +359,7 @@ func ReadDZCliConfig(path string) (collector.AuthConfig, error) { userId := "" teamId := "" userEmail := "" + authToken := "" localUserPath := filepath.Join(path, localUserFile) if util.FileExists(localUserPath) { @@ -382,11 +394,11 @@ func ReadDZCliConfig(path string) (collector.AuthConfig, error) { return collector.AuthConfig{}, err } + authToken = token.AccessToken + var claims CustomClaims // Parse and verify the token _, _, err := new(jwt.Parser).ParseUnverified(token.AccessToken, &claims) - if err != nil { - } if err != nil { return collector.AuthConfig{}, err } @@ -395,7 +407,6 @@ func ReadDZCliConfig(path string) (collector.AuthConfig, error) { userEmail = claims.Email teamId = claims.TeamID } - } } @@ -403,5 +414,6 @@ func ReadDZCliConfig(path string) (collector.AuthConfig, error) { UserID: userId, TeamID: teamId, UserEmail: userEmail, + AuthToken: authToken, }, nil }