chore: add api endpoints to get idp field values (#16063)

Supports coder/internal#210
This commit is contained in:
Jaayden Halko
2025-01-08 16:07:02 -05:00
committed by GitHub
parent 303c4a9edb
commit 6ca1e5973e
7 changed files with 359 additions and 0 deletions
+33
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"regexp"
"github.com/google/uuid"
@@ -163,3 +164,35 @@ func (c *Client) GetOrganizationAvailableIDPSyncFields(ctx context.Context, orgI
var resp []string
return resp, json.NewDecoder(res.Body).Decode(&resp)
}
func (c *Client) GetIDPSyncFieldValues(ctx context.Context, claimField string) ([]string, error) {
qv := url.Values{}
qv.Add("claimField", claimField)
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/settings/idpsync/field-values?%s", qv.Encode()), nil)
if err != nil {
return nil, xerrors.Errorf("make request: %w", err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, ReadBodyAsError(res)
}
var resp []string
return resp, json.NewDecoder(res.Body).Decode(&resp)
}
func (c *Client) GetOrganizationIDPSyncFieldValues(ctx context.Context, orgID string, claimField string) ([]string, error) {
qv := url.Values{}
qv.Add("claimField", claimField)
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/organizations/%s/settings/idpsync/field-values?%s", orgID, qv.Encode()), nil)
if err != nil {
return nil, xerrors.Errorf("make request: %w", err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, ReadBodyAsError(res)
}
var resp []string
return resp, json.NewDecoder(res.Body).Decode(&resp)
}