|
| 1 | +package client |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/meshcloud/terraform-provider-meshstack/client/internal" |
| 7 | + "github.com/meshcloud/terraform-provider-meshstack/client/types" |
| 8 | +) |
| 9 | + |
| 10 | +// Enums |
| 11 | + |
| 12 | +type MeshBuildingBlockType string |
| 13 | + |
| 14 | +const ( |
| 15 | + MeshBuildingBlockTypeTenantLevel MeshBuildingBlockType = "TENANT_LEVEL" |
| 16 | + MeshBuildingBlockTypeWorkspaceLevel MeshBuildingBlockType = "WORKSPACE_LEVEL" |
| 17 | +) |
| 18 | + |
| 19 | +// MeshBuildingBlockDefinition types |
| 20 | + |
| 21 | +type MeshBuildingBlockDefinitionMetadataBase struct { |
| 22 | + OwnedByWorkspace string `json:"ownedByWorkspace" tfsdk:"owned_by_workspace"` |
| 23 | + Tags map[string][]string `json:"tags" tfsdk:"tags"` |
| 24 | +} |
| 25 | + |
| 26 | +type MeshBuildingBlockDefinitionMetadataAdapter[String any] struct { |
| 27 | + MeshBuildingBlockDefinitionMetadataBase |
| 28 | + Uuid String `json:"uuid,omitempty" tfsdk:"uuid"` |
| 29 | + CreatedOn String `json:"createdOn,omitempty" tfsdk:"created_on"` |
| 30 | + MarkedForDeletionOn String `json:"markedForDeletionOn,omitempty" tfsdk:"marked_for_deletion_on"` |
| 31 | + MarkedForDeletionBy String `json:"markedForDeletionBy,omitempty" tfsdk:"marked_for_deletion_by"` |
| 32 | +} |
| 33 | + |
| 34 | +type MeshBuildingBlockDefinitionMetadata = MeshBuildingBlockDefinitionMetadataAdapter[*types.String] |
| 35 | + |
| 36 | +type MeshBuildingBlockDefinitionSpec struct { |
| 37 | + DisplayName string `json:"displayName" tfsdk:"display_name"` |
| 38 | + Symbol *string `json:"symbol,omitempty" tfsdk:"symbol"` |
| 39 | + TargetType MeshBuildingBlockType `json:"targetType" tfsdk:"target_type"` |
| 40 | + Description string `json:"description" tfsdk:"description"` |
| 41 | + Readme *string `json:"readme,omitempty" tfsdk:"readme"` |
| 42 | + SupportedPlatforms []string `json:"supportedPlatforms" tfsdk:"supported_platforms"` |
| 43 | + RunTransparency bool `json:"runTransparency" tfsdk:"run_transparency"` |
| 44 | + UseInLandingZonesOnly bool `json:"useInLandingZonesOnly" tfsdk:"use_in_landing_zones_only"` |
| 45 | + SupportURL *string `json:"supportUrl,omitempty" tfsdk:"support_url"` |
| 46 | + DocumentationURL *string `json:"documentationUrl,omitempty" tfsdk:"documentation_url"` |
| 47 | + NotificationSubscriberUsernames []string `json:"notificationSubscriberUsernames,omitempty" tfsdk:"notification_subscriber_usernames"` |
| 48 | +} |
| 49 | + |
| 50 | +type MeshBuildingBlockDefinitionStatusVersion struct { |
| 51 | + VersionUuid string `json:"versionUuid"` |
| 52 | + VersionNumber int64 `json:"versionNumber" ` |
| 53 | + State MeshBuildingBlockDefinitionVersionState `json:"state"` |
| 54 | +} |
| 55 | + |
| 56 | +type MeshBuildingBlockDefinitionStatus struct { |
| 57 | + UsageCount *int64 `json:"usageCount"` |
| 58 | + Versions []MeshBuildingBlockDefinitionStatusVersion `json:"versions"` |
| 59 | + LatestVersion int64 `json:"latestVersion"` |
| 60 | + LatestVersionUuid string `json:"latestVersionUuid" ` |
| 61 | + LatestReleasedVersion *int64 `json:"latestReleasedVersion"` |
| 62 | + LatestReleasedVersionUuid *string `json:"latestReleasedVersionUuid"` |
| 63 | +} |
| 64 | + |
| 65 | +type MeshBuildingBlockDefinition struct { |
| 66 | + ApiVersion string `json:"apiVersion"` |
| 67 | + Kind string `json:"kind"` |
| 68 | + Metadata MeshBuildingBlockDefinitionMetadata `json:"metadata" ` |
| 69 | + Spec MeshBuildingBlockDefinitionSpec `json:"spec"` |
| 70 | + Status *MeshBuildingBlockDefinitionStatus `json:"status,omitempty"` |
| 71 | +} |
| 72 | + |
| 73 | +type MeshBuildingBlockDefinitionClient interface { |
| 74 | + List(ctx context.Context, workspaceIdentifier *string) ([]MeshBuildingBlockDefinition, error) |
| 75 | + Read(ctx context.Context, uuid string) (*MeshBuildingBlockDefinition, error) |
| 76 | + Create(ctx context.Context, definition MeshBuildingBlockDefinition) (*MeshBuildingBlockDefinition, error) |
| 77 | + Update(ctx context.Context, uuid string, definition MeshBuildingBlockDefinition) (*MeshBuildingBlockDefinition, error) |
| 78 | + Delete(ctx context.Context, uuid string) error |
| 79 | +} |
| 80 | + |
| 81 | +type meshBuildingBlockDefinitionClient struct { |
| 82 | + meshObject internal.MeshObjectClient[MeshBuildingBlockDefinition] |
| 83 | +} |
| 84 | + |
| 85 | +func newBuildingBlockDefinitionClient(ctx context.Context, httpClient *internal.HttpClient) MeshBuildingBlockDefinitionClient { |
| 86 | + return meshBuildingBlockDefinitionClient{ |
| 87 | + meshObject: internal.NewMeshObjectClient[MeshBuildingBlockDefinition](ctx, httpClient, "v1-preview"), |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +func (c meshBuildingBlockDefinitionClient) List(ctx context.Context, workspaceIdentifier *string) ([]MeshBuildingBlockDefinition, error) { |
| 92 | + var options []internal.RequestOption |
| 93 | + if workspaceIdentifier != nil { |
| 94 | + options = append(options, internal.WithUrlQuery("workspaceIdentifier", *workspaceIdentifier)) |
| 95 | + } |
| 96 | + return c.meshObject.List(ctx, options...) |
| 97 | +} |
| 98 | + |
| 99 | +func (c meshBuildingBlockDefinitionClient) Read(ctx context.Context, uuid string) (*MeshBuildingBlockDefinition, error) { |
| 100 | + return c.meshObject.Get(ctx, uuid) |
| 101 | +} |
| 102 | + |
| 103 | +func (c meshBuildingBlockDefinitionClient) Create(ctx context.Context, definition MeshBuildingBlockDefinition) (*MeshBuildingBlockDefinition, error) { |
| 104 | + definition.Kind = c.meshObject.Kind |
| 105 | + definition.ApiVersion = c.meshObject.ApiVersion |
| 106 | + return c.meshObject.Post(ctx, definition) |
| 107 | +} |
| 108 | + |
| 109 | +func (c meshBuildingBlockDefinitionClient) Update(ctx context.Context, uuid string, definition MeshBuildingBlockDefinition) (*MeshBuildingBlockDefinition, error) { |
| 110 | + definition.Kind = c.meshObject.Kind |
| 111 | + definition.ApiVersion = c.meshObject.ApiVersion |
| 112 | + return c.meshObject.Put(ctx, uuid, definition) |
| 113 | +} |
| 114 | + |
| 115 | +func (c meshBuildingBlockDefinitionClient) Delete(ctx context.Context, uuid string) error { |
| 116 | + return c.meshObject.Delete(ctx, uuid) |
| 117 | +} |
0 commit comments