Skip to content

Commit 33c9d34

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevenmasley/rego_to_sql
2 parents 7cfad87 + 028a4ed commit 33c9d34

File tree

6 files changed

+59
-14
lines changed

6 files changed

+59
-14
lines changed

cli/cliui/table.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
6767
}
6868

6969
// Get the list of table column headers.
70-
headersRaw, err := typeToTableHeaders(v.Type().Elem())
70+
headersRaw, err := TypeToTableHeaders(v.Type().Elem())
7171
if err != nil {
7272
return "", xerrors.Errorf("get table headers recursively for type %q: %w", v.Type().Elem().String(), err)
7373
}
@@ -207,10 +207,10 @@ func isStructOrStructPointer(t reflect.Type) bool {
207207
return t.Kind() == reflect.Struct || (t.Kind() == reflect.Pointer && t.Elem().Kind() == reflect.Struct)
208208
}
209209

210-
// typeToTableHeaders converts a type to a slice of column names. If the given
210+
// TypeToTableHeaders converts a type to a slice of column names. If the given
211211
// type is invalid (not a struct or a pointer to a struct, has invalid table
212212
// tags, etc.), an error is returned.
213-
func typeToTableHeaders(t reflect.Type) ([]string, error) {
213+
func TypeToTableHeaders(t reflect.Type) ([]string, error) {
214214
if !isStructOrStructPointer(t) {
215215
return nil, xerrors.Errorf("typeToTableHeaders called with a non-struct or a non-pointer-to-a-struct type")
216216
}
@@ -235,7 +235,7 @@ func typeToTableHeaders(t reflect.Type) ([]string, error) {
235235
return nil, xerrors.Errorf("field %q in type %q is marked as recursive but does not contain a struct or a pointer to a struct", field.Name, t.String())
236236
}
237237

238-
childNames, err := typeToTableHeaders(fieldType)
238+
childNames, err := TypeToTableHeaders(fieldType)
239239
if err != nil {
240240
return nil, xerrors.Errorf("get child field header names for field %q in type %q: %w", field.Name, fieldType.String(), err)
241241
}

cli/list.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cli
22

33
import (
44
"fmt"
5+
"reflect"
6+
"strings"
57
"time"
68

79
"github.com/google/uuid"
@@ -58,10 +60,12 @@ func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]coders
5860

5961
func list() *cobra.Command {
6062
var (
61-
all bool
62-
columns []string
63-
defaultQuery = "owner:me"
64-
searchQuery string
63+
all bool
64+
columns []string
65+
defaultQuery = "owner:me"
66+
searchQuery string
67+
me bool
68+
displayWorkspaces []workspaceListRow
6569
)
6670
cmd := &cobra.Command{
6771
Annotations: workspaceCommand,
@@ -80,6 +84,14 @@ func list() *cobra.Command {
8084
if all && searchQuery == defaultQuery {
8185
filter.FilterQuery = ""
8286
}
87+
88+
if me {
89+
myUser, err := client.User(cmd.Context(), codersdk.Me)
90+
if err != nil {
91+
return err
92+
}
93+
filter.Owner = myUser.Username
94+
}
8395
workspaces, err := client.Workspaces(cmd.Context(), filter)
8496
if err != nil {
8597
return err
@@ -101,7 +113,7 @@ func list() *cobra.Command {
101113
}
102114

103115
now := time.Now()
104-
displayWorkspaces := make([]workspaceListRow, len(workspaces))
116+
displayWorkspaces = make([]workspaceListRow, len(workspaces))
105117
for i, workspace := range workspaces {
106118
displayWorkspaces[i] = workspaceListRowFromWorkspace(now, usersByID, workspace)
107119
}
@@ -115,10 +127,21 @@ func list() *cobra.Command {
115127
return err
116128
},
117129
}
130+
131+
v := reflect.Indirect(reflect.ValueOf(displayWorkspaces))
132+
availColumns, err := cliui.TypeToTableHeaders(v.Type().Elem())
133+
if err != nil {
134+
panic(err)
135+
}
136+
for i, s := range availColumns {
137+
availColumns[i] = strings.Replace(s, " ", "_", -1)
138+
}
139+
columnString := strings.Join(availColumns[:], ", ")
140+
118141
cmd.Flags().BoolVarP(&all, "all", "a", false,
119142
"Specifies whether all workspaces will be listed or not.")
120143
cmd.Flags().StringArrayVarP(&columns, "column", "c", nil,
121-
"Specify a column to filter in the table.")
122-
cmd.Flags().StringVar(&searchQuery, "search", defaultQuery, "Search for a workspace with a query.")
144+
fmt.Sprintf("Specify a column to filter in the table. Available columns are: %v", columnString))
145+
cmd.Flags().StringVar(&searchQuery, "search", "", "Search for a workspace with a query.")
123146
return cmd
124147
}

coderd/audit/request.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,18 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
110110
return
111111
}
112112

113-
diff := Diff(p.Audit, req.Old, req.New)
114-
diffRaw, _ := json.Marshal(diff)
113+
var diffRaw = []byte("{}")
114+
// Only generate diffs if the request succeeded.
115+
if sw.Status < 400 {
116+
diff := Diff(p.Audit, req.Old, req.New)
117+
118+
var err error
119+
diffRaw, err = json.Marshal(diff)
120+
if err != nil {
121+
p.Log.Warn(logCtx, "marshal diff", slog.Error(err))
122+
diffRaw = []byte("{}")
123+
}
124+
}
115125

116126
ip, err := parseIP(p.Request.RemoteAddr)
117127
if err != nil {

coderd/tracing/status_writer_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,9 @@ type hijacker struct {
127127
func (hijacker) Hijack() (net.Conn, *bufio.ReadWriter, error) {
128128
return nil, nil, xerrors.New("hijacked")
129129
}
130+
131+
func (h hijacker) Flush() {
132+
if f, ok := h.ResponseWriter.(http.Flusher); ok {
133+
f.Flush()
134+
}
135+
}

coderd/workspaces.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/go-chi/chi/v5"
1717
"github.com/google/uuid"
18+
"go.opentelemetry.io/otel/trace"
1819
"golang.org/x/xerrors"
1920

2021
"cdr.dev/slog"
@@ -26,6 +27,7 @@ import (
2627
"github.com/coder/coder/coderd/httpmw"
2728
"github.com/coder/coder/coderd/rbac"
2829
"github.com/coder/coder/coderd/telemetry"
30+
"github.com/coder/coder/coderd/tracing"
2931
"github.com/coder/coder/coderd/util/ptr"
3032
"github.com/coder/coder/codersdk"
3133
)
@@ -635,6 +637,7 @@ func (api *API) putWorkspaceTTL(rw http.ResponseWriter, r *http.Request) {
635637
})
636638
)
637639
defer commitAudit()
640+
aReq.Old = workspace
638641

639642
if !api.Authorize(r, rbac.ActionUpdate, workspace) {
640643
httpapi.ResourceNotFound(rw)
@@ -797,6 +800,9 @@ func (api *API) watchWorkspace(rw http.ResponseWriter, r *http.Request) {
797800
return
798801
}
799802

803+
// Ignore all trace spans after this, they're not too useful.
804+
ctx = trace.ContextWithSpan(ctx, tracing.NoopSpan)
805+
800806
t := time.NewTicker(time.Second * 1)
801807
defer t.Stop()
802808
for {

site/src/components/LastUsed/LastUsed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const LastUsed: FC<LastUsedProps> = ({ lastUsedAt }) => {
5050
>
5151
<Icon className={styles.icon} />
5252
</span>
53-
{message}
53+
<span data-chromatic="ignore">{message}</span>
5454
</span>
5555
)
5656
}

0 commit comments

Comments
 (0)