feat: provider v0.1.9 — namespace hardcoded in client, removed from provider schema and all examples

This commit is contained in:
“Naeel”
2026-03-09 15:27:55 +04:00
parent 17d32fcb39
commit 5faec45a04
9 changed files with 23 additions and 41 deletions
+6 -3
View File
@@ -23,16 +23,19 @@ type Client struct {
httpClient *http.Client
endpoint string
token string
Namespace string // берётся из provider {}, пользователь не касается
// Namespace захардкодено = "default".
// TODO: изоляция пользователей — каждый токен привязан к своему namespace,
// провайдер получает его через GET /v1/whoami. Сейчас всё в одном ns для демо.
Namespace string
}
// New создаёт клиент. endpoint — базовый URL оператора (без trailing slash).
func New(endpoint, token, namespace string) *Client {
func New(endpoint, token string) *Client {
return &Client{
httpClient: &http.Client{Timeout: 30 * time.Second},
endpoint: endpoint,
token: token,
Namespace: namespace,
Namespace: "default",
}
}
@@ -28,9 +28,8 @@ type SlessProvider struct {
// SlessProviderModel — конфигурация блока provider {} в .tf файле.
type SlessProviderModel struct {
Endpoint types.String `tfsdk:"endpoint"`
Token types.String `tfsdk:"token"`
Namespace types.String `tfsdk:"namespace"`
Endpoint types.String `tfsdk:"endpoint"`
Token types.String `tfsdk:"token"`
}
// New возвращает фабрику провайдера — точная копия паттерна nubes.
@@ -57,12 +56,6 @@ func (p *SlessProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp
Optional: true,
Sensitive: true,
},
// namespace — окружение/проект в кластере. Задаётся один раз здесь.
// В ресурсах (sless_function, sless_trigger, sless_job) namespace НЕ указывается.
"namespace": schema.StringAttribute{
MarkdownDescription: "Пространство имён (окружение). Задаётся один раз для всех ресурсов.",
Required: true,
},
},
}
}
@@ -94,9 +87,7 @@ func (p *SlessProvider) Configure(ctx context.Context, req provider.ConfigureReq
}
}
namespace := config.Namespace.ValueString()
c := client.New(endpoint, token, namespace)
c := client.New(endpoint, token)
resp.ResourceData = c
resp.DataSourceData = c
}
@@ -25,7 +25,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -323,12 +322,7 @@ func mapToStringMap(ctx context.Context, m types.Map) (map[string]string, diag.D
result := make(map[string]string, len(elements))
var diags diag.Diagnostics
for k, v := range elements {
sv, ok := v.(attr.Value)
if !ok {
diags.AddError("env_vars conversion", fmt.Sprintf("unexpected type for key %q", k))
continue
}
strVal, ok := sv.(types.String)
strVal, ok := v.(types.String)
if !ok {
diags.AddError("env_vars conversion", fmt.Sprintf("value for key %q is not a string", k))
continue