mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-08 15:13:56 -06:00
631b0b865c
Here we add a basic provider with a single resource type. It's copied heavily from the `github` provider and `github_repository` resource, as there is some overlap in those types/apis. ~~~ resource "gitlab_project" "test1" { name = "test1" visibility_level = "public" } ~~~ We implement in terms of the [go-gitlab](https://github.com/xanzy/go-gitlab) library, which provides a wrapping of the [gitlab api](https://docs.gitlab.com/ee/api/) We have been a little selective in the properties we surface for the project resource, as not all properties are very instructive. Notable is the removal of the `public` bool as the `visibility_level` will take precedent if both are supplied which leads to confusing interactions if they disagree.
32 lines
696 B
Go
32 lines
696 B
Go
package gitlab
|
|
|
|
import (
|
|
"github.com/xanzy/go-gitlab"
|
|
)
|
|
|
|
// Config is per-provider, specifies where to connect to gitlab
|
|
type Config struct {
|
|
Token string
|
|
BaseURL string
|
|
}
|
|
|
|
// Client returns a *gitlab.Client to interact with the configured gitlab instance
|
|
func (c *Config) Client() (interface{}, error) {
|
|
client := gitlab.NewClient(nil, c.Token)
|
|
if c.BaseURL != "" {
|
|
err := client.SetBaseURL(c.BaseURL)
|
|
if err != nil {
|
|
// The BaseURL supplied wasn't valid, bail.
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
// Test the credentials by checking we can get information about the authenticated user.
|
|
_, _, err := client.Users.CurrentUser()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return client, nil
|
|
}
|