Compare commits
8 Commits
48f5c3ee3c
...
v0.16.0
Author | SHA1 | Date | |
---|---|---|---|
601cc245ef | |||
340bcd48fe | |||
2d7147442b | |||
ed32470b17 | |||
483bda1033
|
|||
c707cba22e | |||
5b14a5d789 | |||
707443c6d2 |
2
Makefile
2
Makefile
@ -5,7 +5,7 @@ KERNEL?=$$(uname -s | tr '[:upper:]' '[:lower:]')
|
|||||||
|
|
||||||
GOFMT ?= gofmt -s
|
GOFMT ?= gofmt -s
|
||||||
|
|
||||||
VERSION = 0.14.1
|
VERSION = 0.16.0
|
||||||
|
|
||||||
test: fmt-check
|
test: fmt-check
|
||||||
go test -i $(TEST) || exit 1
|
go test -i $(TEST) || exit 1
|
||||||
|
@ -17,7 +17,7 @@ terraform {
|
|||||||
required_providers {
|
required_providers {
|
||||||
gitea = {
|
gitea = {
|
||||||
source = "Lerentis/gitea"
|
source = "Lerentis/gitea"
|
||||||
version = "0.14.1"
|
version = "0.16.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ terraform {
|
|||||||
required_providers {
|
required_providers {
|
||||||
gitea = {
|
gitea = {
|
||||||
source = "Lerentis/gitea"
|
source = "Lerentis/gitea"
|
||||||
version = "0.14.1"
|
version = "0.16.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,10 @@ Handling [gitea oauth application](https://docs.gitea.io/en-us/oauth2-provider/)
|
|||||||
- `name` (String) OAuth Application name
|
- `name` (String) OAuth Application name
|
||||||
- `redirect_uris` (Set of String) Accepted redirect URIs
|
- `redirect_uris` (Set of String) Accepted redirect URIs
|
||||||
|
|
||||||
|
### Optional
|
||||||
|
|
||||||
|
- `confidential_client` (Boolean) If set to false, it will be a public client (PKCE will be required)
|
||||||
|
|
||||||
### Read-Only
|
### Read-Only
|
||||||
|
|
||||||
- `client_id` (String) OAuth2 Application client id
|
- `client_id` (String) OAuth2 Application client id
|
||||||
|
@ -46,5 +46,6 @@ resource "gitea_repository" "org_repo" {
|
|||||||
|
|
||||||
- `avatar_url` (String)
|
- `avatar_url` (String)
|
||||||
- `id` (String) The ID of this resource.
|
- `id` (String) The ID of this resource.
|
||||||
|
- `repos` (List of String) List of all Repositories that are part of this organisation
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,3 +123,15 @@ output "token" {
|
|||||||
value = resource.gitea_token.test_token.token
|
value = resource.gitea_token.test_token.token
|
||||||
sensitive = true
|
sensitive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data "gitea_repo" "org_repos" {
|
||||||
|
name = each.key
|
||||||
|
username = gitea_org.org1.name
|
||||||
|
for_each = {
|
||||||
|
for repo in resource.gitea_org.org1.repos : repo => repo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output "repos" {
|
||||||
|
value = data.gitea_repo.org_repos["repo1-in-org1"].clone_url
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@ terraform {
|
|||||||
required_providers {
|
required_providers {
|
||||||
gitea = {
|
gitea = {
|
||||||
source = "terraform.local/lerentis/gitea"
|
source = "terraform.local/lerentis/gitea"
|
||||||
version = "0.14.1"
|
version = "0.16.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ terraform {
|
|||||||
required_providers {
|
required_providers {
|
||||||
gitea = {
|
gitea = {
|
||||||
source = "Lerentis/gitea"
|
source = "Lerentis/gitea"
|
||||||
version = "0.14.1"
|
version = "0.16.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
oauth2KeyName string = "name"
|
oauth2KeyName string = "name"
|
||||||
|
oauth2KeyConfidentialClient string = "confidential_client"
|
||||||
oauth2KeyRedirectURIs string = "redirect_uris"
|
oauth2KeyRedirectURIs string = "redirect_uris"
|
||||||
oauth2KeyClientId string = "client_id"
|
oauth2KeyClientId string = "client_id"
|
||||||
oauth2KeyClientSecret string = "client_secret"
|
oauth2KeyClientSecret string = "client_secret"
|
||||||
@ -37,6 +38,12 @@ func resourceGiteaOauthApp() *schema.Resource {
|
|||||||
},
|
},
|
||||||
Description: "Accepted redirect URIs",
|
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: {
|
oauth2KeyClientId: {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
@ -89,8 +96,15 @@ func resourceOauth2AppUpcreate(d *schema.ResourceData, meta interface{}) (err er
|
|||||||
return fmt.Errorf("attribute %s must be set and must be a string", oauth2KeyName)
|
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{
|
opts := gitea.CreateOauth2Option{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
ConfidentialClient: confidentialClient,
|
||||||
RedirectURIs: redirectURIs,
|
RedirectURIs: redirectURIs,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +113,7 @@ func resourceOauth2AppUpcreate(d *schema.ResourceData, meta interface{}) (err er
|
|||||||
if d.IsNewResource() {
|
if d.IsNewResource() {
|
||||||
oauth2, _, err = client.CreateOauth2(opts)
|
oauth2, _, err = client.CreateOauth2(opts)
|
||||||
} else {
|
} else {
|
||||||
oauth2, err := searchOauth2AppByClientId(client, d.Id())
|
oauth2, err = searchOauth2AppByClientId(client, d.Id())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -177,6 +191,7 @@ func setOAuth2ResourceData(app *gitea.Oauth2, d *schema.ResourceData) (err error
|
|||||||
|
|
||||||
for k, v := range map[string]interface{}{
|
for k, v := range map[string]interface{}{
|
||||||
oauth2KeyName: app.Name,
|
oauth2KeyName: app.Name,
|
||||||
|
oauth2KeyConfidentialClient: app.ConfidentialClient,
|
||||||
oauth2KeyRedirectURIs: schema.NewSet(schema.HashString, CollapseStringList(app.RedirectURIs)),
|
oauth2KeyRedirectURIs: schema.NewSet(schema.HashString, CollapseStringList(app.RedirectURIs)),
|
||||||
oauth2KeyClientId: app.ClientID,
|
oauth2KeyClientId: app.ClientID,
|
||||||
} {
|
} {
|
||||||
|
@ -16,6 +16,7 @@ const (
|
|||||||
orgLocation string = "location"
|
orgLocation string = "location"
|
||||||
orgVisibility string = "visibility"
|
orgVisibility string = "visibility"
|
||||||
RepoAdminChangeTeamAccess string = "repo_admin_change_team_access"
|
RepoAdminChangeTeamAccess string = "repo_admin_change_team_access"
|
||||||
|
orgRepos string = "org_repos"
|
||||||
)
|
)
|
||||||
|
|
||||||
// might come in handy if we want to stick to numeric IDs
|
// might come in handy if we want to stick to numeric IDs
|
||||||
@ -48,6 +49,32 @@ func searchOrgByClientId(c *gitea.Client, id int64) (res *gitea.Organization, er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAllOrgRepos(c *gitea.Client, orgName string) (repos []string, err error) {
|
||||||
|
page := 1
|
||||||
|
|
||||||
|
for {
|
||||||
|
repoBuffer, _, err := c.ListOrgRepos(orgName, gitea.ListOrgReposOptions{
|
||||||
|
ListOptions: gitea.ListOptions{
|
||||||
|
Page: page,
|
||||||
|
PageSize: 50,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(repoBuffer) == 0 {
|
||||||
|
return repos, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, repo := range repoBuffer {
|
||||||
|
repos = append(repos, repo.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
page += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func resourceOrgRead(d *schema.ResourceData, meta interface{}) (err error) {
|
func resourceOrgRead(d *schema.ResourceData, meta interface{}) (err error) {
|
||||||
client := meta.(*gitea.Client)
|
client := meta.(*gitea.Client)
|
||||||
|
|
||||||
@ -62,7 +89,8 @@ func resourceOrgRead(d *schema.ResourceData, meta interface{}) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = setOrgResourceData(org, d)
|
repos, _ := getAllOrgRepos(client, org.UserName)
|
||||||
|
err = setOrgResourceData(org, d, &repos)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -85,7 +113,8 @@ func resourceOrgCreate(d *schema.ResourceData, meta interface{}) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = setOrgResourceData(org, d)
|
repos, _ := getAllOrgRepos(client, org.UserName)
|
||||||
|
err = setOrgResourceData(org, d, &repos)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -118,7 +147,8 @@ func resourceOrgUpdate(d *schema.ResourceData, meta interface{}) (err error) {
|
|||||||
|
|
||||||
org, resp, err = client.GetOrg(d.Get(orgName).(string))
|
org, resp, err = client.GetOrg(d.Get(orgName).(string))
|
||||||
|
|
||||||
err = setOrgResourceData(org, d)
|
repos, _ := getAllOrgRepos(client, org.UserName)
|
||||||
|
err = setOrgResourceData(org, d, &repos)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -141,7 +171,7 @@ func resourceOrgDelete(d *schema.ResourceData, meta interface{}) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func setOrgResourceData(org *gitea.Organization, d *schema.ResourceData) (err error) {
|
func setOrgResourceData(org *gitea.Organization, d *schema.ResourceData, repos *[]string) (err error) {
|
||||||
d.SetId(fmt.Sprintf("%d", org.ID))
|
d.SetId(fmt.Sprintf("%d", org.ID))
|
||||||
d.Set("name", org.UserName)
|
d.Set("name", org.UserName)
|
||||||
d.Set("full_name", org.FullName)
|
d.Set("full_name", org.FullName)
|
||||||
@ -150,6 +180,7 @@ func setOrgResourceData(org *gitea.Organization, d *schema.ResourceData) (err er
|
|||||||
d.Set("website", org.Website)
|
d.Set("website", org.Website)
|
||||||
d.Set("location", org.Location)
|
d.Set("location", org.Location)
|
||||||
d.Set("visibility", org.Visibility)
|
d.Set("visibility", org.Visibility)
|
||||||
|
d.Set("repos", repos)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -211,6 +242,13 @@ func resourceGiteaOrg() *schema.Resource {
|
|||||||
Default: "public",
|
Default: "public",
|
||||||
Description: "Flag is this organisation should be publicly visible or not.",
|
Description: "Flag is this organisation should be publicly visible or not.",
|
||||||
},
|
},
|
||||||
|
"repos": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Required: false,
|
||||||
|
Computed: true,
|
||||||
|
Description: "List of all Repositories that are part of this organisation",
|
||||||
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Description: "`gitea_org` manages a gitea organisation.\n\n" +
|
Description: "`gitea_org` manages a gitea organisation.\n\n" +
|
||||||
"Organisations are a way to group repositories and abstract permission management in a gitea instance.",
|
"Organisations are a way to group repositories and abstract permission management in a gitea instance.",
|
||||||
|
2
vendor/code.gitea.io/sdk/gitea/oauth2.go
generated
vendored
2
vendor/code.gitea.io/sdk/gitea/oauth2.go
generated
vendored
@ -18,6 +18,7 @@ type Oauth2 struct {
|
|||||||
ClientID string `json:"client_id"`
|
ClientID string `json:"client_id"`
|
||||||
ClientSecret string `json:"client_secret"`
|
ClientSecret string `json:"client_secret"`
|
||||||
RedirectURIs []string `json:"redirect_uris"`
|
RedirectURIs []string `json:"redirect_uris"`
|
||||||
|
ConfidentialClient bool `json:"confidential_client"`
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ type ListOauth2Option struct {
|
|||||||
// CreateOauth2Option required options for creating an Application
|
// CreateOauth2Option required options for creating an Application
|
||||||
type CreateOauth2Option struct {
|
type CreateOauth2Option struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
ConfidentialClient bool `json:"confidential_client"`
|
||||||
RedirectURIs []string `json:"redirect_uris"`
|
RedirectURIs []string `json:"redirect_uris"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user