From 613fb5c28639fd7a566b8f2f593d9534ba4c679d Mon Sep 17 00:00:00 2001 From: mitchell Date: Thu, 5 Sep 2024 11:26:36 -0400 Subject: [PATCH] The new hasura inventory service search endpoint requires a timestamp. By always using the latest inventory timestamp, we don't need to pass around or specify timestamps anymore. This eliminates the `--ts now` flag for package operations. --- cmd/state/internal/cmdtree/packages.go | 15 ------ internal/locale/locales/en-us.yaml | 4 +- internal/runbits/commits_runbit/time.go | 29 ------------ .../runtime/requirements/requirements.go | 47 +++++++++---------- internal/runners/initialize/init.go | 2 +- internal/runners/languages/install.go | 2 +- internal/runners/packages/info.go | 13 ++--- internal/runners/packages/install.go | 14 ++---- internal/runners/packages/search.go | 12 ++--- internal/runners/packages/uninstall.go | 9 +--- internal/runners/platforms/add.go | 1 - internal/runners/platforms/remove.go | 1 - internal/runners/publish/publish.go | 2 +- .../request/search_ingredients.go | 4 +- pkg/platform/model/inventory.go | 23 +++++---- test/integration/package_int_test.go | 2 +- test/integration/publish_int_test.go | 2 +- test/integration/runtime_int_test.go | 4 +- 18 files changed, 55 insertions(+), 131 deletions(-) diff --git a/cmd/state/internal/cmdtree/packages.go b/cmd/state/internal/cmdtree/packages.go index 39b66a1cb0..e1992b5788 100644 --- a/cmd/state/internal/cmdtree/packages.go +++ b/cmd/state/internal/cmdtree/packages.go @@ -60,11 +60,6 @@ func newInstallCommand(prime *primer.Values) *captain.Command { locale.T("package_install_cmd_description"), prime, []*captain.Flag{ - { - Name: "ts", - Description: locale.T("package_flag_ts_description"), - Value: ¶ms.Timestamp, - }, { Name: "revision", Shorthand: "r", @@ -181,11 +176,6 @@ func newSearchCommand(prime *primer.Values) *captain.Command { Description: locale.T("package_search_flag_exact-term_description"), Value: ¶ms.ExactTerm, }, - { - Name: "ts", - Description: locale.T("package_flag_ts_description"), - Value: ¶ms.Timestamp, - }, }, []*captain.Argument{ { @@ -217,11 +207,6 @@ func newInfoCommand(prime *primer.Values) *captain.Command { Description: locale.T("package_info_flag_language_description"), Value: ¶ms.Language, }, - { - Name: "ts", - Description: locale.T("package_flag_ts_description"), - Value: ¶ms.Timestamp, - }, }, []*captain.Argument{ { diff --git a/internal/locale/locales/en-us.yaml b/internal/locale/locales/en-us.yaml index 62aa856235..acbe597f77 100644 --- a/internal/locale/locales/en-us.yaml +++ b/internal/locale/locales/en-us.yaml @@ -594,8 +594,6 @@ namespace_list_flag_project_description: other: The namespace packages should be listed from package_search_flag_ns_description: other: The namespace to search within. -package_flag_ts_description: - other: The timestamp at which you want to query. Can be either 'now' or RFC3339 formatted timestamp. package_flag_rev_description: other: The revision you want to use. This ensures you get this exact revision and nothing else. package_search_flag_language_description: @@ -1455,7 +1453,7 @@ uploadingredient_success: Revision: [ACTIONABLE]{{.V3}}[/RESET] Timestamp: [ACTIONABLE]{{.V4}}[/RESET] - You can install this package by running `[ACTIONABLE]state install {{.V1}}/{{.V0}} --ts now`[/RESET]. + You can install this package by running `[ACTIONABLE]state install {{.V1}}/{{.V0}}`[/RESET]. err_runtime_cache_invalid: other: Your runtime needs to be updated. Please run '[ACTIONABLE]state refresh[/RESET]'. err_buildscript_not_exist: diff --git a/internal/runbits/commits_runbit/time.go b/internal/runbits/commits_runbit/time.go index 478cfc544d..698bfe095c 100644 --- a/internal/runbits/commits_runbit/time.go +++ b/internal/runbits/commits_runbit/time.go @@ -5,10 +5,8 @@ import ( "github.com/ActiveState/cli/internal/captain" "github.com/ActiveState/cli/internal/errs" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" - "github.com/ActiveState/cli/pkg/project" ) // ExpandTime returns a timestamp based on the given "--ts" value. @@ -36,30 +34,3 @@ func ExpandTime(ts *captain.TimeValue, auth *authentication.Auth) (time.Time, er return latest, nil } - -// ExpandTimeForProject is the same as ExpandTime except that it ensures the returned time is either the same or -// later than that of the most recent commit. -func ExpandTimeForProject(ts *captain.TimeValue, auth *authentication.Auth, proj *project.Project) (time.Time, error) { - timestamp, err := ExpandTime(ts, auth) - if err != nil { - return time.Time{}, errs.Wrap(err, "Unable to expand time") - } - - if proj != nil { - commitID, err := localcommit.Get(proj.Dir()) - if err != nil { - return time.Time{}, errs.Wrap(err, "Unable to get commit ID") - } - - atTime, err := model.FetchTimeStampForCommit(commitID, auth) - if err != nil { - return time.Time{}, errs.Wrap(err, "Unable to get commit time") - } - - if atTime.After(timestamp) { - return *atTime, nil - } - } - - return timestamp, nil -} diff --git a/internal/runbits/runtime/requirements/requirements.go b/internal/runbits/runtime/requirements/requirements.go index cf7cd8f89a..f21a015251 100644 --- a/internal/runbits/runtime/requirements/requirements.go +++ b/internal/runbits/runtime/requirements/requirements.go @@ -6,7 +6,6 @@ import ( "regexp" "strconv" "strings" - "time" "github.com/ActiveState/cli/internal/analytics" anaConsts "github.com/ActiveState/cli/internal/analytics/constants" @@ -130,7 +129,7 @@ type Requirement struct { // ExecuteRequirementOperation executes the operation on the requirement // This has become quite unwieldy, and is ripe for a refactor - https://activestatef.atlassian.net/browse/DX-1897 -func (r *RequirementOperation) ExecuteRequirementOperation(ts *time.Time, requirements ...*Requirement) (rerr error) { +func (r *RequirementOperation) ExecuteRequirementOperation(requirements ...*Requirement) (rerr error) { defer r.rationalizeError(&rerr) if len(requirements) == 0 { @@ -154,7 +153,7 @@ func (r *RequirementOperation) ExecuteRequirementOperation(ts *time.Time, requir } out.Notice(locale.Tr("operating_message", r.Project.NamespaceString(), r.Project.Dir())) - if err := r.resolveNamespaces(ts, requirements...); err != nil { + if err := r.resolveNamespaces(requirements...); err != nil { return errs.Wrap(err, "Could not resolve namespaces") } @@ -200,7 +199,7 @@ func (r *RequirementOperation) ExecuteRequirementOperation(ts *time.Time, requir } bp := bpModel.NewBuildPlannerModel(r.Auth) - script, err := r.prepareBuildScript(bp, parentCommitID, requirements, ts) + script, err := r.prepareBuildScript(bp, parentCommitID, requirements) if err != nil { return errs.Wrap(err, "Could not prepare build script") } @@ -281,25 +280,21 @@ func (r *RequirementOperation) ExecuteRequirementOperation(ts *time.Time, requir return nil } -func (r *RequirementOperation) prepareBuildScript(bp *bpModel.BuildPlanner, parentCommit strfmt.UUID, requirements []*Requirement, ts *time.Time) (*buildscript.BuildScript, error) { +func (r *RequirementOperation) prepareBuildScript(bp *bpModel.BuildPlanner, parentCommit strfmt.UUID, requirements []*Requirement) (*buildscript.BuildScript, error) { script, err := bp.GetBuildScript(string(parentCommit)) if err != nil { return nil, errs.Wrap(err, "Failed to get build expression") } - if ts != nil { - script.SetAtTime(*ts) - } else { - // If no atTime was provided then we need to ensure that the atTime in the script is updated to use - // the most recent, which is either the current value or the platform latest. - latest, err := model.FetchLatestTimeStamp(r.Auth) - if err != nil { - return nil, errs.Wrap(err, "Unable to fetch latest Platform timestamp") - } - atTime := script.AtTime() - if atTime == nil || latest.After(*atTime) { - script.SetAtTime(latest) - } + // Ensure that the atTime in the script is updated to use + // the most recent, which is either the current value or the platform latest. + latest, err := model.FetchLatestTimeStamp(r.Auth) + if err != nil { + return nil, errs.Wrap(err, "Unable to fetch latest Platform timestamp") + } + atTime := script.AtTime() + if atTime == nil || latest.After(*atTime) { + script.SetAtTime(latest) } for _, req := range requirements { @@ -334,9 +329,9 @@ func (e ResolveNamespaceError) Error() string { return "unable to resolve namespace" } -func (r *RequirementOperation) resolveNamespaces(ts *time.Time, requirements ...*Requirement) error { +func (r *RequirementOperation) resolveNamespaces(requirements ...*Requirement) error { for _, requirement := range requirements { - if err := r.resolveNamespace(ts, requirement); err != nil { + if err := r.resolveNamespace(requirement); err != nil { if err != errNoLanguage { err = errs.Pack(err, &ResolveNamespaceError{requirement.Name}) } @@ -346,7 +341,7 @@ func (r *RequirementOperation) resolveNamespaces(ts *time.Time, requirements ... return nil } -func (r *RequirementOperation) resolveNamespace(ts *time.Time, requirement *Requirement) error { +func (r *RequirementOperation) resolveNamespace(requirement *Requirement) error { requirement.langName = "undetermined" if requirement.NamespaceType != nil { @@ -386,7 +381,7 @@ func (r *RequirementOperation) resolveNamespace(ts *time.Time, requirement *Requ var nsv model.Namespace var supportedLang *medmodel.SupportedLanguage - requirement.Name, nsv, supportedLang, err = resolvePkgAndNamespace(r.Prompt, requirement.Name, *requirement.NamespaceType, supported, ts, r.Auth) + requirement.Name, nsv, supportedLang, err = resolvePkgAndNamespace(r.Prompt, requirement.Name, *requirement.NamespaceType, supported, r.Auth) if err != nil { return errs.Wrap(err, "Could not resolve pkg and namespace") } @@ -441,7 +436,7 @@ func (r *RequirementOperation) validatePackage(requirement *Requirement) error { multilog.Error("Failed to normalize '%s': %v", requirement.Name, err) } - packages, err := model.SearchIngredientsStrict(requirement.Namespace.String(), normalized, false, false, nil, r.Auth) // ideally case-sensitive would be true (PB-4371) + packages, err := model.SearchIngredientsStrict(requirement.Namespace.String(), normalized, false, false, r.Auth) // ideally case-sensitive would be true (PB-4371) if err != nil { return locale.WrapError(err, "package_err_cannot_obtain_search_results") } @@ -591,11 +586,11 @@ func supportedLanguageByName(supported []medmodel.SupportedLanguage, langName st return funk.Find(supported, func(l medmodel.SupportedLanguage) bool { return l.Name == langName }).(medmodel.SupportedLanguage) } -func resolvePkgAndNamespace(prompt prompt.Prompter, packageName string, nsType model.NamespaceType, supported []medmodel.SupportedLanguage, ts *time.Time, auth *authentication.Auth) (string, model.Namespace, *medmodel.SupportedLanguage, error) { +func resolvePkgAndNamespace(prompt prompt.Prompter, packageName string, nsType model.NamespaceType, supported []medmodel.SupportedLanguage, auth *authentication.Auth) (string, model.Namespace, *medmodel.SupportedLanguage, error) { ns := model.NewBlankNamespace() // Find ingredients that match the input query - ingredients, err := model.SearchIngredientsStrict("", packageName, false, false, ts, auth) + ingredients, err := model.SearchIngredientsStrict("", packageName, false, false, auth) if err != nil { return "", ns, nil, locale.WrapError(err, "err_pkgop_search_err", "Failed to check for ingredients.") } @@ -644,7 +639,7 @@ func resolvePkgAndNamespace(prompt prompt.Prompter, packageName string, nsType m } func getSuggestions(ns model.Namespace, name string, auth *authentication.Auth) ([]string, error) { - results, err := model.SearchIngredients(ns.String(), name, false, nil, auth) + results, err := model.SearchIngredients(ns.String(), name, false, auth) if err != nil { return []string{}, locale.WrapError(err, "package_ingredient_err_search", "Failed to resolve ingredient named: {{.V0}}", name) } diff --git a/internal/runners/initialize/init.go b/internal/runners/initialize/init.go index 1951a206f8..1b8aeab49d 100644 --- a/internal/runners/initialize/init.go +++ b/internal/runners/initialize/init.go @@ -334,7 +334,7 @@ func (r *Initialize) Run(params *RunParams) (rerr error) { } func getKnownVersions(lang language.Language, auth *authentication.Auth) ([]string, error) { - pkgs, err := model.SearchIngredientsStrict(model.NewNamespaceLanguage().String(), lang.Requirement(), false, true, nil, auth) + pkgs, err := model.SearchIngredientsStrict(model.NewNamespaceLanguage().String(), lang.Requirement(), false, true, auth) if err != nil { return nil, errs.Wrap(err, "Failed to fetch Platform languages") } diff --git a/internal/runners/languages/install.go b/internal/runners/languages/install.go index d2f208dae6..d5f73bd9da 100644 --- a/internal/runners/languages/install.go +++ b/internal/runners/languages/install.go @@ -54,7 +54,7 @@ func (u *Update) Run(params *UpdateParams) error { } op := requirements.NewRequirementOperation(u.prime) - return op.ExecuteRequirementOperation(nil, &requirements.Requirement{ + return op.ExecuteRequirementOperation(&requirements.Requirement{ Name: lang.Name, Version: lang.Version, NamespaceType: &model.NamespaceLanguage, diff --git a/internal/runners/packages/info.go b/internal/runners/packages/info.go index cb0cbc88a8..f0917fdabf 100644 --- a/internal/runners/packages/info.go +++ b/internal/runners/packages/info.go @@ -12,7 +12,6 @@ import ( "github.com/ActiveState/cli/internal/multilog" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/rtutils/ptr" - "github.com/ActiveState/cli/internal/runbits/commits_runbit" hsInventoryModel "github.com/ActiveState/cli/pkg/platform/api/hasura_inventory/model" "github.com/ActiveState/cli/pkg/platform/api/vulnerabilities/request" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -22,9 +21,8 @@ import ( // InfoRunParams tracks the info required for running Info. type InfoRunParams struct { - Package captain.PackageValue - Timestamp captain.TimeValue - Language string + Package captain.PackageValue + Language string } // Info manages the information execution context. @@ -70,12 +68,7 @@ func (i *Info) Run(params InfoRunParams, nstype model.NamespaceType) error { normalized = params.Package.Name } - ts, err := commits_runbit.ExpandTimeForProject(¶ms.Timestamp, i.auth, i.proj) - if err != nil { - return errs.Wrap(err, "Unable to get timestamp from params") - } - - packages, err := model.SearchIngredientsStrict(ns.String(), normalized, false, false, &ts, i.auth) // ideally case-sensitive would be true (PB-4371) + packages, err := model.SearchIngredientsStrict(ns.String(), normalized, false, false, i.auth) // ideally case-sensitive would be true (PB-4371) if err != nil { return locale.WrapError(err, "package_err_cannot_obtain_search_results") } diff --git a/internal/runners/packages/install.go b/internal/runners/packages/install.go index 30193f4cf8..3e3ed7a570 100644 --- a/internal/runners/packages/install.go +++ b/internal/runners/packages/install.go @@ -2,10 +2,8 @@ package packages import ( "github.com/ActiveState/cli/internal/captain" - "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/rtutils/ptr" - "github.com/ActiveState/cli/internal/runbits/commits_runbit" "github.com/ActiveState/cli/internal/runbits/runtime/requirements" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/types" "github.com/ActiveState/cli/pkg/platform/model" @@ -13,9 +11,8 @@ import ( // InstallRunParams tracks the info required for running Install. type InstallRunParams struct { - Packages captain.PackagesValue - Timestamp captain.TimeValue - Revision captain.IntValue + Packages captain.PackagesValue + Revision captain.IntValue } // Install manages the installing execution context. @@ -52,10 +49,5 @@ func (a *Install) Run(params InstallRunParams, nsType model.NamespaceType) (rerr reqs = append(reqs, req) } - ts, err := commits_runbit.ExpandTimeForProject(¶ms.Timestamp, a.prime.Auth(), a.prime.Project()) - if err != nil { - return errs.Wrap(err, "Unable to get timestamp from params") - } - - return requirements.NewRequirementOperation(a.prime).ExecuteRequirementOperation(&ts, reqs...) + return requirements.NewRequirementOperation(a.prime).ExecuteRequirementOperation(reqs...) } diff --git a/internal/runners/packages/search.go b/internal/runners/packages/search.go index 540068b492..809bfb764a 100644 --- a/internal/runners/packages/search.go +++ b/internal/runners/packages/search.go @@ -8,7 +8,6 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" - "github.com/ActiveState/cli/internal/runbits/commits_runbit" "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/vulnerabilities/request" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -22,7 +21,6 @@ type SearchRunParams struct { Language string ExactTerm bool Ingredient captain.PackageValueNoVersion - Timestamp captain.TimeValue } // Search manages the searching execution context. @@ -59,16 +57,12 @@ func (s *Search) Run(params SearchRunParams, nstype model.NamespaceType) error { ns = model.NewRawNamespace(params.Ingredient.Namespace) } - ts, err := commits_runbit.ExpandTimeForProject(¶ms.Timestamp, s.auth, s.proj) - if err != nil { - return errs.Wrap(err, "Unable to get timestamp from params") - } - var packages []*model.IngredientAndVersion + var err error if params.ExactTerm { - packages, err = model.SearchIngredientsLatestStrict(ns.String(), params.Ingredient.Name, true, true, &ts, s.auth) + packages, err = model.SearchIngredientsLatestStrict(ns.String(), params.Ingredient.Name, true, true, s.auth) } else { - packages, err = model.SearchIngredientsLatest(ns.String(), params.Ingredient.Name, true, &ts, s.auth) + packages, err = model.SearchIngredientsLatest(ns.String(), params.Ingredient.Name, true, s.auth) } if err != nil { return locale.WrapError(err, "package_err_cannot_obtain_search_results") diff --git a/internal/runners/packages/uninstall.go b/internal/runners/packages/uninstall.go index a9008261dd..4cd7571ff1 100644 --- a/internal/runners/packages/uninstall.go +++ b/internal/runners/packages/uninstall.go @@ -2,10 +2,8 @@ package packages import ( "github.com/ActiveState/cli/internal/captain" - "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/rtutils/ptr" - "github.com/ActiveState/cli/internal/runbits/commits_runbit" "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/internal/runbits/runtime/requirements" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/types" @@ -51,10 +49,5 @@ func (u *Uninstall) Run(params UninstallRunParams, nsType model.NamespaceType) ( reqs = append(reqs, req) } - ts, err := commits_runbit.ExpandTimeForProject(&captain.TimeValue{}, u.prime.Auth(), u.prime.Project()) - if err != nil { - return errs.Wrap(err, "Unable to get timestamp from params") - } - - return requirements.NewRequirementOperation(u.prime).ExecuteRequirementOperation(&ts, reqs...) + return requirements.NewRequirementOperation(u.prime).ExecuteRequirementOperation(reqs...) } diff --git a/internal/runners/platforms/add.go b/internal/runners/platforms/add.go index 767c569f2a..6d97f2952f 100644 --- a/internal/runners/platforms/add.go +++ b/internal/runners/platforms/add.go @@ -51,7 +51,6 @@ func (a *Add) Run(ps AddRunParams) error { } if err := requirements.NewRequirementOperation(a.prime).ExecuteRequirementOperation( - nil, &requirements.Requirement{ Name: params.name, Version: params.version, diff --git a/internal/runners/platforms/remove.go b/internal/runners/platforms/remove.go index 3690be8257..d85df219f8 100644 --- a/internal/runners/platforms/remove.go +++ b/internal/runners/platforms/remove.go @@ -41,7 +41,6 @@ func (r *Remove) Run(ps RemoveRunParams) error { } if err := requirements.NewRequirementOperation(r.prime).ExecuteRequirementOperation( - nil, &requirements.Requirement{ Name: params.name, Version: params.version, diff --git a/internal/runners/publish/publish.go b/internal/runners/publish/publish.go index b831913fac..f890af64ae 100644 --- a/internal/runners/publish/publish.go +++ b/internal/runners/publish/publish.go @@ -168,7 +168,7 @@ func (r *Runner) Run(params *Params) error { if ingredient == nil { // Attempt to find the existing ingredient, if we didn't already get it from the version specific call above - ingredients, err := model.SearchIngredientsStrict(reqVars.Namespace, reqVars.Name, true, false, &latestRevisionTime, r.auth) + ingredients, err := model.SearchIngredientsStrict(reqVars.Namespace, reqVars.Name, true, false, r.auth) var errSearch404 *model.ErrSearch404 if err != nil && !errors.As(err, &errSearch404) { // 404 means either the ingredient or the namespace was not found, which is fine return locale.WrapError(err, "err_uploadingredient_search", "Could not search for ingredient") diff --git a/pkg/platform/api/hasura_inventory/request/search_ingredients.go b/pkg/platform/api/hasura_inventory/request/search_ingredients.go index 74c2efe65f..4b91c747f5 100644 --- a/pkg/platform/api/hasura_inventory/request/search_ingredients.go +++ b/pkg/platform/api/hasura_inventory/request/search_ingredients.go @@ -6,7 +6,7 @@ import ( "time" ) -func SearchIngredients(namespaces []string, name string, exact bool, time *time.Time, limit, offset int) *searchIngredients { +func SearchIngredients(namespaces []string, name string, exact bool, time time.Time, limit, offset int) *searchIngredients { return &searchIngredients{map[string]interface{}{ "namespaces": fmt.Sprintf("{%s}", strings.Join(namespaces, ",")), // API requires enclosure in {} "name": name, @@ -23,7 +23,7 @@ type searchIngredients struct { func (s *searchIngredients) Query() string { return ` -query ($namespaces: _non_empty_citext, $name: non_empty_citext, $exact: Boolean!, $time: timestamptz, $limit: Int!, $offset: Int!) { +query ($namespaces: _non_empty_citext, $name: non_empty_citext, $exact: Boolean!, $time: timestamptz!, $limit: Int!, $offset: Int!) { search_ingredients( args: {namespaces: $namespaces, name_: $name, exact: $exact, timestamp_: $time, limit_: $limit, offset_: $offset} ) { diff --git a/pkg/platform/model/inventory.go b/pkg/platform/model/inventory.go index bf435908fc..1a274e823f 100644 --- a/pkg/platform/model/inventory.go +++ b/pkg/platform/model/inventory.go @@ -84,14 +84,14 @@ func GetIngredientByNameAndVersion(namespace string, name string, version string // SearchIngredients will return all ingredients+ingredientVersions that fuzzily // match the ingredient name. -func SearchIngredients(namespace string, name string, includeVersions bool, ts *time.Time, auth *authentication.Auth) ([]*IngredientAndVersion, error) { - return searchIngredientsNamespace(namespace, name, includeVersions, false, ts, auth) +func SearchIngredients(namespace string, name string, includeVersions bool, auth *authentication.Auth) ([]*IngredientAndVersion, error) { + return searchIngredientsNamespace(namespace, name, includeVersions, false, auth) } // SearchIngredientsStrict will return all ingredients+ingredientVersions that // strictly match the ingredient name. -func SearchIngredientsStrict(namespace string, name string, caseSensitive bool, includeVersions bool, ts *time.Time, auth *authentication.Auth) ([]*IngredientAndVersion, error) { - results, err := searchIngredientsNamespace(namespace, name, includeVersions, true, ts, auth) +func SearchIngredientsStrict(namespace string, name string, caseSensitive bool, includeVersions bool, auth *authentication.Auth) ([]*IngredientAndVersion, error) { + results, err := searchIngredientsNamespace(namespace, name, includeVersions, true, auth) if err != nil { return nil, err } @@ -118,8 +118,8 @@ func SearchIngredientsStrict(namespace string, name string, caseSensitive bool, // SearchIngredientsLatest will return all ingredients+ingredientVersions that // fuzzily match the ingredient name, but only the latest version of each // ingredient. -func SearchIngredientsLatest(namespace string, name string, includeVersions bool, ts *time.Time, auth *authentication.Auth) ([]*IngredientAndVersion, error) { - results, err := searchIngredientsNamespace(namespace, name, includeVersions, false, ts, auth) +func SearchIngredientsLatest(namespace string, name string, includeVersions bool, auth *authentication.Auth) ([]*IngredientAndVersion, error) { + results, err := searchIngredientsNamespace(namespace, name, includeVersions, false, auth) if err != nil { return nil, err } @@ -130,8 +130,8 @@ func SearchIngredientsLatest(namespace string, name string, includeVersions bool // SearchIngredientsLatestStrict will return all ingredients+ingredientVersions that // strictly match the ingredient name, but only the latest version of each // ingredient. -func SearchIngredientsLatestStrict(namespace string, name string, caseSensitive bool, includeVersions bool, ts *time.Time, auth *authentication.Auth) ([]*IngredientAndVersion, error) { - results, err := SearchIngredientsStrict(namespace, name, caseSensitive, includeVersions, ts, auth) +func SearchIngredientsLatestStrict(namespace string, name string, caseSensitive bool, includeVersions bool, auth *authentication.Auth) ([]*IngredientAndVersion, error) { + results, err := SearchIngredientsStrict(namespace, name, caseSensitive, includeVersions, auth) if err != nil { return nil, err } @@ -183,10 +183,15 @@ type ErrTooManyMatches struct { Query string } -func searchIngredientsNamespace(ns string, name string, includeVersions bool, exactOnly bool, ts *time.Time, auth *authentication.Auth) ([]*IngredientAndVersion, error) { +func searchIngredientsNamespace(ns string, name string, includeVersions bool, exactOnly bool, auth *authentication.Auth) ([]*IngredientAndVersion, error) { limit := 100 offset := 0 + ts, err := FetchLatestRevisionTimeStamp(auth) + if err != nil { + return nil, errs.Wrap(err, "Unable to fetch latest inventory timestamp") + } + client := hsInventory.New(auth) request := hsInventoryRequest.SearchIngredients([]string{ns}, name, exactOnly, ts, limit, offset) diff --git a/test/integration/package_int_test.go b/test/integration/package_int_test.go index d7243b1167..8b4cd658ec 100644 --- a/test/integration/package_int_test.go +++ b/test/integration/package_int_test.go @@ -710,7 +710,7 @@ func (suite *PackageIntegrationTestSuite) TestCVE_Indirect() { cp = ts.Spawn("config", "set", constants.SecurityPromptConfig, "true") cp.ExpectExitCode(0) - cp = ts.Spawn("install", "private/ActiveState-CLI-Testing/language/python/django_dep", "--ts=now") + cp = ts.Spawn("install", "private/ActiveState-CLI-Testing/language/python/django_dep") cp.ExpectRe(`Warning: Dependency has \d indirect known vulnerabilities`) cp.Expect("Do you want to continue") cp.SendLine("n") diff --git a/test/integration/publish_int_test.go b/test/integration/publish_int_test.go index 709cde17ab..a18cc66a69 100644 --- a/test/integration/publish_int_test.go +++ b/test/integration/publish_int_test.go @@ -457,7 +457,7 @@ authors: cp.Expect(version) cp.ExpectExitCode(inv.expect.exitCode) - cp = ts.Spawn("search", namespace+"/"+name, "--ts=now") + cp = ts.Spawn("search", namespace+"/"+name) cp.Expect(version) time.Sleep(time.Second) cp.Send("q") diff --git a/test/integration/runtime_int_test.go b/test/integration/runtime_int_test.go index 83ab55cfa4..6b59ad6f3d 100644 --- a/test/integration/runtime_int_test.go +++ b/test/integration/runtime_int_test.go @@ -148,7 +148,7 @@ func (suite *RuntimeIntegrationTestSuite) TestBuildInProgress() { ts.LoginAsPersistentUser() - // Publish a new ingredient revision, which, when coupled with `state install --ts now`, will + // Publish a new ingredient revision, which, when coupled with `state install`, will // force a build. // The ingredient is a tarball comprising: // 1. An empty, executable "configure" script (emulating autotools). @@ -167,7 +167,7 @@ func (suite *RuntimeIntegrationTestSuite) TestBuildInProgress() { ts.PrepareEmptyProject() - cp = ts.Spawn("install", "private/"+e2e.PersistentUsername+"/hello-world", "--ts", "now") + cp = ts.Spawn("install", "private/"+e2e.PersistentUsername+"/hello-world") cp.Expect("Build Log") cp.Expect("Building") cp.Expect("All dependencies have been installed and verified", e2e.RuntimeBuildSourcingTimeoutOpt)