-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api,cdsctl,sdk): add export worker model #3774
Conversation
Signed-off-by: Benjamin Coenen <[email protected]>
Signed-off-by: Benjamin Coenen <[email protected]>
Signed-off-by: Benjamin Coenen <[email protected]>
engine/api/worker_model_import.go
Outdated
if err != nil { | ||
return sdk.WrapError(err, "Unable to start tx") | ||
} | ||
defer tx.Rollback() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of tx.Rollback
is not checked (from errcheck
)
sdk/cdsclient/client_import.go
Outdated
url += "?force=true" | ||
} | ||
|
||
mods := []RequestModifier{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this value of mods
is never used (from megacheck
)
sdk/cdsclient/client_import.go
Outdated
@@ -129,6 +129,49 @@ func (c *client) EnvironmentImport(projectKey string, content io.Reader, format | |||
return messages, nil | |||
} | |||
|
|||
// WorkerModelImport import a worker model via as code | |||
func (c *client) WorkerModelImport(content io.Reader, format string, force bool) (*sdk.Model, error) { | |||
var url string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should merge variable declaration with assignment on next line (from megacheck
)
sdk/exportentities/worker_model.go
Outdated
return fmt.Errorf("Error: VSphere main worker command empty") | ||
} | ||
} | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant break statement (from megacheck
)
Signed-off-by: Benjamin Coenen <[email protected]>
engine/api/worker/model_import.go
Outdated
} | ||
|
||
//User must be admin of the group set in the model | ||
var ok bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var ok bool | |
var isGroupAdmin bool |
engine/api/worker/model_import.go
Outdated
if g.ID == sdkWm.GroupID { | ||
for _, a := range g.Admins { | ||
if a.ID == u.ID { | ||
ok = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok = true | |
isGroupAdmin = true |
engine/api/worker/model_import.go
Outdated
} | ||
|
||
//User should have the right permission or be admin | ||
if !u.Admin && !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !u.Admin && !ok { | |
if !u.Admin && !isGroupAdmin { |
engine/api/worker/model_import.go
Outdated
} | ||
|
||
if errAdd := InsertWorkerModel(db, &sdkWm); errAdd != nil { | ||
if errPG, ok := errAdd.(*pq.Error); ok && errPG.Code == gorpmapping.ViolateUniqueKeyPGCode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use sdk.Cause(errAdd) then cast to *pq.Error (https://ovh.github.io/cds/contribute/error_management/). Is the error was wrapped this will to work.
sdk/exportentities/worker_model.go
Outdated
// IsValid returns error if worker model is invalid | ||
func (wm *WorkerModel) IsValid() error { | ||
if wm.Name == "" { | ||
return fmt.Errorf("Error: worker model name is not provided") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the error in this func should probably generates a bad request to the client, so can be sdk.NewErrorFrom(sdk.ErrWrongRequest, "Worker model name is not provided").
Co-Authored-By: bnjjj <[email protected]>
Signed-off-by: Benjamin Coenen <[email protected]>
close cdsctl worker model export #3767
@ovh/cds