-
Notifications
You must be signed in to change notification settings - Fork 968
Expand file tree
/
Copy pathdata_source_github_actions_organization_remove_token.go
More file actions
55 lines (47 loc) · 1.56 KB
/
data_source_github_actions_organization_remove_token.go
File metadata and controls
55 lines (47 loc) · 1.56 KB
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
54
55
package github
import (
"context"
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// dataSourceGithubActionsOrganizationRemoveToken is a data source that creates a token that can be
// used to remove a self-hosted runner from an organization.
// https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-remove-token-for-an-organization
func dataSourceGithubActionsOrganizationRemoveToken() *schema.Resource {
return &schema.Resource{
Read: dataSourceGithubActionsOrganizationRemoveTokenRead,
Schema: map[string]*schema.Schema{
"token": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "Token used to remove a self-hosted runner from an organization.",
},
"expires_at": {
Type: schema.TypeInt,
Computed: true,
Description: "The token expiration date.",
},
},
}
}
func dataSourceGithubActionsOrganizationRemoveTokenRead(d *schema.ResourceData, meta any) error {
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
log.Printf("[DEBUG] Creating a GitHub Actions organization remove token for %s", owner)
token, _, err := client.Actions.CreateOrganizationRemoveToken(context.TODO(), owner)
if err != nil {
return fmt.Errorf("error creating a GitHub Actions organization remove token for %s: %w", owner, err)
}
d.SetId(owner)
err = d.Set("token", token.Token)
if err != nil {
return err
}
err = d.Set("expires_at", token.ExpiresAt.Unix())
if err != nil {
return err
}
return nil
}