feat: Allow inheriting parameters from previous template_versions when updating a template (#2397)

* WIP: feat: Update templates also updates parameters
* Insert params for template version update
* Working implementation of inherited params
* Add "--always-prompt" flag and logging info
This commit is contained in:
Steven Masley
2022-06-17 12:22:28 -05:00
committed by GitHub
parent 18973a65c1
commit 64b92eea67
16 changed files with 547 additions and 167 deletions
+29 -5
View File
@@ -12,6 +12,7 @@ import (
"golang.org/x/exp/slices"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/util/slice"
)
// New returns an in-memory fake of the database.
@@ -103,6 +104,19 @@ func (q *fakeQuerier) AcquireProvisionerJob(_ context.Context, arg database.Acqu
return database.ProvisionerJob{}, sql.ErrNoRows
}
func (q *fakeQuerier) ParameterValue(_ context.Context, id uuid.UUID) (database.ParameterValue, error) {
q.mutex.Lock()
defer q.mutex.Unlock()
for _, parameterValue := range q.parameterValues {
if parameterValue.ID.String() != id.String() {
continue
}
return parameterValue, nil
}
return database.ParameterValue{}, sql.ErrNoRows
}
func (q *fakeQuerier) DeleteParameterValueByID(_ context.Context, id uuid.UUID) error {
q.mutex.Lock()
defer q.mutex.Unlock()
@@ -744,17 +758,27 @@ func (q *fakeQuerier) GetOrganizationsByUserID(_ context.Context, userID uuid.UU
return organizations, nil
}
func (q *fakeQuerier) GetParameterValuesByScope(_ context.Context, arg database.GetParameterValuesByScopeParams) ([]database.ParameterValue, error) {
func (q *fakeQuerier) ParameterValues(_ context.Context, arg database.ParameterValuesParams) ([]database.ParameterValue, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
parameterValues := make([]database.ParameterValue, 0)
for _, parameterValue := range q.parameterValues {
if parameterValue.Scope != arg.Scope {
continue
if len(arg.Scopes) > 0 {
if !slice.Contains(arg.Scopes, parameterValue.Scope) {
continue
}
}
if parameterValue.ScopeID != arg.ScopeID {
continue
if len(arg.ScopeIds) > 0 {
if !slice.Contains(arg.ScopeIds, parameterValue.ScopeID) {
continue
}
}
if len(arg.Ids) > 0 {
if !slice.Contains(arg.Ids, parameterValue.ID) {
continue
}
}
parameterValues = append(parameterValues, parameterValue)
}