2022-03-31 21:24:00 +00:00
|
|
|
package gitea
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2022-08-06 14:21:18 +00:00
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
2022-03-31 21:24:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Provider returns a terraform.ResourceProvider.
|
2022-08-06 14:21:18 +00:00
|
|
|
func Provider() *schema.Provider {
|
2022-03-31 21:24:00 +00:00
|
|
|
|
|
|
|
// The actual provider
|
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"token": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("GITEA_TOKEN", nil),
|
|
|
|
Description: descriptions["token"],
|
|
|
|
ConflictsWith: []string{
|
|
|
|
"username",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"username": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("GITEA_USERNAME", nil),
|
|
|
|
Description: descriptions["username"],
|
|
|
|
ConflictsWith: []string{
|
|
|
|
"token",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"password": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("GITEA_PASSWORD", nil),
|
|
|
|
Description: descriptions["password"],
|
|
|
|
ConflictsWith: []string{
|
|
|
|
"token",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"base_url": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("GITEA_BASE_URL", ""),
|
|
|
|
Description: descriptions["base_url"],
|
|
|
|
ValidateFunc: validateAPIURLVersion,
|
|
|
|
},
|
|
|
|
"cacert_file": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "",
|
|
|
|
Description: descriptions["cacert_file"],
|
|
|
|
},
|
|
|
|
"insecure": {
|
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
Default: false,
|
|
|
|
Description: descriptions["insecure"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
DataSourcesMap: map[string]*schema.Resource{
|
|
|
|
"gitea_user": dataSourceGiteaUser(),
|
|
|
|
"gitea_org": dataSourceGiteaOrg(),
|
|
|
|
// "gitea_team": dataSourceGiteaTeam(),
|
|
|
|
// "gitea_teams": dataSourceGiteaTeams(),
|
|
|
|
// "gitea_team_members": dataSourceGiteaTeamMembers(),
|
2022-04-01 04:23:50 +00:00
|
|
|
"gitea_repo": dataSourceGiteaRepo(),
|
2022-03-31 21:24:00 +00:00
|
|
|
// "gitea_repos": dataSourceGiteaRepos(),
|
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2022-10-01 11:56:10 +00:00
|
|
|
"gitea_org": resourceGiteaOrg(),
|
|
|
|
// "gitea_team": resourceGiteaTeam(),
|
|
|
|
// "gitea_repo": resourceGiteaRepo(),
|
2022-06-14 21:24:42 +00:00
|
|
|
"gitea_user": resourceGiteaUser(),
|
2022-05-23 10:28:33 +00:00
|
|
|
"gitea_oauth2_app": resourceGiteaOauthApp(),
|
2022-06-04 15:17:08 +00:00
|
|
|
"gitea_repository": resourceGiteaRepository(),
|
2022-10-01 11:56:10 +00:00
|
|
|
"gitea_fork": resourceGiteaFork(),
|
2022-06-21 21:10:25 +00:00
|
|
|
"gitea_public_key": resourceGiteaPublicKey(),
|
2022-06-25 21:36:24 +00:00
|
|
|
"gitea_team": resourceGiteaTeam(),
|
2022-08-30 18:10:07 +00:00
|
|
|
"gitea_git_hook": resourceGiteaGitHook(),
|
2022-03-31 21:24:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var descriptions map[string]string
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
descriptions = map[string]string{
|
|
|
|
"token": "The application token used to connect to Gitea.",
|
|
|
|
"username": "Username in case of using basic auth",
|
|
|
|
"password": "Password in case of using basic auth",
|
|
|
|
"base_url": "The Gitea Base API URL",
|
|
|
|
"cacert_file": "A file containing the ca certificate to use in case ssl certificate is not from a standard chain",
|
|
|
|
"insecure": "Disable SSL verification of API calls",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
config := Config{
|
|
|
|
Token: d.Get("token").(string),
|
|
|
|
Username: d.Get("username").(string),
|
|
|
|
Password: d.Get("password").(string),
|
|
|
|
BaseURL: d.Get("base_url").(string),
|
|
|
|
CACertFile: d.Get("cacert_file").(string),
|
|
|
|
Insecure: d.Get("insecure").(bool),
|
|
|
|
}
|
|
|
|
|
|
|
|
return config.Client()
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateAPIURLVersion(value interface{}, key string) (ws []string, es []error) {
|
|
|
|
v := value.(string)
|
|
|
|
if strings.HasSuffix(v, "/api/v1") || strings.HasSuffix(v, "/api/v1/") {
|
|
|
|
es = append(es, fmt.Errorf("terraform-gitea-provider base URL format is incorrect; Please leave out API Path %s", v))
|
|
|
|
}
|
2022-08-04 16:23:41 +00:00
|
|
|
if strings.Contains(v, "localhost") && strings.Contains(v, ".") {
|
|
|
|
es = append(es, fmt.Errorf("terraform-gitea-provider base URL violates RFC 2606; Please do not define a subdomain for localhost!"))
|
|
|
|
}
|
2022-03-31 21:24:00 +00:00
|
|
|
return
|
|
|
|
}
|