importexport

package
v1.180.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentTypeForFormat

func ContentTypeForFormat(format ExportFormat) string

ContentTypeForFormat returns the MIME type for a given format

func FileExtensionForFormat

func FileExtensionForFormat(format ExportFormat) string

FileExtensionForFormat returns the file extension for a given format

Types

type ExportFormat

type ExportFormat string

ExportFormat defines the export format

const (
	// ExportFormatYAML exports as YAML
	ExportFormatYAML ExportFormat = "yaml"
	// ExportFormatTOML exports as TOML
	ExportFormatTOML ExportFormat = "toml"
	// ExportFormatJSON exports as JSON
	ExportFormatJSON ExportFormat = "json"
)

type ExportOptions

type ExportOptions struct {
	Format         ExportFormat // Output format
	IncludeSecrets bool         // Include webhook secrets in export
	StatusFilter   []string     // Filter by status (active, paused, etc.)
	IncludeTypes   []string     // Include only specified types (schedules, webhooks)
}

ExportOptions contains options for export operations

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter handles exporting of team resources

func NewExporter

func NewExporter(
	scheduleManager schedule.Manager,
	webhookRepository repositories.WebhookRepository,
) *Exporter

NewExporter creates a new Exporter instance

func (*Exporter) Export

func (e *Exporter) Export(ctx context.Context, teamID, userID string, options ExportOptions) (*TeamResources, error)

Export exports team resources

type Formatter

type Formatter struct{}

Formatter handles formatting of export data

func NewFormatter

func NewFormatter() *Formatter

NewFormatter creates a new Formatter instance

func (*Formatter) Format

func (f *Formatter) Format(resources *TeamResources, format ExportFormat, writer io.Writer) error

Format formats TeamResources to the specified format

func (*Formatter) FormatJSON

func (f *Formatter) FormatJSON(resources *TeamResources, writer io.Writer) error

FormatJSON formats as JSON

func (*Formatter) FormatTOML

func (f *Formatter) FormatTOML(resources *TeamResources, writer io.Writer) error

FormatTOML formats as TOML

func (*Formatter) FormatYAML

func (f *Formatter) FormatYAML(resources *TeamResources, writer io.Writer) error

FormatYAML formats as YAML

type GitHubConditionsImport

type GitHubConditionsImport struct {
	Events       []string `yaml:"events,omitempty" toml:"events,omitempty" json:"events,omitempty"`
	Actions      []string `yaml:"actions,omitempty" toml:"actions,omitempty" json:"actions,omitempty"`
	Branches     []string `yaml:"branches,omitempty" toml:"branches,omitempty" json:"branches,omitempty"`
	Repositories []string `yaml:"repositories,omitempty" toml:"repositories,omitempty" json:"repositories,omitempty"`
	Labels       []string `yaml:"labels,omitempty" toml:"labels,omitempty" json:"labels,omitempty"`
	Paths        []string `yaml:"paths,omitempty" toml:"paths,omitempty" json:"paths,omitempty"`
	BaseBranches []string `yaml:"base_branches,omitempty" toml:"base_branches,omitempty" json:"base_branches,omitempty"`
	Draft        *bool    `yaml:"draft,omitempty" toml:"draft,omitempty" json:"draft,omitempty"`
	Sender       []string `yaml:"sender,omitempty" toml:"sender,omitempty" json:"sender,omitempty"`
}

GitHubConditionsImport represents GitHub-specific trigger conditions for import/export

type GitHubConfigImport

type GitHubConfigImport struct {
	EnterpriseURL       string   `yaml:"enterprise_url,omitempty" toml:"enterprise_url,omitempty" json:"enterprise_url,omitempty"`
	AllowedEvents       []string `yaml:"allowed_events,omitempty" toml:"allowed_events,omitempty" json:"allowed_events,omitempty"`
	AllowedRepositories []string `yaml:"allowed_repositories,omitempty" toml:"allowed_repositories,omitempty" json:"allowed_repositories,omitempty"`
}

GitHubConfigImport represents GitHub-specific webhook configuration for import/export

type Handlers

type Handlers struct {
	// contains filtered or unexported fields
}

Handlers handles import/export endpoints

func NewHandlers

func NewHandlers(
	scheduleManager schedule.Manager,
	webhookRepository repositories.WebhookRepository,
) *Handlers

NewHandlers creates a new Handlers instance

func (*Handlers) ExportTeamResources

func (h *Handlers) ExportTeamResources(c echo.Context) error

ExportTeamResources handles GET /manage/:team_id

func (*Handlers) GetName

func (h *Handlers) GetName() string

GetName returns the name of this handler for logging

func (*Handlers) ImportTeamResources

func (h *Handlers) ImportTeamResources(c echo.Context) error

ImportTeamResources handles POST/PUT /manage/:team_id POST: Import with create mode (default) PUT: Import with upsert mode (default)

func (*Handlers) RegisterRoutes

func (h *Handlers) RegisterRoutes(e *echo.Echo, _ *app.Server) error

RegisterRoutes registers import/export routes Implements the app.CustomHandler interface

type ImportDetail

type ImportDetail struct {
	ResourceType string `json:"resource_type"` // "schedule" or "webhook"
	ResourceName string `json:"resource_name"`
	Action       string `json:"action"` // "created", "updated", "skipped", "failed"
	ID           string `json:"id,omitempty"`
	Status       string `json:"status"` // "success" or "error"
	Error        string `json:"error,omitempty"`
}

ImportDetail contains detailed information about a single resource import

type ImportMode

type ImportMode string

ImportMode defines the import behavior

const (
	// ImportModeCreate creates new resources only, fails if already exists
	ImportModeCreate ImportMode = "create"
	// ImportModeUpdate updates existing resources only, fails if not exists
	ImportModeUpdate ImportMode = "update"
	// ImportModeUpsert creates or updates resources as needed
	ImportModeUpsert ImportMode = "upsert"
)

type ImportOptions

type ImportOptions struct {
	DryRun        bool       // Only validate, don't create
	Mode          ImportMode // Import mode
	IDField       string     // Field to use for matching: "name" or "id"
	AllowPartial  bool       // Allow partial success
	RegenerateAll bool       // Regenerate all secrets
}

ImportOptions contains options for import operations

type ImportResourceSummary

type ImportResourceSummary struct {
	Created int `json:"created"`
	Updated int `json:"updated"`
	Skipped int `json:"skipped"`
	Failed  int `json:"failed"`
}

ImportResourceSummary contains summary statistics for a resource type

type ImportResult

type ImportResult struct {
	Success bool           `json:"success"`
	Summary ImportSummary  `json:"summary"`
	Details []ImportDetail `json:"details"`
	Errors  []string       `json:"errors,omitempty"`
}

ImportResult contains the results of an import operation

type ImportSummary

type ImportSummary struct {
	Schedules ImportResourceSummary `json:"schedules"`
	Webhooks  ImportResourceSummary `json:"webhooks"`
}

ImportSummary contains summary statistics for each resource type

type Importer

type Importer struct {
	// contains filtered or unexported fields
}

Importer handles importing of team resources

func NewImporter

func NewImporter(
	scheduleManager schedule.Manager,
	webhookRepository repositories.WebhookRepository,
) *Importer

NewImporter creates a new Importer instance

func (*Importer) Import

func (i *Importer) Import(ctx context.Context, resources *TeamResources, userID string, options ImportOptions) (*ImportResult, error)

Import imports team resources

type JSONPathConditionImport

type JSONPathConditionImport struct {
	Path     string      `yaml:"path" toml:"path" json:"path"`
	Operator string      `yaml:"operator" toml:"operator" json:"operator"`
	Value    interface{} `yaml:"value" toml:"value" json:"value"`
}

JSONPathConditionImport represents a JSONPath condition for import/export

type Parser

type Parser struct{}

Parser handles parsing of import files in various formats

func NewParser

func NewParser() *Parser

NewParser creates a new Parser instance

func (*Parser) Parse

func (p *Parser) Parse(data []byte, contentType string) (*TeamResources, error)

Parse parses the input data and returns TeamResources It auto-detects the format based on content type or content

func (*Parser) ParseJSON

func (p *Parser) ParseJSON(data []byte) (*TeamResources, error)

ParseJSON parses JSON data

func (*Parser) ParseTOML

func (p *Parser) ParseTOML(data []byte) (*TeamResources, error)

ParseTOML parses TOML data

func (*Parser) ParseYAML

func (p *Parser) ParseYAML(data []byte) (*TeamResources, error)

ParseYAML parses YAML data

type ResourceMetadata

type ResourceMetadata struct {
	// TeamID in the format "org-team" (e.g., "myorg-backend-team")
	TeamID      string `yaml:"team_id" toml:"team_id" json:"team_id"`
	Description string `yaml:"description,omitempty" toml:"description,omitempty" json:"description,omitempty"`
}

ResourceMetadata contains metadata about the team resources

type ScheduleImport

type ScheduleImport struct {
	Name          string              `yaml:"name" toml:"name" json:"name"`
	Status        string              `yaml:"status,omitempty" toml:"status,omitempty" json:"status,omitempty"`
	ScheduledAt   *time.Time          `yaml:"scheduled_at,omitempty" toml:"scheduled_at,omitempty" json:"scheduled_at,omitempty"`
	CronExpr      string              `yaml:"cron_expr,omitempty" toml:"cron_expr,omitempty" json:"cron_expr,omitempty"`
	Timezone      string              `yaml:"timezone,omitempty" toml:"timezone,omitempty" json:"timezone,omitempty"`
	SessionConfig SessionConfigImport `yaml:"session_config" toml:"session_config" json:"session_config"`
}

ScheduleImport represents a schedule for import/export

type SessionConfigImport

type SessionConfigImport struct {
	Environment map[string]string    `yaml:"environment,omitempty" toml:"environment,omitempty" json:"environment,omitempty"`
	Tags        map[string]string    `yaml:"tags,omitempty" toml:"tags,omitempty" json:"tags,omitempty"`
	Params      *SessionParamsImport `yaml:"params,omitempty" toml:"params,omitempty" json:"params,omitempty"`
}

SessionConfigImport represents session configuration for import/export

type SessionParamsImport

type SessionParamsImport struct {
	InitialMessage         string `yaml:"initial_message,omitempty" toml:"initial_message,omitempty" json:"initial_message,omitempty"`
	InitialMessageTemplate string `yaml:"initial_message_template,omitempty" toml:"initial_message_template,omitempty" json:"initial_message_template,omitempty"`
	GitHubToken            string `yaml:"github_token,omitempty" toml:"github_token,omitempty" json:"github_token,omitempty"`
}

SessionParamsImport represents session parameters for import/export

type TeamResources

type TeamResources struct {
	APIVersion string           `yaml:"apiVersion" toml:"api_version" json:"apiVersion"`
	Kind       string           `yaml:"kind" toml:"kind" json:"kind"`
	Metadata   ResourceMetadata `yaml:"metadata" toml:"metadata" json:"metadata"`
	Schedules  []ScheduleImport `yaml:"schedules,omitempty" toml:"schedules,omitempty" json:"schedules,omitempty"`
	Webhooks   []WebhookImport  `yaml:"webhooks,omitempty" toml:"webhooks,omitempty" json:"webhooks,omitempty"`
}

TeamResources represents the root structure for team resource import/export

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator validates imported resources

func NewValidator

func NewValidator() *Validator

NewValidator creates a new Validator instance

func (*Validator) Validate

func (v *Validator) Validate(resources *TeamResources) error

Validate validates the entire TeamResources structure

func (*Validator) ValidateGitHubConditions

func (v *Validator) ValidateGitHubConditions(conditions GitHubConditionsImport) error

ValidateGitHubConditions validates GitHub conditions

func (*Validator) ValidateGitHubConfig

func (v *Validator) ValidateGitHubConfig(config GitHubConfigImport) error

ValidateGitHubConfig validates GitHub configuration

func (*Validator) ValidateJSONPathCondition

func (v *Validator) ValidateJSONPathCondition(condition JSONPathConditionImport) error

ValidateJSONPathCondition validates a JSONPath condition

func (*Validator) ValidateMetadata

func (v *Validator) ValidateMetadata(metadata ResourceMetadata) error

ValidateMetadata validates the metadata section

func (*Validator) ValidateSchedule

func (v *Validator) ValidateSchedule(schedule ScheduleImport) error

ValidateSchedule validates a single schedule

func (*Validator) ValidateSessionConfig

func (v *Validator) ValidateSessionConfig(config SessionConfigImport) error

ValidateSessionConfig validates session configuration

func (*Validator) ValidateTrigger

func (v *Validator) ValidateTrigger(trigger WebhookTriggerImport) error

ValidateTrigger validates a webhook trigger

func (*Validator) ValidateTriggerConditions

func (v *Validator) ValidateTriggerConditions(conditions WebhookTriggerConditionsImport) error

ValidateTriggerConditions validates trigger conditions

func (*Validator) ValidateWebhook

func (v *Validator) ValidateWebhook(webhook WebhookImport) error

ValidateWebhook validates a single webhook

type WebhookImport

type WebhookImport struct {
	Name            string                 `yaml:"name" toml:"name" json:"name"`
	Status          string                 `yaml:"status,omitempty" toml:"status,omitempty" json:"status,omitempty"`
	WebhookType     string                 `yaml:"webhook_type" toml:"webhook_type" json:"webhook_type"`
	Secret          string                 `yaml:"secret,omitempty" toml:"secret,omitempty" json:"secret,omitempty"`
	SignatureHeader string                 `yaml:"signature_header,omitempty" toml:"signature_header,omitempty" json:"signature_header,omitempty"`
	SignatureType   string                 `yaml:"signature_type,omitempty" toml:"signature_type,omitempty" json:"signature_type,omitempty"`
	MaxSessions     int                    `yaml:"max_sessions,omitempty" toml:"max_sessions,omitempty" json:"max_sessions,omitempty"`
	GitHub          *GitHubConfigImport    `yaml:"github,omitempty" toml:"github,omitempty" json:"github,omitempty"`
	Triggers        []WebhookTriggerImport `yaml:"triggers" toml:"triggers" json:"triggers"`
	SessionConfig   *SessionConfigImport   `yaml:"session_config,omitempty" toml:"session_config,omitempty" json:"session_config,omitempty"`
}

WebhookImport represents a webhook for import/export

type WebhookTriggerConditionsImport

type WebhookTriggerConditionsImport struct {
	GitHub     *GitHubConditionsImport   `yaml:"github,omitempty" toml:"github,omitempty" json:"github,omitempty"`
	JSONPath   []JSONPathConditionImport `yaml:"json_path,omitempty" toml:"json_path,omitempty" json:"json_path,omitempty"`
	GoTemplate string                    `yaml:"go_template,omitempty" toml:"go_template,omitempty" json:"go_template,omitempty"`
}

WebhookTriggerConditionsImport represents trigger conditions for import/export

type WebhookTriggerImport

type WebhookTriggerImport struct {
	Name          string                         `yaml:"name" toml:"name" json:"name"`
	Priority      int                            `yaml:"priority,omitempty" toml:"priority,omitempty" json:"priority,omitempty"`
	Enabled       bool                           `yaml:"enabled" toml:"enabled" json:"enabled"`
	Conditions    WebhookTriggerConditionsImport `yaml:"conditions" toml:"conditions" json:"conditions"`
	SessionConfig *SessionConfigImport           `yaml:"session_config,omitempty" toml:"session_config,omitempty" json:"session_config,omitempty"`
	StopOnMatch   bool                           `yaml:"stop_on_match,omitempty" toml:"stop_on_match,omitempty" json:"stop_on_match,omitempty"`
}

WebhookTriggerImport represents a webhook trigger for import/export

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL