utils

package
v0.0.0-...-81b95c2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ReleaseSources = []GithubReleaseSource{
	{Type: ReleaseOlakeUI, Repo: "olake-ui", OnlyNewerReleases: true},
	{Type: ReleaseWorker, Repo: "olake-helm", OnlyNewerReleases: true},
	{Type: ReleaseOlakeHelm, Repo: "olake-helm"},
	{Type: ReleaseOlake, Repo: "olake", OnlyNewerReleases: true},
}

ReleaseSources defines the list of GitHub repositories to fetch releases from.

Functions

func AddFileToArchive

func AddFileToArchive(tarWriter *tar.Writer, filePath, nameInArchive string) error

addFileToArchive streams a file into the tar archive

func BindAndValidate

func BindAndValidate(c *gin.Context, target interface{}) error

func BuildReleasesResponse

func BuildReleasesResponse(currentVersion, olakeSourceVersion string, fetched map[ReleaseType][]*dto.ReleaseMetadataResponse) (*dto.ReleasesResponse, error)

BuildReleasesResponse builds the final releases response from fetched data. currentVersion is used for olake-ui and worker releases. olakeSourceVersion is used for olake source releases (minimum version from database).

func ConvertMBToBytes

func ConvertMBToBytes(sizeMB int64) string

func CreateDirectory

func CreateDirectory(dirPath string, perm os.FileMode) error

CreateDirectory creates a directory with the specified permissions if it doesn't exist

func Decrypt

func Decrypt(encryptedText string) (string, error)

func Encrypt

func Encrypt(plaintext string) (string, error)

func ErrorResponse

func ErrorResponse(c *gin.Context, status int, message string, err error)

func ExistsInArray

func ExistsInArray[T comparable](arr []T, value T) bool

func ExtractJobIDFromWorkflowID

func ExtractJobIDFromWorkflowID(workflowID, projectID string) (int, bool)

ExtractJobIDFromWorkflowID extracts the JobID from Temporal workflow IDs created by this system.

Expected workflow ID shapes: - sync-<projectID>-<jobID> - sync-<projectID>-<jobID>-<suffix>

projectID itself can contain '-', so we match the exact prefix and then parse the leading integer.

func FetchAndBuildReleaseMetadata

func FetchAndBuildReleaseMetadata(ctx context.Context, repo, releaseType string, limit int) ([]*dto.ReleaseMetadataResponse, error)

FetchAndBuildReleaseMetadata fetches GitHub releases and converts them into normalized, sorted ReleaseMetadataResponse objects.

func FetchFeaturesJSON

func FetchFeaturesJSON(ctx context.Context) ([]*dto.ReleaseMetadataResponse, error)

FetchFeaturesJSON fetches the features.json file from GitHub.

func GetAndValidateLogBaseDir

func GetAndValidateLogBaseDir(filePath string) (string, error)

GetAndValidateLogBaseDir returns the base directory path for log files based on the SHA256 hash of the filePath (workflow ID) and validates it exists

func GetAndValidateSyncDir

func GetAndValidateSyncDir(baseDir string) (string, string, error)

GetAndValidateSyncDir returns the logs directory and sync_* folder name under it

func GetAppEnv

func GetAppEnv() string

GetAppEnv returns the application environment in normalized format Supported values: development, production

func GetCachedImages

func GetCachedImages(ctx context.Context) ([]string, error)

GetCachedImages retrieves locally cached Docker images

func GetCurrentUserID

func GetCurrentUserID(c *gin.Context) *int

func GetCustomDriverVersion

func GetCustomDriverVersion() string

CustomDriverVersion returns the custom driver version used to test olake with olake-ui. Note: This is only for development/testing purposes. When a custom version is set, semver-based compatibility checks will bypassed.

func GetDriverImageTags

func GetDriverImageTags(ctx context.Context, imageName string, cachedTags bool) ([]string, string, error)

GetDriverImageTags returns image tags from ECR, Artifact Registry, or Docker Hub with fallback to cached images

func GetIDParam

func GetIDParam(c *gin.Context) (int, error)

func GetLogArchiveFilename

func GetLogArchiveFilename(jobID int, filePath string) (string, error)

GetLogArchiveFilename generates the filename for the log archive download

func GetProjectID

func GetProjectID(c *gin.Context) (string, error)

func GetWorkerEnvVars

func GetWorkerEnvVars() map[string]string

GetWorkerEnvVars returns the environment variables from the worker container.

func MarshalToString

func MarshalToString(v interface{}) (string, error)

func MergeReleaseDescriptions

func MergeReleaseDescriptions(primary *dto.ReleaseTypeData, primaryTitle string, secondary *dto.ReleaseTypeData, secondaryTitle string) *dto.ReleaseTypeData

MergeReleaseDescriptions merges secondary release notes into primary by version.

func NormalizeString

func NormalizeString(s string) string

NormalizeString converts a string to lowercase, trims leading and trailing spaces and replaces spaces with underscores

func ParseECRDetails

func ParseECRDetails(fullImageName string) (accountID, region, repoName string, err error)

ParseECRDetails extracts account ID, region, and repository name from ECR URI Example:

Input:  "123456789012.dkr.ecr.us-west-2.amazonaws.com/olakego/source-mysql:latest"
Output: accountID = "123456789012"
        region    = "us-west-2"
        repoName  = "olakego/source-mysql:latest"

func ParseGCRArtifactRegistryDetails

func ParseGCRArtifactRegistryDetails(fullImageName string) (project, location, repository, packageName string, err error)

ParseGCRArtifactRegistryDetails extracts project, location, repository, and package name from an Artifact Registry Docker image URI.

Example:

Input:  "us-docker.pkg.dev/my-project/my-repo/olakego/source-mysql:v1.0.0"
Output: project     = "my-project"
        location    = "us"
        repository  = "my-repo"
        packageName = "olakego/source-mysql"

The package name is URL-encoded for the API (e.g., "olakego%2Fsource-mysql")

func ReadLinesBackward

func ReadLinesBackward(f *os.File, startOffset int64, limit int, fileSize int64) ([]string, int64, bool, error)

ReadLinesBackward reads up to `limit` complete VALID log lines from file backwards starting at startOffset. Filters out empty lines, invalid JSON, and debug-level logs DURING reading. startOffset is treated as exclusive - we read lines that END BEFORE startOffset. Returns: valid lines (oldest->newest), newOffset (byte position before first returned line), hasMore, error.

func ReadLinesForward

func ReadLinesForward(f *os.File, startOffset int64, limit int, fileSize int64) ([]string, int64, bool, error)

ReadLinesForward reads up to `limit` complete VALID log lines from file forwards starting at startOffset. Filters out empty lines, invalid JSON, and debug-level logs DURING reading. startOffset is treated as inclusive - we start reading from exactly that position. Returns: valid lines (oldest->newest), newOffset (byte position after last returned line), hasMore, error.

func ReadLogs

func ReadLogs(mainLogDir string, cursor int64, limit int, direction string) (*dto.TaskLogsResponse, error)

ReadLogs reads logs from the given mainLogDir and returns structured log entries. Direction can be "older" or "newer". If cursor < 0, it tails from the end of the file. Returns a TaskLogsResponse-like struct: oldest->newest logs plus cursors and hasMore flags.

func RetryWithBackoff

func RetryWithBackoff(fn func() error, maxRetries int, initialDelay time.Duration) error

RetryWithBackoff retries a function with exponential backoff

func SetIfNotEmpty

func SetIfNotEmpty(m map[string]string, key, value string)

func StatusFromBindError

func StatusFromBindError(err error) int

func SuccessResponse

func SuccessResponse(c *gin.Context, message string, data interface{})

func Ternary

func Ternary(cond bool, a, b any) any

func ToCron

func ToCron(frequency string) string

ToCron converts a frequency string to a cron expression

func ULID

func ULID() string

func WriteFile

func WriteFile(filePath string, data []byte, perm os.FileMode) error

WriteFile writes data to a file, creating the directory if necessary

Types

type DockerHubTag

type DockerHubTag struct {
	Name string `json:"name"`
}

DockerHubTag represents a single tag from Docker Hub API response

type DockerHubTagsResponse

type DockerHubTagsResponse struct {
	Results []DockerHubTag `json:"results"`
}

DockerHubTagsResponse represents the response structure from Docker Hub tags API

type GitHubRelease

type GitHubRelease struct {
	TagName     string    `json:"tag_name"`
	Name        string    `json:"name"`
	Body        string    `json:"body"`
	PublishedAt time.Time `json:"published_at"`
	HTMLURL     string    `json:"html_url"`
	Prerelease  bool      `json:"prerelease"`
	Draft       bool      `json:"draft"`
}

GitHubRelease represents a release from GitHub API response.

type GithubReleaseSource

type GithubReleaseSource struct {
	Type              ReleaseType
	Repo              string
	OnlyNewerReleases bool
}

GithubReleaseSource represents a GitHub repository source for fetching releases. It defines the release type, repository name, and whether to filter only newer releases.

type LineWithPos

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

type LogEntry

type LogEntry struct {
	Level   string          `json:"level"`
	Time    time.Time       `json:"time"`
	Message json.RawMessage `json:"message"` // store raw JSON
}

LogEntry represents a log entry

type ReleaseType

type ReleaseType string

ReleaseType represents the type of release source.

const (
	ReleaseOlakeUI   ReleaseType = "olake_ui"
	ReleaseWorker    ReleaseType = "worker"
	ReleaseOlakeHelm ReleaseType = "olake_helm"
	ReleaseOlake     ReleaseType = "olake"
	ReleaseFeatures  ReleaseType = "features"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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