feat: move to forgejo sdk
This commit is contained in:
parent
d9bf396917
commit
9e053a1c5c
35 changed files with 316 additions and 714 deletions
132
forgejo/provider.go
Normal file
132
forgejo/provider.go
Normal file
|
@ -0,0 +1,132 @@
|
|||
package forgejo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
// Provider returns a terraform.ResourceProvider.
|
||||
func Provider() *schema.Provider {
|
||||
|
||||
// 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{
|
||||
"forgejo_user": dataSourceGiteaUser(),
|
||||
"forgejo_org": dataSourceGiteaOrg(),
|
||||
// "forgejo_team": dataSourceGiteaTeam(),
|
||||
// "forgejo_teams": dataSourceGiteaTeams(),
|
||||
// "forgejo_team_members": dataSourceGiteaTeamMembers(),
|
||||
"forgejo_repo": dataSourceGiteaRepo(),
|
||||
// "forgejo_repos": dataSourceGiteaRepos(),
|
||||
},
|
||||
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
"forgejo_org": resourceGiteaOrg(),
|
||||
// "forgejo_team": resourceGiteaTeam(),
|
||||
// "forgejo_repo": resourceGiteaRepo(),
|
||||
"forgejo_user": resourceGiteaUser(),
|
||||
"forgejo_oauth2_app": resourceGiteaOauthApp(),
|
||||
"forgejo_repository": resourceGiteaRepository(),
|
||||
"forgejo_fork": resourceGiteaFork(),
|
||||
"forgejo_public_key": resourceGiteaPublicKey(),
|
||||
"forgejo_team": resourceGiteaTeam(),
|
||||
"forgejo_team_membership": resourceGiteaTeamMembership(),
|
||||
"forgejo_team_members": resourceGiteaTeamMembers(),
|
||||
"forgejo_git_hook": resourceGiteaGitHook(),
|
||||
"forgejo_token": resourceGiteaToken(),
|
||||
"forgejo_repository_key": resourceGiteaRepositoryKey(),
|
||||
"forgejo_repository_webhook": resourceGiteaRepositoryWebhook(),
|
||||
"forgejo_repository_branch_protection": resourceGiteaRepositoryBranchProtection(),
|
||||
},
|
||||
|
||||
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-forgejo-provider base URL format is incorrect; Please leave out API Path %s", v))
|
||||
}
|
||||
if strings.Contains(v, "localhost") && strings.Contains(v, ".") {
|
||||
es = append(es, fmt.Errorf("terraform-forgejo-provider base URL violates RFC 2606; Please do not define a subdomain for localhost!"))
|
||||
}
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue