mirror of
https://git.uploadfilter24.eu/lerentis/terraform-provider-gitea.git
synced 2024-11-05 10:28:12 +00:00
86 lines
1.6 KiB
Go
86 lines
1.6 KiB
Go
|
package gitea
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"strings"
|
||
|
|
||
|
"code.gitea.io/sdk/gitea"
|
||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||
|
)
|
||
|
|
||
|
func dataSourceGiteaOrg() *schema.Resource {
|
||
|
return &schema.Resource{
|
||
|
Read: dataSourceGitlabUserRead,
|
||
|
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 dataSourceGitlabOrgRead(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
|
||
|
}
|