Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add running user in debug upload request, unexport flare env type #1400

Merged
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
10 changes: 5 additions & 5 deletions pkg/debug/checkups/checkups.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ func RunDoctor(ctx context.Context, k types.Knapsack, w io.Writer) {
}
}

type RuntimeEnvironmentType string
type runtimeEnvironmentType string

const (
StandaloneEnviroment RuntimeEnvironmentType = "standalone"
InSituEnvironment RuntimeEnvironmentType = "in situ"
StandaloneEnviroment runtimeEnvironmentType = "standalone"
InSituEnvironment runtimeEnvironmentType = "in situ"
)

func RunFlare(ctx context.Context, k types.Knapsack, flareStream io.WriteCloser, runtimeEnvironment RuntimeEnvironmentType) error {
func RunFlare(ctx context.Context, k types.Knapsack, flareStream io.WriteCloser, runtimeEnvironment runtimeEnvironmentType) error {
flare := zip.NewWriter(flareStream)
combinedSummary := bytes.Buffer{}

Expand Down Expand Up @@ -303,7 +303,7 @@ func RunFlare(ctx context.Context, k types.Knapsack, flareStream io.WriteCloser,
return close()
}

func writeFlareEnv(z *zip.Writer, runtimeEnvironment RuntimeEnvironmentType) error {
func writeFlareEnv(z *zip.Writer, runtimeEnvironment runtimeEnvironmentType) error {
if _, err := z.Create(fmt.Sprintf("FLARE_RUNNING_%s", strings.ReplaceAll(strings.ToUpper(string(runtimeEnvironment)), " ", "_"))); err != nil {
return fmt.Errorf("making env note file: %s", err)
}
Expand Down
25 changes: 17 additions & 8 deletions pkg/debug/shipper/shipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"net/http"
"net/url"
"os"
"os/user"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -204,30 +205,38 @@ func launcherData(k types.Knapsack, note string) ([]byte, error) {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()

usernames := ""
var consoleUsers string
foundConsoleUsers, err := consoleuser.CurrentUsers(ctx)

switch {
case err != nil:
usernames = fmt.Sprintf("error getting current users: %s", err)
consoleUsers = fmt.Sprintf("error getting console users: %s", err)
case len(foundConsoleUsers) == 0:
usernames = "no console users found"
consoleUsers = "no console users found"
default:
currentUserNames := make([]string, len(foundConsoleUsers))
consoleUserNames := make([]string, len(foundConsoleUsers))
for i, u := range foundConsoleUsers {
currentUserNames[i] = u.Username
consoleUserNames[i] = u.Username
}
usernames = strings.Join(currentUserNames, ", ")
consoleUsers = strings.Join(consoleUserNames, ", ")
}

hostname, err := os.Hostname()
if err != nil {
hostname = fmt.Sprintf("error getting hostname: %s", err)
}

runningUser, err := user.Current()
var runningUsername string
if err != nil {
runningUsername = fmt.Sprintf("error getting running user: %s", err)
} else {
runningUsername = runningUser.Username
}

b, err := json.Marshal(map[string]string{
"enroll_secret": enrollSecret(k),
"usernames": usernames,
"console_users": consoleUsers,
"running_user": runningUsername,
"hostname": hostname,
"note": note,
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/debug/shipper/shipper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ func TestShip(t *testing.T) { //nolint:paralleltest

require.Equal(t, tt.expectSecret, len(data["enroll_secret"]) > 0)
require.NotEmpty(t, data["hostname"])
require.NotEmpty(t, data["usernames"])
require.NotEmpty(t, data["note"])
require.NotEmpty(t, data["console_users"])
require.NotEmpty(t, data["running_user"])
urlData := struct {
URL string
}{
Expand Down
Loading