mirror of
https://git.uploadfilter24.eu/lerentis/terraform-provider-gitea.git
synced 2024-11-16 23:18:12 +00:00
e1266ebf64
Update to v2 SDK updated dependencies
85 lines
1.6 KiB
Go
85 lines
1.6 KiB
Go
package gitea
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"strings"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
)
|
|
|
|
func dataSourceGiteaOrg() *schema.Resource {
|
|
return &schema.Resource{
|
|
Read: dataSourceGiteaUserRead,
|
|
Schema: map[string]*schema.Schema{
|
|
"id": {
|
|
Type: schema.TypeInt,
|
|
Computed: true,
|
|
},
|
|
"name": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
Optional: true,
|
|
},
|
|
"full_name": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
"description": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
"avatar_url": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
"website": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
"location": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
"visibility": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func dataSourceGiteaOrgRead(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*gitea.Client)
|
|
|
|
var org *gitea.Organization
|
|
var err error
|
|
|
|
log.Printf("[INFO] Reading Gitea Org")
|
|
|
|
nameData, nameOk := d.GetOk("name")
|
|
|
|
if !nameOk {
|
|
return fmt.Errorf("name of org must be passed")
|
|
}
|
|
name := strings.ToLower(nameData.(string))
|
|
|
|
org, _, err = client.GetOrg(name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
d.Set("id", org.ID)
|
|
d.Set("name", org.UserName)
|
|
d.Set("full_name", org.FullName)
|
|
d.Set("avatar_url", org.AvatarURL)
|
|
d.Set("location", org.Location)
|
|
d.Set("website", org.Website)
|
|
d.Set("description", org.Description)
|
|
d.Set("visibility", org.Visibility)
|
|
|
|
d.SetId(fmt.Sprintf("%d", org.ID))
|
|
|
|
return nil
|
|
}
|