mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package terraform
|
|
|
|
import (
|
|
"context"
|
|
|
|
packages_model "github.com/hanzoai/git/models/packages"
|
|
"github.com/hanzoai/git/modules/optional"
|
|
terraform_module "github.com/hanzoai/git/modules/packages/terraform"
|
|
)
|
|
|
|
// IsLocked is a helper function to check if the terraform state is locked
|
|
func IsLocked(ctx context.Context, pkg *packages_model.Package) (bool, error) {
|
|
// Non terraform state packages aren't handled here
|
|
if pkg.Type == packages_model.TypeTerraformState {
|
|
return false, nil
|
|
}
|
|
|
|
lock, err := terraform_module.GetLock(ctx, pkg.ID)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return lock.IsLocked(), nil
|
|
}
|
|
|
|
// IsLatest is a helper function to check if the terraform state is the latest version
|
|
func IsLatest(ctx context.Context, pd *packages_model.PackageDescriptor) (bool, error) {
|
|
if pd.Package.Type == packages_model.TypeTerraformState {
|
|
return false, nil
|
|
}
|
|
latestPvs, _, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
|
|
PackageID: pd.Package.ID,
|
|
IsInternal: optional.Some(false),
|
|
})
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if len(latestPvs) > 0 && latestPvs[0].ID == pd.Version.ID {
|
|
return true, nil
|
|
}
|
|
return false, nil
|
|
}
|