e1336c0c87
Resources renamed from artifactapi_remote to per-type: - artifactapi_remote_generic - artifactapi_remote_docker (with ban_tags) - artifactapi_remote_helm - artifactapi_remote_pypi - artifactapi_remote_npm - artifactapi_remote_rpm - artifactapi_remote_alpine - artifactapi_remote_puppet - artifactapi_remote_terraform (with releases_remote) - artifactapi_remote_goproxy Classification simplified: - patterns: paths to proxy (empty = all, acts as allowlist) - blocklist: paths to deny (checked first) - mutable_patterns: override provider auto-classification - immutable_patterns: override provider auto-classification - Provider handles mutability automatically per package type
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
|
"github.com/hashicorp/terraform-plugin-framework/provider"
|
|
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
)
|
|
|
|
var _ provider.Provider = &ArtifactAPIProvider{}
|
|
|
|
type ArtifactAPIProvider struct {
|
|
version string
|
|
}
|
|
|
|
type artifactAPIProviderModel struct {
|
|
Endpoint types.String `tfsdk:"endpoint"`
|
|
}
|
|
|
|
func New(version string) func() provider.Provider {
|
|
return func() provider.Provider {
|
|
return &ArtifactAPIProvider{version: version}
|
|
}
|
|
}
|
|
|
|
func (p *ArtifactAPIProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
|
|
resp.TypeName = "artifactapi"
|
|
resp.Version = p.version
|
|
}
|
|
|
|
func (p *ArtifactAPIProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
|
|
resp.Schema = schema.Schema{
|
|
Description: "Manage ArtifactAPI remotes and virtual repositories.",
|
|
Attributes: map[string]schema.Attribute{
|
|
"endpoint": schema.StringAttribute{
|
|
Description: "The ArtifactAPI server endpoint URL (e.g. https://artifactapi.example.com).",
|
|
Required: true,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (p *ArtifactAPIProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
|
|
var config artifactAPIProviderModel
|
|
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
|
|
if resp.Diagnostics.HasError() {
|
|
return
|
|
}
|
|
|
|
client := newAPIClient(config.Endpoint.ValueString())
|
|
resp.DataSourceData = client
|
|
resp.ResourceData = client
|
|
}
|
|
|
|
func (p *ArtifactAPIProvider) Resources(_ context.Context) []func() resource.Resource {
|
|
return []func() resource.Resource{
|
|
newRemoteResource("generic"),
|
|
newRemoteResource("docker"),
|
|
newRemoteResource("helm"),
|
|
newRemoteResource("pypi"),
|
|
newRemoteResource("npm"),
|
|
newRemoteResource("rpm"),
|
|
newRemoteResource("alpine"),
|
|
newRemoteResource("puppet"),
|
|
newRemoteResource("terraform"),
|
|
newRemoteResource("goproxy"),
|
|
NewVirtualResource,
|
|
}
|
|
}
|
|
|
|
func (p *ArtifactAPIProvider) DataSources(_ context.Context) []func() datasource.DataSource {
|
|
return []func() datasource.DataSource{
|
|
NewRemoteDataSource,
|
|
NewVirtualDataSource,
|
|
}
|
|
}
|