2018-03-20 22:17:14 +01:00
|
|
|
package artifactory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-11-06 23:18:33 +01:00
|
|
|
cleanhttp "github.com/hashicorp/go-cleanhttp"
|
2021-05-17 17:42:17 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/backend"
|
2020-11-18 16:07:30 +01:00
|
|
|
"github.com/hashicorp/terraform/internal/legacy/helper/schema"
|
2020-08-11 17:43:01 +02:00
|
|
|
"github.com/hashicorp/terraform/states/remote"
|
|
|
|
"github.com/hashicorp/terraform/states/statemgr"
|
2018-03-20 22:17:14 +01:00
|
|
|
artifactory "github.com/lusis/go-artifactory/src/artifactory.v401"
|
|
|
|
)
|
|
|
|
|
|
|
|
func New() backend.Backend {
|
|
|
|
s := &schema.Backend{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"username": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("ARTIFACTORY_USERNAME", nil),
|
|
|
|
Description: "Username",
|
|
|
|
},
|
|
|
|
"password": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("ARTIFACTORY_PASSWORD", nil),
|
|
|
|
Description: "Password",
|
|
|
|
},
|
|
|
|
"url": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("ARTIFACTORY_URL", nil),
|
|
|
|
Description: "Artfactory base URL",
|
|
|
|
},
|
|
|
|
"repo": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
Description: "The repository name",
|
|
|
|
},
|
|
|
|
"subpath": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
Description: "Path within the repository",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
b := &Backend{Backend: s}
|
|
|
|
b.Backend.ConfigureFunc = b.configure
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
type Backend struct {
|
|
|
|
*schema.Backend
|
|
|
|
|
|
|
|
client *ArtifactoryClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Backend) configure(ctx context.Context) error {
|
|
|
|
data := schema.FromContextBackendConfig(ctx)
|
|
|
|
|
|
|
|
userName := data.Get("username").(string)
|
|
|
|
password := data.Get("password").(string)
|
|
|
|
url := data.Get("url").(string)
|
|
|
|
repo := data.Get("repo").(string)
|
|
|
|
subpath := data.Get("subpath").(string)
|
|
|
|
|
|
|
|
clientConf := &artifactory.ClientConfig{
|
2019-11-06 23:18:33 +01:00
|
|
|
BaseURL: url,
|
|
|
|
Username: userName,
|
|
|
|
Password: password,
|
|
|
|
Transport: cleanhttp.DefaultPooledTransport(),
|
2018-03-20 22:17:14 +01:00
|
|
|
}
|
|
|
|
nativeClient := artifactory.NewClient(clientConf)
|
|
|
|
|
|
|
|
b.client = &ArtifactoryClient{
|
|
|
|
nativeClient: &nativeClient,
|
|
|
|
userName: userName,
|
|
|
|
password: password,
|
|
|
|
url: url,
|
|
|
|
repo: repo,
|
|
|
|
subpath: subpath,
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
func (b *Backend) Workspaces() ([]string, error) {
|
2018-10-31 16:45:03 +01:00
|
|
|
return nil, backend.ErrWorkspacesNotSupported
|
2018-03-20 22:17:14 +01:00
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
func (b *Backend) DeleteWorkspace(string) error {
|
2018-10-31 16:45:03 +01:00
|
|
|
return backend.ErrWorkspacesNotSupported
|
2018-03-20 22:17:14 +01:00
|
|
|
}
|
|
|
|
|
2020-08-11 17:43:01 +02:00
|
|
|
func (b *Backend) StateMgr(name string) (statemgr.Full, error) {
|
2018-03-20 22:17:14 +01:00
|
|
|
if name != backend.DefaultStateName {
|
2018-10-31 16:45:03 +01:00
|
|
|
return nil, backend.ErrWorkspacesNotSupported
|
2018-03-20 22:17:14 +01:00
|
|
|
}
|
|
|
|
return &remote.State{
|
|
|
|
Client: b.client,
|
|
|
|
}, nil
|
|
|
|
}
|