|
|
|
@ -8,10 +8,11 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
oauth2KeyName string = "name"
|
|
|
|
|
oauth2KeyRedirectURIs string = "redirect_uris"
|
|
|
|
|
oauth2KeyClientId string = "client_id"
|
|
|
|
|
oauth2KeyClientSecret string = "client_secret"
|
|
|
|
|
oauth2KeyName string = "name"
|
|
|
|
|
oauth2KeyConfidentialClient string = "confidential_client"
|
|
|
|
|
oauth2KeyRedirectURIs string = "redirect_uris"
|
|
|
|
|
oauth2KeyClientId string = "client_id"
|
|
|
|
|
oauth2KeyClientSecret string = "client_secret"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func resourceGiteaOauthApp() *schema.Resource {
|
|
|
|
@ -37,6 +38,12 @@ func resourceGiteaOauthApp() *schema.Resource {
|
|
|
|
|
},
|
|
|
|
|
Description: "Accepted redirect URIs",
|
|
|
|
|
},
|
|
|
|
|
oauth2KeyConfidentialClient: {
|
|
|
|
|
Type: schema.TypeBool,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Default: false,
|
|
|
|
|
Description: "If set to false, it will be a public client (PKCE will be required)",
|
|
|
|
|
},
|
|
|
|
|
oauth2KeyClientId: {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
@ -89,9 +96,16 @@ func resourceOauth2AppUpcreate(d *schema.ResourceData, meta interface{}) (err er
|
|
|
|
|
return fmt.Errorf("attribute %s must be set and must be a string", oauth2KeyName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
confidentialClient, confidentialClientOk := d.Get(oauth2KeyConfidentialClient).(bool)
|
|
|
|
|
|
|
|
|
|
if !confidentialClientOk {
|
|
|
|
|
return fmt.Errorf("attribute %s must be set and must be a bool", oauth2KeyConfidentialClient)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opts := gitea.CreateOauth2Option{
|
|
|
|
|
Name: name,
|
|
|
|
|
RedirectURIs: redirectURIs,
|
|
|
|
|
Name: name,
|
|
|
|
|
ConfidentialClient: confidentialClient,
|
|
|
|
|
RedirectURIs: redirectURIs,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var oauth2 *gitea.Oauth2
|
|
|
|
@ -99,7 +113,7 @@ func resourceOauth2AppUpcreate(d *schema.ResourceData, meta interface{}) (err er
|
|
|
|
|
if d.IsNewResource() {
|
|
|
|
|
oauth2, _, err = client.CreateOauth2(opts)
|
|
|
|
|
} else {
|
|
|
|
|
oauth2, err := searchOauth2AppByClientId(client, d.Id())
|
|
|
|
|
oauth2, err = searchOauth2AppByClientId(client, d.Id())
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -176,9 +190,10 @@ func setOAuth2ResourceData(app *gitea.Oauth2, d *schema.ResourceData) (err error
|
|
|
|
|
d.SetId(app.ClientID)
|
|
|
|
|
|
|
|
|
|
for k, v := range map[string]interface{}{
|
|
|
|
|
oauth2KeyName: app.Name,
|
|
|
|
|
oauth2KeyRedirectURIs: schema.NewSet(schema.HashString, CollapseStringList(app.RedirectURIs)),
|
|
|
|
|
oauth2KeyClientId: app.ClientID,
|
|
|
|
|
oauth2KeyName: app.Name,
|
|
|
|
|
oauth2KeyConfidentialClient: app.ConfidentialClient,
|
|
|
|
|
oauth2KeyRedirectURIs: schema.NewSet(schema.HashString, CollapseStringList(app.RedirectURIs)),
|
|
|
|
|
oauth2KeyClientId: app.ClientID,
|
|
|
|
|
} {
|
|
|
|
|
err = d.Set(k, v)
|
|
|
|
|
if err != nil {
|
|
|
|
|