-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathgitauth.go
53 lines (45 loc) · 1.73 KB
/
gitauth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/coder/terraform-provider-coder/provider/helpers"
)
// gitAuthDataSource returns a schema for a Git authentication data source.
func gitAuthDataSource() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "Use the `coder_external_auth` data source instead.",
Description: "~> **Deprecated**\nUse the `coder_external_auth` data source instead.\n\nUse this data source to require users to authenticate with a Git provider prior to workspace creation. This can be used to perform an authenticated `git clone` in startup scripts.",
ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
rawID, ok := rd.GetOk("id")
if !ok {
return diag.Errorf("id is required")
}
id, ok := rawID.(string)
if !ok {
return diag.Errorf("unexpected type %q for id", rawID)
}
rd.SetId(id)
accessToken := helpers.OptionalEnv(GitAuthAccessTokenEnvironmentVariable(id))
rd.Set("access_token", accessToken)
return nil
},
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
Description: "The identifier of a configured git auth provider set up in your Coder deployment.",
},
"access_token": {
Type: schema.TypeString,
Computed: true,
Description: "The access token returned by the git authentication provider. This can be used to pre-authenticate command-line tools.",
},
},
}
}
func GitAuthAccessTokenEnvironmentVariable(id string) string {
return fmt.Sprintf("CODER_GIT_AUTH_ACCESS_TOKEN_%s", id)
}