fleet/server/service/service_errors.go
Konstantin Sykulev cb26f43472
gitops, basic apis, and table for android certificate templates (#35788)
**Related issue:** Resolves #35460, #35462

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)

## Testing

- [x] Added/updated automated tests
- [x] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)

- [x] QA'd all new/changed functionality manually

## Database migrations

- [x] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [x] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [x] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

* **New Features**
* Added certificate templates for managing Android device certificates
at global and team levels
* Introduced API endpoints to create, list, retrieve, and delete
certificate templates
* Enabled GitOps workflow support for certificate template
specifications
* Implemented automatic variable substitution in certificate subjects
for host identifiers

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Scott Gress <scottmgress@gmail.com>
Co-authored-by: Scott Gress <scott@fleetdm.com>
2025-11-24 15:44:06 -06:00

95 lines
2 KiB
Go

package service
import (
"fmt"
"path/filepath"
"github.com/fleetdm/fleet/v4/server/fleet"
)
type alreadyExistsError struct {
fleet.ErrorWithUUID
}
func (a *alreadyExistsError) Error() string {
return "Entity already exists"
}
func (a *alreadyExistsError) IsExists() bool {
return true
}
func newAlreadyExistsError() *alreadyExistsError {
return &alreadyExistsError{}
}
type notFoundError struct {
fleet.ErrorWithUUID
}
func (e *notFoundError) Error() string {
return "not found"
}
func (e *notFoundError) IsNotFound() bool {
return true
}
func newNotFoundError() *notFoundError {
return &notFoundError{}
}
// ssoErrCode defines a code for the type of SSO error that occurred. This is
// used to indicate to the frontend why the SSO login attempt failed so that
// it can provide a helpful and appropriate error message.
type ssoErrCode string
// List of valid SSO error codes.
const (
ssoOtherError ssoErrCode = "error"
ssoOrgDisabled ssoErrCode = "org_disabled"
ssoAccountDisabled ssoErrCode = "account_disabled"
ssoAccountInvalid ssoErrCode = "account_invalid"
)
// ssoError is an error that occurs during the single sign-on flow. Its code
// indicates the type of error.
type ssoError struct {
err error
code ssoErrCode
fleet.ErrorWithUUID
}
func newSSOError(err error, code ssoErrCode) *ssoError {
return &ssoError{
err: err,
code: code,
}
}
func (e *ssoError) Error() string {
return string(e.code) + ": " + e.err.Error()
}
func (e *ssoError) Unwrap() error {
return e.err
}
// gitOpsValidationError is an error that occurs during validating fields in the yaml spec.
type gitOpsValidationError struct {
message string
}
func (e *gitOpsValidationError) Error() string {
return e.message
}
func (e *gitOpsValidationError) WithFileContext(baseDir, filename string) error {
fileFullPath := filepath.Join(baseDir, filename)
return fmt.Errorf("Couldn't edit %q at: %q. %s", filename, fileFullPath, e.message)
}
func newGitOpsValidationError(message string) *gitOpsValidationError {
return &gitOpsValidationError{message: message}
}