Documentation
¶
Index ¶
- Constants
- Variables
- func BlueprintWithRelations(bp api.Blueprint, kept map[string]interface{}) api.Blueprint
- func BuildExistingBlueprintsSet(additionalExisting []string) map[string]bool
- func CleanActionForCreate(action api.Action) api.Action
- func CleanFolderForCreate(folder api.Folder) api.Folder
- func CleanPageForCreate(page api.Page) api.Page
- func CleanPageForCreateNoNav(page api.Page) api.Page
- func CleanPageForUpdate(page api.Page) api.Page
- func CleanPageForUpdateNoNav(page api.Page) api.Page
- func CommonSystemBlueprints() []string
- func CreateBlueprintWithRelations(identifier string, relations map[string]interface{}) api.Blueprint
- func DescribeSidebarPipeline(steps []SidebarPipelineStep) []string
- func ExtractDependentFields(bp api.Blueprint) map[string]interface{}
- func ExtractEntityRelations(entity api.Entity) map[string]interface{}
- func ExtractRelations(bp api.Blueprint) map[string]interface{}
- func FlattenLevels(levels [][]api.Blueprint) []api.Blueprint
- func GetAllDependencies(bp api.Blueprint) []string
- func HasEntityRelations(entity api.Entity) bool
- func IsAdditionalPropertyError(err error) bool
- func IsAfterItemNotInParent(err error) bool
- func IsAgentIdentifierError(err error) bool
- func IsInvalidPermissionsError(err error) bool
- func IsRelationError(err error) bool
- func IsSidebarParentNotFound(err error) bool
- func IsSystemBlueprint(identifier string) bool
- func MergeWidgetAgentIdentifiers(newWidgets, existingWidgets []interface{}) []interface{}
- func ParseInvalidPermissionFields(err error) (relations, properties []string)
- func PartitionBlueprintRelationsRuleResultTarget(rels map[string]interface{}) (kept map[string]interface{}, ignoredKeys []string)
- func SanitizePermissions(perms api.Permissions, invalidRelations, invalidProperties []string) api.Permissions
- func SeparateSystemBlueprints(blueprints []api.Blueprint) (nonSystem, system []api.Blueprint)
- func SortFoldersByAfterLevels(folders []api.Folder) [][]api.Folder
- func SortPagesByAfterDeps(pages []api.Page) []api.Page
- func StripDependentFields(bp api.Blueprint) api.Blueprint
- func StripEntityRelations(entity api.Entity) api.Entity
- func StripRelations(bp api.Blueprint) api.Blueprint
- func TopologicalSort(blueprints []api.Blueprint, existingBlueprints map[string]bool) ([][]api.Blueprint, []api.Blueprint)
- func TopologicalSortAggProps(storedAggProps map[string]map[string]interface{}) [][]string
- func TopologicalSortOwnership(blueprints []api.Blueprint) ([][]api.Blueprint, []api.Blueprint)
- func ValidateAllDependencies(bp api.Blueprint, existingBlueprints map[string]bool) []string
- func ValidateRelationTargets(bp api.Blueprint, existingBlueprints map[string]bool) []string
- type BatchProcessor
- type BatchResult
- type DiffComparer
- type DiffResult
- type ErrorCategory
- type ErrorCollector
- func (ec *ErrorCollector) Add(err error, resourceType, resourceID string)
- func (ec *ErrorCollector) AddImportError(ie *ImportError)
- func (ec *ErrorCollector) All() []*ImportError
- func (ec *ErrorCollector) Clear()
- func (ec *ErrorCollector) Count() int
- func (ec *ErrorCollector) CountByCategory(cat ErrorCategory) int
- func (ec *ErrorCollector) GetByCategory(cat ErrorCategory) []*ImportError
- func (ec *ErrorCollector) GetByResource(resourceType string) []*ImportError
- func (ec *ErrorCollector) GetRetryable() []*ImportError
- func (ec *ErrorCollector) HasErrors() bool
- func (ec *ErrorCollector) Summary(maxExamplesPerCategory int) string
- func (ec *ErrorCollector) ToStringSlice() []string
- type ImportError
- type Importer
- type Loader
- type Module
- type Options
- type PermissionsChange
- type ProgressCallback
- type Result
- type SidebarPipelineOperation
- type SidebarPipelineStep
- type ValidationWarning
- type WorkerPool
Constants ¶
const ( BlueprintConcurrency = 5 EntityConcurrency = 20 DefaultConcurrency = 10 )
Concurrency limits for different resource types
const RuleResultTargetRelationType = "rule_result_target"
RuleResultTargetRelationType is the Port blueprint relation type for scorecard rule result catalog targets.
Variables ¶
var DependentFields = []string{
"mirrorProperties",
"calculationProperties",
"aggregationProperties",
"ownership",
}
DependentFields are blueprint fields that may reference other blueprints. Note: "relations" is NOT included because the relation schema must be created with the blueprint - you can't add relations to a blueprint after creation. The topological sort ensures relation targets exist before blueprint creation.
Functions ¶
func BlueprintWithRelations ¶ added in v0.2.10
BlueprintWithRelations returns a shallow copy of bp with relations replaced by kept (or relations removed if kept is nil or empty).
func BuildExistingBlueprintsSet ¶ added in v0.1.3
BuildExistingBlueprintsSet creates a set of blueprint identifiers that are considered "existing". This includes system blueprints and any explicitly provided identifiers.
func CleanActionForCreate ¶ added in v0.1.11
CleanActionForCreate returns a copy of the action with audit fields removed.
func CleanFolderForCreate ¶ added in v0.1.15
func CleanPageForCreate ¶ added in v0.1.11
CleanPageForCreate returns a copy of page with audit/internal fields removed. Sidebar placement fields are preserved, but requiredQueryParams is stripped because Port rejects it for some page types on create.
func CleanPageForCreateNoNav ¶ added in v0.1.11
CleanPageForCreateNoNav is like CleanPageForCreate but also strips navigation fields (after, sidebar, parent, section, requiredQueryParams). Used as a fallback when the target org is missing the sidebar parent.
func CleanPageForUpdate ¶ added in v0.1.11
CleanPageForUpdate returns a copy of page with audit/internal fields and `type` removed. Navigation fields are kept so Port can move the page to the correct sidebar position, except requiredQueryParams and sidebar which are stripped by default because Port rejects them for some page types on update. Nav fields that are nil/null are also stripped — sending null would clear the page's existing navigation context in Port.
func CleanPageForUpdateNoNav ¶ added in v0.1.12
CleanPageForUpdateNoNav is the fallback for CleanPageForUpdate when Port rejects the update because the parent page doesn't exist in the target org.
func CommonSystemBlueprints ¶ added in v0.1.3
func CommonSystemBlueprints() []string
CommonSystemBlueprints returns identifiers of commonly available system blueprints.
func CreateBlueprintWithRelations ¶
func CreateBlueprintWithRelations(identifier string, relations map[string]interface{}) api.Blueprint
CreateBlueprintWithRelations creates a blueprint payload with only the relations field. This is used for the second pass update.
func DescribeSidebarPipeline ¶ added in v0.1.15
func DescribeSidebarPipeline(steps []SidebarPipelineStep) []string
func ExtractDependentFields ¶ added in v0.1.3
ExtractDependentFields extracts all dependent fields from a blueprint. Returns a map of field name to field value for fields that were present.
func ExtractEntityRelations ¶ added in v0.1.3
ExtractEntityRelations extracts the relations field from an entity.
func ExtractRelations ¶
ExtractRelations extracts the relations field from a blueprint.
func FlattenLevels ¶ added in v0.1.3
FlattenLevels converts leveled blueprints to a flat slice in dependency order.
func GetAllDependencies ¶ added in v0.1.3
GetAllDependencies extracts all blueprint identifiers that this blueprint depends on. This includes targets from relations, mirrorProperties, calculationProperties, and aggregationProperties.
func HasEntityRelations ¶ added in v0.1.3
HasEntityRelations checks if an entity has any relation values set.
func IsAdditionalPropertyError ¶ added in v0.1.13
IsAdditionalPropertyError is the exported form for use by the migrate package.
func IsAfterItemNotInParent ¶ added in v0.1.11
IsAfterItemNotInParent returns true when Port rejects page creation because the `after` sibling item doesn't exist inside the specified parent folder.
func IsAgentIdentifierError ¶ added in v0.1.11
IsAgentIdentifierError returns true when the Port API rejects a request because a widget is missing the required agentIdentifier field.
func IsInvalidPermissionsError ¶ added in v0.2.18
IsInvalidPermissionsError is the exported form for use by the migrate package.
func IsRelationError ¶
IsRelationError checks if an error is related to missing relation targets. This detects common error patterns from the Port API when a relation target doesn't exist.
func IsSidebarParentNotFound ¶ added in v0.1.11
IsSidebarParentNotFound is the exported form for use by the migrate package.
func IsSystemBlueprint ¶ added in v0.1.3
IsSystemBlueprint returns true if the blueprint identifier indicates a system blueprint. System blueprints start with underscore (_user, _team, _rule, etc.)
func MergeWidgetAgentIdentifiers ¶ added in v0.1.11
func MergeWidgetAgentIdentifiers(newWidgets, existingWidgets []interface{}) []interface{}
MergeWidgetAgentIdentifiers copies agentIdentifier values from existing widgets into new widgets so that Port's required-field validation passes.
func ParseInvalidPermissionFields ¶ added in v0.2.18
ParseInvalidPermissionFields extracts the invalidRelations and invalidProperties arrays from an invalid_permissions API error. Returns nil slices when the error is not parseable or not an invalid_permissions error.
func PartitionBlueprintRelationsRuleResultTarget ¶ added in v0.2.10
func PartitionBlueprintRelationsRuleResultTarget(rels map[string]interface{}) (kept map[string]interface{}, ignoredKeys []string)
PartitionBlueprintRelationsRuleResultTarget splits blueprint relations into kept vs ignored. A relation is ignored when its definition map has type rule_result_target (Port-managed). ignoredKeys is sorted lexicographically for stable tests and CLI output.
func SanitizePermissions ¶ added in v0.2.18
func SanitizePermissions(perms api.Permissions, invalidRelations, invalidProperties []string) api.Permissions
SanitizePermissions returns a deep copy of perms with the named relation and property keys removed. Invalid relations are stripped from top-level keys and from entities.updateRelations; invalid properties are stripped from top-level keys and from entities.updateProperties.
func SeparateSystemBlueprints ¶ added in v0.1.3
SeparateSystemBlueprints splits blueprints into system and non-system blueprints.
func SortFoldersByAfterLevels ¶ added in v0.1.15
func SortPagesByAfterDeps ¶ added in v0.1.13
SortPagesByAfterDeps is the exported version of sortPagesByAfterDeps for use by migrate.
func StripDependentFields ¶ added in v0.1.3
StripDependentFields creates a copy of the blueprint without any dependent fields.
func StripEntityRelations ¶ added in v0.1.3
StripEntityRelations creates a copy of the entity without the relations field.
func StripRelations ¶
StripRelations creates a copy of the blueprint without the relations field.
func TopologicalSort ¶ added in v0.1.3
func TopologicalSort(blueprints []api.Blueprint, existingBlueprints map[string]bool) ([][]api.Blueprint, []api.Blueprint)
TopologicalSort sorts blueprints in dependency order using Kahn's algorithm. Returns blueprints grouped by dependency level (level 0 has no dependencies, etc.) Also returns any blueprints involved in cycles (which couldn't be sorted).
func TopologicalSortAggProps ¶ added in v0.2.7
TopologicalSortAggProps sorts blueprint IDs by their cross-blueprint aggregation property dependencies. If blueprint A has an agg prop that targets blueprint B and references a property that is itself an agg prop on B, A must run after B. Returns levels where blueprints in the same level can be applied concurrently.
func TopologicalSortOwnership ¶ added in v0.1.14
TopologicalSortOwnership sorts blueprints with ownership in the order their ownership can be applied. Blueprints with direct ownership are in the first level. Blueprints with inherited ownership depend on the target blueprint of the first relation segment in their ownership path.
func ValidateAllDependencies ¶ added in v0.1.3
ValidateAllDependencies checks if all dependencies exist in the provided blueprint set.
Types ¶
type BatchProcessor ¶ added in v0.1.3
type BatchProcessor[T any] struct { // contains filtered or unexported fields }
BatchProcessor processes items in batches with bounded concurrency.
func NewBatchProcessor ¶ added in v0.1.3
func NewBatchProcessor[T any](concurrency int) *BatchProcessor[T]
NewBatchProcessor creates a processor for batch operations.
func (*BatchProcessor[T]) Process ¶ added in v0.1.3
func (bp *BatchProcessor[T]) Process(items []T, fn func(T) error) []BatchResult[T]
Process processes all items using the provided function. Returns results in the order items were processed (not necessarily submission order).
func (*BatchProcessor[T]) ProcessWithContext ¶ added in v0.1.3
func (bp *BatchProcessor[T]) ProcessWithContext(ctx context.Context, items []T, fn func(T) error) []BatchResult[T]
ProcessWithContext processes items with context cancellation support.
func (*BatchProcessor[T]) SetProgressCallback ¶ added in v0.1.3
func (bp *BatchProcessor[T]) SetProgressCallback(cb func(processed, total int))
SetProgressCallback sets a callback for progress updates.
type BatchResult ¶ added in v0.1.3
BatchResult holds the result of processing a single item.
type DiffComparer ¶
type DiffComparer struct {
// contains filtered or unexported fields
}
DiffComparer compares import data with current organization state.
func NewDiffComparer ¶
func NewDiffComparer(client *api.Client) *DiffComparer
NewDiffComparer creates a new diff comparer.
func (*DiffComparer) Compare ¶
func (d *DiffComparer) Compare(ctx context.Context, importData *export.Data, opts Options) (*DiffResult, error)
Compare compares import data with current organization state.
type DiffResult ¶
type DiffResult struct {
BlueprintsToCreate []api.Blueprint
BlueprintsToUpdate []api.Blueprint
BlueprintsToSkip []api.Blueprint
EntitiesToCreate []api.Entity
EntitiesToUpdate []api.Entity
EntitiesToSkip []api.Entity
ScorecardsToCreate []api.Scorecard
ScorecardsToUpdate []api.Scorecard
ScorecardsToSkip []api.Scorecard
ActionsToCreate []api.Action
ActionsToUpdate []api.Action
ActionsToSkip []api.Action
TeamsToCreate []api.Team
TeamsToUpdate []api.Team
TeamsToSkip []api.Team
UsersToCreate []api.User
UsersToUpdate []api.User
UsersToSkip []api.User
PagesToCreate []api.Page
PagesToUpdate []api.Page
PagesToSkip []api.Page
IntegrationsToUpdate []api.Integration
IntegrationsToSkip []api.Integration
BlueprintPermissions []PermissionsChange
ActionPermissions []PermissionsChange
PagePermissions []PermissionsChange
}
DiffResult represents the result of comparing import data with current state.
func (*DiffResult) FilterData ¶
func (d *DiffResult) FilterData(original *export.Data) *export.Data
FilterData filters import data to only include resources that need to be created or updated.
type ErrorCategory ¶ added in v0.1.3
type ErrorCategory string
ErrorCategory represents the type of error encountered during import.
const ( // ErrDependency indicates a missing blueprint/entity reference. // These errors may resolve after dependencies are created. ErrDependency ErrorCategory = "DEPENDENCY" // ErrAuth indicates authentication or permission issues. ErrAuth ErrorCategory = "AUTH" // ErrBlueprintConfig indicates blueprint configuration prevents the operation. // E.g., inherited ownership enabled, protected blueprints, etc. ErrBlueprintConfig ErrorCategory = "BLUEPRINT_CONFIG" // ErrValidation indicates invalid data format or values. ErrValidation ErrorCategory = "VALIDATION" // ErrSchemaMismatch indicates entity data doesn't match blueprint schema. ErrSchemaMismatch ErrorCategory = "SCHEMA_MISMATCH" // ErrRateLimit indicates the API throttled the request. ErrRateLimit ErrorCategory = "RATE_LIMIT" // ErrNetwork indicates connection or network issues. ErrNetwork ErrorCategory = "NETWORK" // ErrConflict indicates the resource already exists. ErrConflict ErrorCategory = "CONFLICT" // ErrNotFound indicates the resource was not found. ErrNotFound ErrorCategory = "NOT_FOUND" // ErrServerError indicates the API returned a 5xx server-side error. ErrServerError ErrorCategory = "SERVER_ERROR" // ErrUnknown indicates an unexpected error. ErrUnknown ErrorCategory = "UNKNOWN" )
type ErrorCollector ¶ added in v0.1.3
type ErrorCollector struct {
// contains filtered or unexported fields
}
ErrorCollector collects and categorizes errors during import.
func NewErrorCollector ¶ added in v0.1.3
func NewErrorCollector() *ErrorCollector
NewErrorCollector creates a new error collector.
func (*ErrorCollector) Add ¶ added in v0.1.3
func (ec *ErrorCollector) Add(err error, resourceType, resourceID string)
Add adds an error to the collector.
func (*ErrorCollector) AddImportError ¶ added in v0.1.3
func (ec *ErrorCollector) AddImportError(ie *ImportError)
AddImportError adds a pre-categorized ImportError.
func (*ErrorCollector) All ¶ added in v0.1.3
func (ec *ErrorCollector) All() []*ImportError
All returns all collected errors.
func (*ErrorCollector) Clear ¶ added in v0.1.3
func (ec *ErrorCollector) Clear()
Clear removes all collected errors.
func (*ErrorCollector) Count ¶ added in v0.1.3
func (ec *ErrorCollector) Count() int
Count returns the total number of errors.
func (*ErrorCollector) CountByCategory ¶ added in v0.1.3
func (ec *ErrorCollector) CountByCategory(cat ErrorCategory) int
CountByCategory returns the count of errors for a category.
func (*ErrorCollector) GetByCategory ¶ added in v0.1.3
func (ec *ErrorCollector) GetByCategory(cat ErrorCategory) []*ImportError
GetByCategory returns errors for a specific category.
func (*ErrorCollector) GetByResource ¶ added in v0.1.3
func (ec *ErrorCollector) GetByResource(resourceType string) []*ImportError
GetByResource returns errors for a specific resource type.
func (*ErrorCollector) GetRetryable ¶ added in v0.1.3
func (ec *ErrorCollector) GetRetryable() []*ImportError
GetRetryable returns all errors that are retryable.
func (*ErrorCollector) HasErrors ¶ added in v0.1.3
func (ec *ErrorCollector) HasErrors() bool
HasErrors returns true if any errors were collected.
func (*ErrorCollector) Summary ¶ added in v0.1.3
func (ec *ErrorCollector) Summary(maxExamplesPerCategory int) string
Summary returns a human-readable summary of errors. Shows count + first N examples per category.
func (*ErrorCollector) ToStringSlice ¶ added in v0.1.3
func (ec *ErrorCollector) ToStringSlice() []string
ToStringSlice converts errors to a simple string slice (for backward compatibility).
type ImportError ¶ added in v0.1.3
type ImportError struct {
Category ErrorCategory
ResourceType string // "blueprint", "entity", "action", etc.
ResourceID string // identifier of the resource
Message string
Cause error
Retryable bool
}
ImportError represents a categorized error from an import operation.
func CategorizeError ¶ added in v0.1.3
func CategorizeError(err error, resourceType, resourceID string) *ImportError
CategorizeError analyzes an error and returns an ImportError with appropriate category.
func (*ImportError) Error ¶ added in v0.1.3
func (e *ImportError) Error() string
type Importer ¶
type Importer struct {
// contains filtered or unexported fields
}
Importer handles importing data to Port with proper dependency ordering.
func NewImporter ¶
NewImporter creates a new importer.
func (*Importer) SetLogCallback ¶ added in v0.1.16
func (*Importer) SetProgressCallback ¶ added in v0.1.3
func (i *Importer) SetProgressCallback(cb ProgressCallback)
SetProgressCallback sets the progress callback for the importer.
type Loader ¶
type Loader struct{}
Loader loads data from tar.gz or JSON files.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module handles importing data to Port.
type Options ¶
type Options struct {
InputPath string
DryRun bool
SkipEntities bool
SkipSystemBlueprints bool // skip _* blueprint schemas and their entities
IncludeRuleResults bool // include _rule_result system blueprint entities (included by default)
IncludeResources []string
ExcludeBlueprints []string // deep: exclude blueprint schema + all its resources
ExcludeBlueprintSchema []string // shallow: exclude only the blueprint schema, keep resources
Verbose bool
ShowPagesPipeline bool
ProgressCallback ProgressCallback
LogCallback func(string)
}
Options represents import options.
type PermissionsChange ¶ added in v0.1.7
type PermissionsChange struct {
Identifier string
Permissions api.Permissions
}
PermissionsChange represents a permissions update for a single resource.
type ProgressCallback ¶ added in v0.1.3
Options represents import options. ProgressCallback is called to report import progress. phase is the current phase name, current is the number of items processed, total is the total count.
type Result ¶
type Result struct {
Success bool
Message string
BlueprintsCreated int
BlueprintsUpdated int
EntitiesCreated int
EntitiesUpdated int
ScorecardsCreated int
ScorecardsUpdated int
ActionsCreated int
ActionsUpdated int
TeamsCreated int
TeamsUpdated int
UsersCreated int
UsersUpdated int
PagesCreated int
PagesUpdated int
IntegrationsUpdated int
BlueprintPermissionsUpdated int
ActionPermissionsUpdated int
PagePermissionsUpdated int
Errors []string
ErrorsByCategory map[string][]string // Categorized errors for verbose output
Warnings []ValidationWarning // Pre-import validation warnings
DiffResult *DiffResult
SidebarPipeline []string
// IgnoredRuleResultTargetRelationCount is how many _rule_result relations with type rule_result_target were omitted from API payloads.
IgnoredRuleResultTargetRelationCount int
// IgnoredRuleResultTargetRelationKeys lists relation identifiers omitted (sorted, unique).
IgnoredRuleResultTargetRelationKeys []string
}
Result represents the result of an import operation.
type SidebarPipelineOperation ¶ added in v0.1.15
type SidebarPipelineStep ¶ added in v0.1.15
type SidebarPipelineStep struct {
Operations []SidebarPipelineOperation
}
func PlanSidebarPipeline ¶ added in v0.1.15
func PlanSidebarPipeline(folders []api.Folder, pages []api.Page) []SidebarPipelineStep
type ValidationWarning ¶ added in v0.1.3
type ValidationWarning struct {
Type string // "cycle", "missing_dependency", "protected_resource", "orphaned_permission_field"
Message string
Details []string
}
ValidationWarning represents a pre-import validation warning.
type WorkerPool ¶ added in v0.1.3
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool provides bounded concurrency for parallel operations. Unlike errgroup.WithContext, individual task failures don't cancel other tasks.
func NewWorkerPool ¶ added in v0.1.3
func NewWorkerPool(limit int) *WorkerPool
NewWorkerPool creates a worker pool with the specified concurrency limit.
func (*WorkerPool) Go ¶ added in v0.1.3
func (p *WorkerPool) Go(task func())
Go submits a task to the worker pool. The task will run when a worker slot is available. Tasks run in separate goroutines and errors are handled by the task itself.
func (*WorkerPool) GoWithContext ¶ added in v0.1.3
func (p *WorkerPool) GoWithContext(ctx context.Context, task func())
GoWithContext submits a task that respects context cancellation. Returns immediately if context is already canceled.
func (*WorkerPool) Wait ¶ added in v0.1.3
func (p *WorkerPool) Wait()
Wait blocks until all submitted tasks complete.