Skip to content

Commit

Permalink
implement set
Browse files Browse the repository at this point in the history
  • Loading branch information
BarnabyShearer committed Nov 22, 2021
1 parent 083246f commit e26e0aa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dockerhub/resource_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,26 @@ func resourceToken() *schema.Resource {
Description: "Token to use as password",
},
"scopes": {
Type: schema.TypeList,
Type: schema.TypeSet,
Required: true,
ForceNew: true,
Description: "Permissions e.g. 'repo:admin'",
Elem: schema.TypeString,
},
},
}
}

func resourceTokenCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*dh.Client)
scopesRaw := d.Get("scopes").(*schema.Set).List()
scopes := make([]string, len(scopesRaw))
for i, raw := range scopesRaw {
scopes[i] = raw.(string)
}
token, err := client.CreatePersonalAccessToken(ctx, dh.CreatePersonalAccessToken{
TokenLabel: d.Get("label").(string),
Scopes: d.Get("scopes").([]string),
Scopes: scopes,
})
if err != nil {
return diag.FromErr(err)
Expand Down

0 comments on commit e26e0aa

Please sign in to comment.