Skip to content

Commit

Permalink
Remove unneeded access funcs from Mod and Workspace (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidaguerre authored Oct 30, 2024
1 parent 2810241 commit d7decaf
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 67 deletions.
2 changes: 1 addition & 1 deletion inputvars/require_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ValueFromModFile terraform.ValueSourceType = 'M'

func CollectVariableValuesFromModRequire(m *modconfig.Mod, lock *versionmap.WorkspaceLock) (terraform.InputValues, error) {
res := make(terraform.InputValues)
if require := m.GetRequire(); require != nil {
if require := m.Require; require != nil {
for _, depModConstraint := range require.Mods {
if args := depModConstraint.Args; args != nil {
// find the loaded dep mod which satisfies this constraint
Expand Down
2 changes: 1 addition & 1 deletion inputvars/unparsed_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func getUndeclaredVariableError(name string, variablesMap *modconfig.ModVariable

for _, m := range variablesMap.Mod.GetModResources().GetMods() {
if m.GetShortName() == parsedVarName.Mod {
return fmt.Sprintf("\"%s\": Dependency mod \"%s\" has no variable \"%s\"", name, m.GetDependencyName(), parsedVarName.Name)
return fmt.Sprintf("\"%s\": Dependency mod \"%s\" has no variable \"%s\"", name, m.DependencyName, parsedVarName.Name)
// so it is a dependency mod
}
}
Expand Down
12 changes: 6 additions & 6 deletions load_mod/load_mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ func loadModDefinition(modPath string, parseCtx *parse.ModParseContext) (*modcon
}

func loadModDependenciesAsync(ctx context.Context, parent *modconfig.Mod, parseCtx *parse.ModParseContext) error {
utils.LogTime(fmt.Sprintf("loadModDependenciesAsync for %s start", parent.GetModPath()))
defer utils.LogTime(fmt.Sprintf("loadModDependenciesAsync for %s end", parent.GetModPath()))
utils.LogTime(fmt.Sprintf("loadModDependenciesAsync for %s start", parent.ModPath))
defer utils.LogTime(fmt.Sprintf("loadModDependenciesAsync for %s end", parent.ModPath))

parentRequire := parent.GetRequire()
parentRequire := parent.Require
if parentRequire == nil || len(parentRequire.Mods) == 0 {
return nil
}
Expand Down Expand Up @@ -185,11 +185,11 @@ func loadModDependency(ctx context.Context, requiredModVersion *modconfig.ModVer
}

func loadModResources(ctx context.Context, mod *modconfig.Mod, parseCtx *parse.ModParseContext) (*modconfig.Mod, error_helpers.ErrorAndWarnings) {
utils.LogTime(fmt.Sprintf("loadModResources %s start", mod.GetModPath()))
defer utils.LogTime(fmt.Sprintf("loadModResources %s end", mod.GetModPath()))
utils.LogTime(fmt.Sprintf("loadModResources %s start", mod.ModPath))
defer utils.LogTime(fmt.Sprintf("loadModResources %s end", mod.ModPath))

// get the source files
sourcePaths, err := getSourcePaths(ctx, mod.GetModPath(), parseCtx.ListOptions)
sourcePaths, err := getSourcePaths(ctx, mod.ModPath, parseCtx.ListOptions)
if err != nil {
slog.Warn("LoadMod: failed to get mod file paths", "error", err)
return nil, error_helpers.NewErrorsAndWarning(err)
Expand Down
2 changes: 1 addition & 1 deletion load_mod/load_mod_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func getInputVariables(parseCtx *parse.ModParseContext, variableMap *modconfig.M

// get mod and mod path from run context
mod := parseCtx.CurrentMod
path := mod.GetModPath()
path := mod.ModPath

var inputValuesUnparsed, err = inputvars.CollectVariableValues(path, variableFileArgs, variableArgs, parseCtx.CurrentMod.ShortName)
if err != nil {
Expand Down
28 changes: 1 addition & 27 deletions modconfig/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (m *Mod) CacheKey() string {
func CreateDefaultMod(modPath string) *Mod {
m := NewMod(defaultModName, modPath, hcl.Range{})
folderName := filepath.Base(modPath)
m.SetTitle(folderName)
m.Title = &folderName
return m
}

Expand Down Expand Up @@ -429,29 +429,3 @@ func (m *Mod) GetDefaultConnectionString(evalContext *hcl.EvalContext) (string,
// if no database is set on mod, use the default steampipe connection
return constants.DefaultSteampipeConnectionString, nil
}

func (m *Mod) GetDependencyName() string {
return m.DependencyName
}
func (m *Mod) GetDependencyPath() *string {
return m.DependencyPath
}

func (m *Mod) GetModPath() string {
return m.ModPath
}

func (m *Mod) GetRequire() *Require {
return m.Require
}

func (m *Mod) SetRequire(require *Require) {
m.Require = require
}

func (m *Mod) SetTitle(title string) {
m.Title = &title
}
func (m *Mod) GetVersion() *DependencyVersion {
return m.Version
}
2 changes: 1 addition & 1 deletion modconfig/mod_tree_item_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (b *ModTreeItemImpl) GetListData() *printers.RowData {
}

func (b *ModTreeItemImpl) IsDependencyResource() bool {
return b.GetMod().GetDependencyPath() != nil
return b.GetMod().DependencyPath != nil
}

func (b *ModTreeItemImpl) GetNestedStructs() []CtyValueProvider {
Expand Down
2 changes: 1 addition & 1 deletion modconfig/mod_variable_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewModVariableMap(mod *Mod) (*ModVariableMap, error) {
if err != nil {
return nil, err
}
m.DependencyVariables[depMod.GetDependencyName()] = depMap
m.DependencyVariables[depMod.DependencyName] = depMap
}
}

Expand Down
4 changes: 2 additions & 2 deletions modconfig/mod_version_constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func NewFilepathModVersionConstraint(mod *Mod) *ModVersionConstraint {
return &ModVersionConstraint{
Args: make(map[string]cty.Value),
// set name and filepath to the same value
Name: mod.GetModPath(),
FilePath: mod.GetModPath(),
Name: mod.ModPath,
FilePath: mod.ModPath,
}
}

Expand Down
16 changes: 8 additions & 8 deletions modinstaller/mod_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewModInstaller(opts *InstallOpts) (*ModInstaller, error) {
return nil, fmt.Errorf("no workspace mod passed to mod installer")
}
// NOTE: ensure worksapace path is absolute
workspacePath, err := filepath.Abs(opts.WorkspaceMod.GetModPath())
workspacePath, err := filepath.Abs(opts.WorkspaceMod.ModPath)
if err != nil {
return nil, err
}
Expand All @@ -80,7 +80,7 @@ func NewModInstaller(opts *InstallOpts) (*ModInstaller, error) {
updateStrategy: opts.UpdateStrategy,
}

if require := opts.WorkspaceMod.GetRequire(); require != nil {
if require := opts.WorkspaceMod.Require; require != nil {
i.oldRequire = require.Clone()
}

Expand Down Expand Up @@ -122,8 +122,8 @@ func (i *ModInstaller) UninstallWorkspaceDependencies(ctx context.Context) error
return err
}

if workspaceMod.GetRequire().Empty() {
workspaceMod.SetRequire(nil)
if workspaceMod.Require.Empty() {
workspaceMod.Require = nil
}

// if this is a dry run, return now
Expand Down Expand Up @@ -314,7 +314,7 @@ func (i *ModInstaller) installMods(ctx context.Context, parent *modconfig.Mod) (

var errors []error

for _, requiredModVersion := range i.workspaceMod.GetRequire().Mods {
for _, requiredModVersion := range i.workspaceMod.Require.Mods {
// is this mod targeted by the command (i.e. was the mod name passed as an arg
// - or else were no args passed, targeting all mods)
commandTargetingMod := i.isCommandTargetingMod(requiredModVersion)
Expand Down Expand Up @@ -377,12 +377,12 @@ func (i *ModInstaller) installModDependenciesRecursively(ctx context.Context, re
} else {
// this mod is already installed - just update the install data
i.installData.addExisting(dependencyMod, parent)
slog.Debug(fmt.Sprintf("not installing %s with version constraint %s as version %s is already Installed", requiredModVersion.Name, requiredModVersion.VersionString, dependencyMod.Mod.GetVersion()))
slog.Debug(fmt.Sprintf("not installing %s with version constraint %s as version %s is already Installed", requiredModVersion.Name, requiredModVersion.VersionString, dependencyMod.Mod.Version))
}

// to get here we have the dependency mod - either we installed it or it was already installed
// recursively install its dependencies
for _, childDependency := range dependencyMod.Mod.GetRequire().Mods {
for _, childDependency := range dependencyMod.Mod.Require.Mods {
childDependencyMod, err := i.getModForRequirement(ctx, childDependency, commandTargettingParent)
if err != nil {
errors = append(errors, err)
Expand Down Expand Up @@ -584,7 +584,7 @@ func (i *ModInstaller) installFromGit(repoName string, gitRefName plumbing.Refer
func (i *ModInstaller) installFromFilepath(_ context.Context, modVersion *modconfig.ModVersionConstraint, parent *modconfig.Mod) (*versionmap.ResolvedVersionConstraint, *modconfig.Mod, error) {
// build a DependencyVersion
// convert the filename to absolute
filePath := i.toAbsoluteFilepath(modVersion.FilePath, parent.GetModPath())
filePath := i.toAbsoluteFilepath(modVersion.FilePath, parent.ModPath)

var dependencyVersion = &modconfig.DependencyVersion{
FilePath: filePath,
Expand Down
2 changes: 1 addition & 1 deletion modinstaller/mod_installer_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (i *ModInstaller) GetRequiredModVersionsFromArgs(modsArgs []string) (map[st
var err error
// check is this a file path
// if modArg IS a filepath, argToFilePath will return the absolute path
if filePath := i.toAbsoluteFilepath(modArg, i.workspaceMod.GetModPath()); filePath != "" {
if filePath := i.toAbsoluteFilepath(modArg, i.workspaceMod.ModPath); filePath != "" {
// special case for file paths
modVersion, err = i.newFilepathModVersionConstraint(filePath)

Expand Down
2 changes: 1 addition & 1 deletion modinstaller/mod_installer_require.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (i *ModInstaller) updateModFile() error {
}

oldRequire := i.oldRequire
newRequire := i.workspaceMod.GetRequire()
newRequire := i.workspaceMod.Require

// fill these requires in with empty requires
// so that we don't have to do nil checks everywhere
Expand Down
4 changes: 2 additions & 2 deletions parse/mod_parse_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func (m *ModParseContext) addReferenceValue(resource modconfig.HclResource, valu
}

modName := mod.ShortName
if mod.GetModPath() == m.RootEvalPath {
if mod.ModPath == m.RootEvalPath {
modName = "local"
}
variablesForMod, ok := m.referenceValues[modName]
Expand Down Expand Up @@ -677,7 +677,7 @@ func (m *ModParseContext) AddLoadedDependencyMod(mod *modconfig.Mod) {
m.depLock.Lock()
defer m.depLock.Unlock()

m.topLevelDependencyMods[mod.GetDependencyName()] = mod
m.topLevelDependencyMods[mod.DependencyName] = mod
m.modResources.AddMaps(mod.GetModResources().TopLevelResources())
}

Expand Down
16 changes: 2 additions & 14 deletions workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"context"
"errors"
"fmt"
"github.com/turbot/pipe-fittings/connection"
"github.com/zclconf/go-cty/cty"
"log/slog"
"os"
"path/filepath"
Expand All @@ -19,6 +17,7 @@ import (
filehelpers "github.com/turbot/go-kit/files"
"github.com/turbot/go-kit/filewatcher"
"github.com/turbot/pipe-fittings/app_specific"
"github.com/turbot/pipe-fittings/connection"
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/load_mod"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/turbot/pipe-fittings/schema"
"github.com/turbot/pipe-fittings/utils"
"github.com/turbot/pipe-fittings/versionmap"
"github.com/zclconf/go-cty/cty"
)

type Workspace struct {
Expand Down Expand Up @@ -179,18 +179,6 @@ func (w *Workspace) LoadWorkspaceMod(ctx context.Context) error_helpers.ErrorAnd
return ew
}

func (w *Workspace) GetMod() *modconfig.Mod {
return w.Mod
}

func (w *Workspace) GetMods() map[string]*modconfig.Mod {
return w.Mods
}

func (w *Workspace) GetPath() string {
return w.Path
}

// resolve values of all input variables
// we may need to load the mod more than once to resolve all variable dependencies
func (w *Workspace) resolveVariableValues(ctx context.Context) (*modconfig.ModVariableMap, error_helpers.ErrorAndWarnings) {
Expand Down
2 changes: 1 addition & 1 deletion workspace/workspace_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func promptForMissingVariables(ctx context.Context, missingVariables []*modconfi
variableName := v.ShortName
variableDisplayName := fmt.Sprintf("var.%s", v.ShortName)
// if this variable is NOT part of the workspace mod, add the mod name to the variable name
if v.Mod.GetModPath() != workspacePath {
if v.Mod.ModPath != workspacePath {
variableDisplayName = fmt.Sprintf("%s.var.%s", v.ModName, v.ShortName)
variableName = fmt.Sprintf("%s.%s", v.ModName, v.ShortName)
}
Expand Down

0 comments on commit d7decaf

Please sign in to comment.