Skip to content

Commit 85db3c2

Browse files
committed
Add endpoint to query git state
1 parent 604cf5b commit 85db3c2

File tree

19 files changed

+532
-37
lines changed

19 files changed

+532
-37
lines changed

coderd/apidoc/docs.go

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/gitauth/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ func ConvertConfig(entries []codersdk.GitAuthConfig, accessURL *url.URL) ([]*Con
4242
for _, entry := range entries {
4343
var typ codersdk.GitProvider
4444
switch entry.Type {
45-
case codersdk.GitProviderAzureDevops:
45+
case string(codersdk.GitProviderAzureDevops):
4646
typ = codersdk.GitProviderAzureDevops
47-
case codersdk.GitProviderBitBucket:
47+
case string(codersdk.GitProviderBitBucket):
4848
typ = codersdk.GitProviderBitBucket
49-
case codersdk.GitProviderGitHub:
49+
case string(codersdk.GitProviderGitHub):
5050
typ = codersdk.GitProviderGitHub
51-
case codersdk.GitProviderGitLab:
51+
case string(codersdk.GitProviderGitLab):
5252
typ = codersdk.GitProviderGitLab
5353
default:
5454
return nil, xerrors.Errorf("unknown git provider type: %q", entry.Type)

coderd/gitauth/config_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,37 @@ func TestConvertYAML(t *testing.T) {
2626
}, {
2727
Name: "InvalidID",
2828
Input: []codersdk.GitAuthConfig{{
29-
Type: codersdk.GitProviderGitHub,
29+
Type: string(codersdk.GitProviderGitHub),
3030
ID: "$hi$",
3131
}},
3232
Error: "doesn't have a valid id",
3333
}, {
3434
Name: "NoClientID",
3535
Input: []codersdk.GitAuthConfig{{
36-
Type: codersdk.GitProviderGitHub,
36+
Type: string(codersdk.GitProviderGitHub),
3737
}},
3838
Error: "client_id must be provided",
3939
}, {
4040
Name: "NoClientSecret",
4141
Input: []codersdk.GitAuthConfig{{
42-
Type: codersdk.GitProviderGitHub,
42+
Type: string(codersdk.GitProviderGitHub),
4343
ClientID: "example",
4444
}},
4545
Error: "client_secret must be provided",
4646
}, {
4747
Name: "DuplicateType",
4848
Input: []codersdk.GitAuthConfig{{
49-
Type: codersdk.GitProviderGitHub,
49+
Type: string(codersdk.GitProviderGitHub),
5050
ClientID: "example",
5151
ClientSecret: "example",
5252
}, {
53-
Type: codersdk.GitProviderGitHub,
53+
Type: string(codersdk.GitProviderGitHub),
5454
}},
5555
Error: "multiple github git auth providers provided",
5656
}, {
5757
Name: "InvalidRegex",
5858
Input: []codersdk.GitAuthConfig{{
59-
Type: codersdk.GitProviderGitHub,
59+
Type: string(codersdk.GitProviderGitHub),
6060
ClientID: "example",
6161
ClientSecret: "example",
6262
Regex: `\K`,
@@ -79,7 +79,7 @@ func TestConvertYAML(t *testing.T) {
7979
t.Run("CustomScopesAndEndpoint", func(t *testing.T) {
8080
t.Parallel()
8181
config, err := gitauth.ConvertConfig([]codersdk.GitAuthConfig{{
82-
Type: codersdk.GitProviderGitLab,
82+
Type: string(codersdk.GitProviderGitLab),
8383
ClientID: "id",
8484
ClientSecret: "secret",
8585
AuthURL: "https://auth.com",

coderd/templateversions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func (api *API) templateVersionRichParameters(rw http.ResponseWriter, r *http.Re
250250
// @Produce json
251251
// @Tags Templates
252252
// @Param templateversion path string true "Template version ID" format(uuid)
253-
// @Success 200 {array} codersdk.GitAuth
253+
// @Success 200 {array} codersdk.TemplateVersionGitAuth
254254
// @Router /templateversions/{templateversion}/gitauth [get]
255255
func (api *API) templateVersionGitAuth(rw http.ResponseWriter, r *http.Request) {
256256
ctx := r.Context()
@@ -266,7 +266,7 @@ func (api *API) templateVersionGitAuth(rw http.ResponseWriter, r *http.Request)
266266
}
267267

268268
rawProviders := templateVersion.GitAuthProviders
269-
providers := make([]codersdk.GitAuth, 0)
269+
providers := make([]codersdk.TemplateVersionGitAuth, 0)
270270
for _, rawProvider := range rawProviders {
271271
var config *gitauth.Config
272272
for _, provider := range api.GitAuthConfigs {
@@ -293,7 +293,7 @@ func (api *API) templateVersionGitAuth(rw http.ResponseWriter, r *http.Request)
293293
return
294294
}
295295

296-
provider := codersdk.GitAuth{
296+
provider := codersdk.TemplateVersionGitAuth{
297297
ID: config.ID,
298298
Type: config.Type,
299299
AuthenticateURL: redirectURL.String(),

codersdk/templateversions.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ import (
1111
"github.com/google/uuid"
1212
)
1313

14-
type GitAuth struct {
15-
ID string `json:"id"`
16-
Type GitProvider `json:"type"`
17-
AuthenticateURL string `json:"authenticate_url"`
18-
Authenticated bool `json:"authenticated"`
19-
}
20-
2114
// TemplateVersion represents a single version of a template.
2215
type TemplateVersion struct {
2316
ID uuid.UUID `json:"id" format:"uuid"`
@@ -31,6 +24,13 @@ type TemplateVersion struct {
3124
CreatedBy User `json:"created_by"`
3225
}
3326

27+
type TemplateVersionGitAuth struct {
28+
ID string `json:"id"`
29+
Type GitProvider `json:"type"`
30+
AuthenticateURL string `json:"authenticate_url"`
31+
Authenticated bool `json:"authenticated"`
32+
}
33+
3434
type ValidationMonotonicOrder string
3535

3636
const (
@@ -116,7 +116,7 @@ func (c *Client) TemplateVersionRichParameters(ctx context.Context, version uuid
116116
}
117117

118118
// TemplateVersionGitAuth returns git authentication for the requested template version.
119-
func (c *Client) TemplateVersionGitAuth(ctx context.Context, version uuid.UUID) ([]GitAuth, error) {
119+
func (c *Client) TemplateVersionGitAuth(ctx context.Context, version uuid.UUID) ([]TemplateVersionGitAuth, error) {
120120
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templateversions/%s/gitauth", version), nil)
121121
if err != nil {
122122
return nil, err
@@ -125,7 +125,7 @@ func (c *Client) TemplateVersionGitAuth(ctx context.Context, version uuid.UUID)
125125
if res.StatusCode != http.StatusOK {
126126
return nil, ReadBodyAsError(res)
127127
}
128-
var gitAuth []GitAuth
128+
var gitAuth []TemplateVersionGitAuth
129129
return gitAuth, json.NewDecoder(res.Body).Decode(&gitAuth)
130130
}
131131

codersdk/workspaceagents.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,11 @@ func (c *Client) WorkspaceAgentListeningPorts(ctx context.Context, agentID uuid.
277277

278278
// GitProvider is a constant that represents the
279279
// type of providers that are supported within Coder.
280-
// @typescript-ignore GitProvider
281280
type GitProvider string
282281

283282
const (
284-
GitProviderAzureDevops = "azure-devops"
285-
GitProviderGitHub = "github"
286-
GitProviderGitLab = "gitlab"
287-
GitProviderBitBucket = "bitbucket"
283+
GitProviderAzureDevops GitProvider = "azure-devops"
284+
GitProviderGitHub GitProvider = "github"
285+
GitProviderGitLab GitProvider = "gitlab"
286+
GitProviderBitBucket GitProvider = "bitbucket"
288287
)

docs/api/schemas.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4570,6 +4570,26 @@ Parameter represents a set value for the scope.
45704570
| `template_id` | string | false | | |
45714571
| `updated_at` | string | false | | |
45724572

4573+
## codersdk.TemplateVersionGitAuth
4574+
4575+
```json
4576+
{
4577+
"authenticate_url": "string",
4578+
"authenticated": true,
4579+
"id": "string",
4580+
"type": "string"
4581+
}
4582+
```
4583+
4584+
### Properties
4585+
4586+
| Name | Type | Required | Restrictions | Description |
4587+
| ------------------ | ------- | -------- | ------------ | ----------- |
4588+
| `authenticate_url` | string | false | | |
4589+
| `authenticated` | boolean | false | | |
4590+
| `id` | string | false | | |
4591+
| `type` | string | false | | |
4592+
45734593
## codersdk.TemplateVersionParameter
45744594

45754595
```json

docs/api/templates.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,60 @@ Status Code **200**
17221722

17231723
To perform this operation, you must be authenticated. [Learn more](authentication.md).
17241724

1725+
## Get git auth by template version
1726+
1727+
### Code samples
1728+
1729+
```shell
1730+
# Example request using curl
1731+
curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/gitauth \
1732+
-H 'Accept: application/json' \
1733+
-H 'Coder-Session-Token: API_KEY'
1734+
```
1735+
1736+
`GET /templateversions/{templateversion}/gitauth`
1737+
1738+
### Parameters
1739+
1740+
| Name | In | Type | Required | Description |
1741+
| ----------------- | ---- | ------------ | -------- | ------------------- |
1742+
| `templateversion` | path | string(uuid) | true | Template version ID |
1743+
1744+
### Example responses
1745+
1746+
> 200 Response
1747+
1748+
```json
1749+
[
1750+
{
1751+
"authenticate_url": "string",
1752+
"authenticated": true,
1753+
"id": "string",
1754+
"type": "string"
1755+
}
1756+
]
1757+
```
1758+
1759+
### Responses
1760+
1761+
| Status | Meaning | Description | Schema |
1762+
| ------ | ------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------- |
1763+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | array of [codersdk.TemplateVersionGitAuth](schemas.md#codersdktemplateversiongitauth) |
1764+
1765+
<h3 id="get-git-auth-by-template-version-responseschema">Response Schema</h3>
1766+
1767+
Status Code **200**
1768+
1769+
| Name | Type | Required | Restrictions | Description |
1770+
| -------------------- | ------- | -------- | ------------ | ----------- |
1771+
| `[array item]` | array | false | | |
1772+
| `» authenticate_url` | string | false | | |
1773+
| `» authenticated` | boolean | false | | |
1774+
| `» id` | string | false | | |
1775+
| `» type` | string | false | | |
1776+
1777+
To perform this operation, you must be authenticated. [Learn more](authentication.md).
1778+
17251779
## Get logs by template version
17261780

17271781
### Code samples

site/src/api/api.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,15 @@ export const createTemplateVersion = async (
280280
return response.data
281281
}
282282

283+
export const getTemplateVersionGitAuth = async (
284+
versionId: string,
285+
): Promise<TypesGen.TemplateVersionGitAuth[]> => {
286+
const response = await axios.get(
287+
`/api/v2/templateversions/${versionId}/gitauth`,
288+
)
289+
return response.data
290+
}
291+
283292
export const getTemplateVersionParameters = async (
284293
versionId: string,
285294
): Promise<TypesGen.Parameter[]> => {

0 commit comments

Comments
 (0)