-
Notifications
You must be signed in to change notification settings - Fork 11
Add Scope for Resource_Gitea_Token #53
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ const ( | |
TokenName string = "name" | ||
TokenHash string = "token" | ||
TokenLastEight string = "last_eight" | ||
TokenScope string = "scope" | ||
) | ||
|
||
func searchTokenById(c *gitea.Client, id int64) (res *gitea.AccessToken, err error) { | ||
|
@@ -49,6 +50,10 @@ func resourceTokenCreate(d *schema.ResourceData, meta interface{}) (err error) { | |
|
||
var opt gitea.CreateAccessTokenOption | ||
opt.Name = d.Get(TokenName).(string) | ||
opt.Scopes = []gitea.AccessTokenScope{} | ||
for _, scope := range d.Get(TokenScope).([]interface{}) { | ||
opt.Scopes = append(opt.Scopes, gitea.AccessTokenScope(scope.(string))) | ||
} | ||
|
||
token, _, err := client.CreateAccessToken(opt) | ||
|
||
|
@@ -102,6 +107,11 @@ func setTokenResourceData(token *gitea.AccessToken, d *schema.ResourceData) (err | |
|
||
d.SetId(fmt.Sprintf("%d", token.ID)) | ||
d.Set(TokenName, token.Name) | ||
var scopeList []string | ||
for _, scope := range token.Scopes { | ||
scopeList = append(scopeList, string(scope)) | ||
} | ||
d.Set(TokenScope, scopeList) | ||
if token.Token != "" { | ||
d.Set(TokenHash, token.Token) | ||
} | ||
|
@@ -137,6 +147,15 @@ func resourceGiteaToken() *schema.Resource { | |
Sensitive: true, | ||
Description: "The actual Access Token", | ||
}, | ||
"scope": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Optional: true, | ||
ForceNew: true, | ||
Description: "The token scope", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add the list of possible values here as it would directly be computed into the documentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the list from go-gitea/gitea#24767 |
||
}, | ||
"last_eight": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ module git.uploadfilter24.eu/terraform-provider-gitea | |
go 1.18 | ||
|
||
require ( | ||
code.gitea.io/sdk/gitea v0.15.1 | ||
code.gitea.io/sdk/gitea v0.15.1-0.20230815151548-091528835fc2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i am wondering if this is not just the way to go. the gitea SDK maintainers do not really release anymore it seems. will try to reach out and clarify the situation but with what i know now this would not be a blocker to move forward here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, It seems to be odd. Not sure if this is related to them changing license structure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just to give you an update: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok 👍 Thanks for the update :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @David-Elizondo As an FYI, there is no licensing change to any Gitea repos. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello @techknowlogick, Thanks for the update. Sure thing I'll go over their and push these changes. I'll close this PR once complete. Congrats @Lerentis 🥳 |
||
github.com/hashicorp/terraform-plugin-docs v0.16.0 | ||
github.com/hashicorp/terraform-plugin-log v0.9.0 | ||
github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0 | ||
|
@@ -19,7 +19,9 @@ require ( | |
github.com/armon/go-radix v1.0.0 // indirect | ||
github.com/bgentry/speakeasy v0.1.0 // indirect | ||
github.com/cloudflare/circl v1.3.3 // indirect | ||
github.com/davidmz/go-pageant v1.0.2 // indirect | ||
github.com/fatih/color v1.13.0 // indirect | ||
github.com/go-fed/httpsig v1.1.0 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/go-cmp v0.5.9 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is definitely worthy of a minor release and not a patch release ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bumped :)