Skip to content

Commit 86f7dab

Browse files
committed
fix provisioner tag filtering
1 parent 8bf79c8 commit 86f7dab

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

coderd/database/dump.sql

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
CREATE OR REPLACE FUNCTION tags_compatible(provisioner_tags jsonb, required_tags jsonb)
1+
CREATE OR REPLACE FUNCTION tags_compatible(subset_tags jsonb, superset_tags jsonb)
22
RETURNS boolean as $$
33
BEGIN
44
RETURN CASE
5-
WHEN provisioner_tags = '{"scope": "organization", "owner": ""}' :: jsonb
6-
THEN provisioner_tags = required_tags
7-
ELSE required_tags <@ provisioner_tags
5+
WHEN superset_tags = '{"scope": "organization", "owner": ""}' :: jsonb
6+
THEN subset_tags = superset_tags
7+
ELSE subset_tags <@ superset_tags
88
END;
99
END;
1010
$$ LANGUAGE plpgsql;

coderd/database/queries.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/provisionerjobs.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ WHERE
2222
AND nested.organization_id = @organization_id
2323
-- Ensure the caller has the correct provisioner.
2424
AND nested.provisioner = ANY(@types :: provisioner_type [ ])
25-
AND tags_compatible(nested.tags, @tags)
25+
AND tags_compatible(@tags, nested.tags)
2626
ORDER BY
2727
nested.created_at
2828
FOR UPDATE

enterprise/coderd/provisionerdaemons.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ func (api *API) provisionerDaemons(rw http.ResponseWriter, r *http.Request) {
6565
org := httpmw.OrganizationParam(r)
6666

6767
tags := provisionerTags(r)
68-
68+
tagsJSON, err := json.Marshal(tags)
6969
daemons, err := api.Database.GetProvisionerDaemonsByOrganization(
7070
ctx,
7171
database.GetProvisionerDaemonsByOrganizationParams{
7272
OrganizationID: org.ID,
73-
Tags: tags,
73+
Tags: tagsJSON,
7474
},
7575
)
7676
if err != nil {
@@ -84,22 +84,21 @@ func (api *API) provisionerDaemons(rw http.ResponseWriter, r *http.Request) {
8484
httpapi.Write(ctx, rw, http.StatusOK, db2sdk.List(daemons, db2sdk.ProvisionerDaemon))
8585
}
8686

87-
func provisionerTags(r *http.Request) json.RawMessage {
87+
func provisionerTags(r *http.Request) map[string]string {
8888
tags := r.URL.Query()["tags"]
8989
if len(tags) == 0 {
90-
return json.RawMessage("{}")
90+
return nil
9191
}
9292

93-
var pairs []string
93+
var tagMap map[string]string
9494
for _, tag := range tags {
9595
parts := strings.SplitN(tag, "=", 2)
9696
if len(parts) == 2 {
97-
pairs = append(pairs, fmt.Sprintf(`%q:%q`, parts[0], parts[1]))
97+
tagMap[parts[0]] = parts[1]
9898
}
9999
}
100100

101-
jsonString := fmt.Sprintf("{%s}", strings.Join(pairs, ","))
102-
return json.RawMessage(jsonString)
101+
return tagMap
103102
}
104103

105104
type provisiionerDaemonAuthResponse struct {

0 commit comments

Comments
 (0)