2016-12-18 05:21:29 +00:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
2021-04-06 10:08:43 +00:00
|
|
|
"io"
|
2018-06-19 11:15:10 +00:00
|
|
|
"path"
|
2016-12-18 05:21:29 +00:00
|
|
|
"time"
|
2016-12-25 20:34:02 +00:00
|
|
|
|
feat(helm/templates): helm app templates EE-943 (#5449)
* feat(helm): add helm chart backport to ce EE-1409 (#5425)
* EE-1311 Helm Chart Backport from EE
* backport to ce
Co-authored-by: Matt Hook <hookenz@gmail.com>
* feat(helm): list and configure helm chart (#5431)
* backport and tidyup code
* --amend
* using rocket icon for charts
* helm chart bugfix - clear category button
* added matomo analytics for helm chart install
* fix web editor exit warning without changes
* editor modified exit bugfix
* fixed notifications typo
* updated helm template text
* helper text to convey slow helm templates load
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
* removing redundant time-consuming api call by using prop attribute
* feat(helm) helm chart backport from ee EE-1311 (#5436)
* Add missing defaultHelmRepoUrl and mock testing
* Backport EE-1477
* Backport updates to helm tests from EE
* add https by default changes and ssl to tls renaming from EE
* Port install integration test. Disabled by default to pass CI checks
* merged changes from EE for the integration test
* kube proxy whitelist updated to support internal helm install command
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
* Pull in all changes from tech review in EE-943
* added helm to sidebar after rebase, sync CE with EE
* bugfix: kubectl shell not opening - bearer token bug
* tidy go modules & remove yarn-error.log
* removed redundant handler (not used) - to match EE
* resolved merge conflicts, updated code
* feat(helm/views): helm release and application views EE-1236 (#5529)
* feat(helm): add helm chart backport to ce EE-1409 (#5425)
* EE-1311 Helm Chart Backport from EE
* backport to ce
Co-authored-by: Matt Hook <hookenz@gmail.com>
* Pull in all changes from tech review in EE-943
* added helm to sidebar after rebase, sync CE with EE
* removed redundant handler (not used) - to match EE
* feat(helm) display helm charts - backend EE-1236
* copy over components for new applications view EE-1236
* Add new applications datatable component
* Add more migrated files
* removed test not applicable to CE
* baclkported EE app data table code to CE
* removed redundant helm repo url
* resolved conflicts, updated code
* using endpoint middleware
* PR review fixes
* using constants, openapi updated
Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com>
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
* fixed test conflicts, go linted
* feat(helm/templates-add): helm templates add repo for user support EE-1278 (#5514)
* feat(helm): add helm chart backport to ce EE-1409 (#5425)
* EE-1311 Helm Chart Backport from EE
* backport to ce
Co-authored-by: Matt Hook <hookenz@gmail.com>
* feat(helm) helm chart backport from ee EE-1311 (#5436)
* Add missing defaultHelmRepoUrl and mock testing
* Backport EE-1477
* Backport updates to helm tests from EE
* add https by default changes and ssl to tls renaming from EE
* Port install integration test. Disabled by default to pass CI checks
* merged changes from EE for the integration test
* kube proxy whitelist updated to support internal helm install command
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
* Pull in all changes from tech review in EE-943
* feat(helm): add helm chart backport to ce EE-1409 (#5425)
* EE-1311 Helm Chart Backport from EE
* backport to ce
Co-authored-by: Matt Hook <hookenz@gmail.com>
* Pull in all changes from tech review in EE-943
* added helm to sidebar after rebase, sync CE with EE
* backport EE-1278, squashed, diffed, updated
* helm install openapi spec update
* resolved conflicts, updated code
* - matching ee codebase at 0afe57034449ee0e9f333d92c252a13995a93019
- helm install using endpoint middleware
- remove trailing slash from added/persisted helm repo urls
* feat(helm) use libhelm url validator and improved path assembly EE-1554 (#5561)
* feat(helm/userrepos) fix getting global repo for ordinary users EE-1562 (#5567)
* feat(helm/userrepos) fix getting global repo for ordinary users EE-1562
* post review changes and further backported changes from EE
* resolved conflicts, updated code
* fixed helm_install handler unit test
* user cannot add existing repo if suffix is '/' (#5571)
* feat(helm/docs) fix broken swagger docs EE-1278 (#5572)
* Fix swagger docs
* minor correction
* fix(helm): migrating code from user handler to helm handler (#5573)
* - migrated user_helm_repos to helm endpoint handler
- migrated api operations from user factory/service to helm factory/service
- passing endpointId into helm service/factory as endpoint provider is deprecated
* upgrade libhelm to hide secrets
Co-authored-by: Matt Hook <hookenz@gmail.com>
* removed duplicate file - due to merge conflict
* dependency injection in helm factory
Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com>
Co-authored-by: Matt Hook <hookenz@gmail.com>
* kubernetes.templates -> kubernetes.templates.helm name conflict fix
* Validate the URL added as a public helm repo (#5579)
* fix(helm): helm app deletion fix EE-1581 (#5582)
* updated helm lib to show correct error on uninstall failure
* passing down helm app namespace on deletion
* fix(k8s): EE-1591 non-admin users cannot deploy charts containing secrets (#5590)
Co-authored-by: Simon Meng <simon.meng@portainer.io>
* fix(helm): helm epic bugfixes EE-1582 EE-1593 (#5585)
* - trim trailing slash and lowercase before persisting helm repo
- browser helm templates url /kubernetes/templates/templates -> /kubernetes/templates/helm
- fix publish url
- fix helm repo add refresh
- semi-fix k8s app expansion
* Tidy up swagger documentation related to helm. Make json consistent
* fixed helm release page for non-default namespaces
* k8s app view table expansion bugfix
* EE-1593: publish url load balancer fallback
Co-authored-by: Matt Hook <hookenz@gmail.com>
* k8s app list fix for charts with deployments containing multiple pods - which use the same label (#5599)
* fix(kubernetes): app list view fix for secrets with long keys or values EE-1600 (#5600)
* k8s app secrets key value text overflow ellipses
* wrapping key value pairs instead of ellipses
* fix(helm): helm apps bundling issue across different namespaces EE-1619 (#5602)
* helm apps bundling issue across different namespaces
* - code comments and indentation to ease reading
- moved namespace calc out of loop
* feat(helm/test) disable slow helm search test by default EE-1599 (#5598)
* skip helm_repo_search as it's an integration test
* switch to portainer built in integration test checker
* make module order match EE
* don't print test struct out when skipping integration test
Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com>
Co-authored-by: Matt Hook <hookenz@gmail.com>
Co-authored-by: cong meng <mcpacino@gmail.com>
Co-authored-by: Simon Meng <simon.meng@portainer.io>
2021-09-10 02:06:57 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/helmuserrepository"
|
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
"github.com/boltdb/bolt"
|
2021-02-22 22:14:52 +00:00
|
|
|
portainer "github.com/portainer/portainer/api"
|
2020-07-06 23:18:39 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/customtemplate"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/dockerhub"
|
2020-04-16 00:22:08 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/edgegroup"
|
2020-06-25 03:25:51 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/edgejob"
|
2020-04-16 00:22:08 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/edgestack"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/endpoint"
|
|
|
|
"github.com/portainer/portainer/api/bolt/endpointgroup"
|
2020-04-16 00:22:08 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/endpointrelation"
|
2020-07-07 21:57:52 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/errors"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/extension"
|
2021-04-06 10:08:43 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/internal"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/registry"
|
|
|
|
"github.com/portainer/portainer/api/bolt/resourcecontrol"
|
2019-05-24 06:04:58 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/role"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/schedule"
|
|
|
|
"github.com/portainer/portainer/api/bolt/settings"
|
2021-08-10 04:59:47 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/ssl"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/stack"
|
|
|
|
"github.com/portainer/portainer/api/bolt/tag"
|
|
|
|
"github.com/portainer/portainer/api/bolt/team"
|
|
|
|
"github.com/portainer/portainer/api/bolt/teammembership"
|
2020-04-16 00:22:08 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/tunnelserver"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/user"
|
|
|
|
"github.com/portainer/portainer/api/bolt/version"
|
|
|
|
"github.com/portainer/portainer/api/bolt/webhook"
|
2018-06-19 11:15:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
databaseFileName = "portainer.db"
|
2016-12-18 05:21:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Store defines the implementation of portainer.DataStore using
|
|
|
|
// BoltDB as the storage system.
|
|
|
|
type Store struct {
|
feat(helm/templates): helm app templates EE-943 (#5449)
* feat(helm): add helm chart backport to ce EE-1409 (#5425)
* EE-1311 Helm Chart Backport from EE
* backport to ce
Co-authored-by: Matt Hook <hookenz@gmail.com>
* feat(helm): list and configure helm chart (#5431)
* backport and tidyup code
* --amend
* using rocket icon for charts
* helm chart bugfix - clear category button
* added matomo analytics for helm chart install
* fix web editor exit warning without changes
* editor modified exit bugfix
* fixed notifications typo
* updated helm template text
* helper text to convey slow helm templates load
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
* removing redundant time-consuming api call by using prop attribute
* feat(helm) helm chart backport from ee EE-1311 (#5436)
* Add missing defaultHelmRepoUrl and mock testing
* Backport EE-1477
* Backport updates to helm tests from EE
* add https by default changes and ssl to tls renaming from EE
* Port install integration test. Disabled by default to pass CI checks
* merged changes from EE for the integration test
* kube proxy whitelist updated to support internal helm install command
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
* Pull in all changes from tech review in EE-943
* added helm to sidebar after rebase, sync CE with EE
* bugfix: kubectl shell not opening - bearer token bug
* tidy go modules & remove yarn-error.log
* removed redundant handler (not used) - to match EE
* resolved merge conflicts, updated code
* feat(helm/views): helm release and application views EE-1236 (#5529)
* feat(helm): add helm chart backport to ce EE-1409 (#5425)
* EE-1311 Helm Chart Backport from EE
* backport to ce
Co-authored-by: Matt Hook <hookenz@gmail.com>
* Pull in all changes from tech review in EE-943
* added helm to sidebar after rebase, sync CE with EE
* removed redundant handler (not used) - to match EE
* feat(helm) display helm charts - backend EE-1236
* copy over components for new applications view EE-1236
* Add new applications datatable component
* Add more migrated files
* removed test not applicable to CE
* baclkported EE app data table code to CE
* removed redundant helm repo url
* resolved conflicts, updated code
* using endpoint middleware
* PR review fixes
* using constants, openapi updated
Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com>
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
* fixed test conflicts, go linted
* feat(helm/templates-add): helm templates add repo for user support EE-1278 (#5514)
* feat(helm): add helm chart backport to ce EE-1409 (#5425)
* EE-1311 Helm Chart Backport from EE
* backport to ce
Co-authored-by: Matt Hook <hookenz@gmail.com>
* feat(helm) helm chart backport from ee EE-1311 (#5436)
* Add missing defaultHelmRepoUrl and mock testing
* Backport EE-1477
* Backport updates to helm tests from EE
* add https by default changes and ssl to tls renaming from EE
* Port install integration test. Disabled by default to pass CI checks
* merged changes from EE for the integration test
* kube proxy whitelist updated to support internal helm install command
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
* Pull in all changes from tech review in EE-943
* feat(helm): add helm chart backport to ce EE-1409 (#5425)
* EE-1311 Helm Chart Backport from EE
* backport to ce
Co-authored-by: Matt Hook <hookenz@gmail.com>
* Pull in all changes from tech review in EE-943
* added helm to sidebar after rebase, sync CE with EE
* backport EE-1278, squashed, diffed, updated
* helm install openapi spec update
* resolved conflicts, updated code
* - matching ee codebase at 0afe57034449ee0e9f333d92c252a13995a93019
- helm install using endpoint middleware
- remove trailing slash from added/persisted helm repo urls
* feat(helm) use libhelm url validator and improved path assembly EE-1554 (#5561)
* feat(helm/userrepos) fix getting global repo for ordinary users EE-1562 (#5567)
* feat(helm/userrepos) fix getting global repo for ordinary users EE-1562
* post review changes and further backported changes from EE
* resolved conflicts, updated code
* fixed helm_install handler unit test
* user cannot add existing repo if suffix is '/' (#5571)
* feat(helm/docs) fix broken swagger docs EE-1278 (#5572)
* Fix swagger docs
* minor correction
* fix(helm): migrating code from user handler to helm handler (#5573)
* - migrated user_helm_repos to helm endpoint handler
- migrated api operations from user factory/service to helm factory/service
- passing endpointId into helm service/factory as endpoint provider is deprecated
* upgrade libhelm to hide secrets
Co-authored-by: Matt Hook <hookenz@gmail.com>
* removed duplicate file - due to merge conflict
* dependency injection in helm factory
Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com>
Co-authored-by: Matt Hook <hookenz@gmail.com>
* kubernetes.templates -> kubernetes.templates.helm name conflict fix
* Validate the URL added as a public helm repo (#5579)
* fix(helm): helm app deletion fix EE-1581 (#5582)
* updated helm lib to show correct error on uninstall failure
* passing down helm app namespace on deletion
* fix(k8s): EE-1591 non-admin users cannot deploy charts containing secrets (#5590)
Co-authored-by: Simon Meng <simon.meng@portainer.io>
* fix(helm): helm epic bugfixes EE-1582 EE-1593 (#5585)
* - trim trailing slash and lowercase before persisting helm repo
- browser helm templates url /kubernetes/templates/templates -> /kubernetes/templates/helm
- fix publish url
- fix helm repo add refresh
- semi-fix k8s app expansion
* Tidy up swagger documentation related to helm. Make json consistent
* fixed helm release page for non-default namespaces
* k8s app view table expansion bugfix
* EE-1593: publish url load balancer fallback
Co-authored-by: Matt Hook <hookenz@gmail.com>
* k8s app list fix for charts with deployments containing multiple pods - which use the same label (#5599)
* fix(kubernetes): app list view fix for secrets with long keys or values EE-1600 (#5600)
* k8s app secrets key value text overflow ellipses
* wrapping key value pairs instead of ellipses
* fix(helm): helm apps bundling issue across different namespaces EE-1619 (#5602)
* helm apps bundling issue across different namespaces
* - code comments and indentation to ease reading
- moved namespace calc out of loop
* feat(helm/test) disable slow helm search test by default EE-1599 (#5598)
* skip helm_repo_search as it's an integration test
* switch to portainer built in integration test checker
* make module order match EE
* don't print test struct out when skipping integration test
Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com>
Co-authored-by: Matt Hook <hookenz@gmail.com>
Co-authored-by: cong meng <mcpacino@gmail.com>
Co-authored-by: Simon Meng <simon.meng@portainer.io>
2021-09-10 02:06:57 +00:00
|
|
|
path string
|
|
|
|
connection *internal.DbConnection
|
|
|
|
isNew bool
|
|
|
|
fileService portainer.FileService
|
|
|
|
CustomTemplateService *customtemplate.Service
|
|
|
|
DockerHubService *dockerhub.Service
|
|
|
|
EdgeGroupService *edgegroup.Service
|
|
|
|
EdgeJobService *edgejob.Service
|
|
|
|
EdgeStackService *edgestack.Service
|
|
|
|
EndpointGroupService *endpointgroup.Service
|
|
|
|
EndpointService *endpoint.Service
|
|
|
|
EndpointRelationService *endpointrelation.Service
|
|
|
|
ExtensionService *extension.Service
|
|
|
|
HelmUserRepositoryService *helmuserrepository.Service
|
|
|
|
RegistryService *registry.Service
|
|
|
|
ResourceControlService *resourcecontrol.Service
|
|
|
|
RoleService *role.Service
|
|
|
|
ScheduleService *schedule.Service
|
|
|
|
SettingsService *settings.Service
|
|
|
|
SSLSettingsService *ssl.Service
|
|
|
|
StackService *stack.Service
|
|
|
|
TagService *tag.Service
|
|
|
|
TeamMembershipService *teammembership.Service
|
|
|
|
TeamService *team.Service
|
|
|
|
TunnelServerService *tunnelserver.Service
|
|
|
|
UserService *user.Service
|
|
|
|
VersionService *version.Service
|
|
|
|
WebhookService *webhook.Service
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
2021-09-27 00:52:50 +00:00
|
|
|
func (store *Store) version() (int, error) {
|
|
|
|
version, err := store.VersionService.DBVersion()
|
|
|
|
if err == errors.ErrObjectNotFound {
|
|
|
|
version = 0
|
|
|
|
}
|
|
|
|
return version, err
|
|
|
|
}
|
|
|
|
|
2021-02-22 22:14:52 +00:00
|
|
|
func (store *Store) edition() portainer.SoftwareEdition {
|
|
|
|
edition, err := store.VersionService.Edition()
|
|
|
|
if err == errors.ErrObjectNotFound {
|
|
|
|
edition = portainer.PortainerCE
|
|
|
|
}
|
|
|
|
return edition
|
|
|
|
}
|
|
|
|
|
2016-12-18 05:21:29 +00:00
|
|
|
// NewStore initializes a new Store and the associated services
|
2021-10-01 07:35:43 +00:00
|
|
|
func NewStore(storePath string, fileService portainer.FileService) *Store {
|
|
|
|
return &Store{
|
2018-06-19 11:15:10 +00:00
|
|
|
path: storePath,
|
|
|
|
fileService: fileService,
|
2020-04-16 00:22:08 +00:00
|
|
|
isNew: true,
|
2021-04-06 10:08:43 +00:00
|
|
|
connection: &internal.DbConnection{},
|
2018-06-19 11:15:10 +00:00
|
|
|
}
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Open opens and initializes the BoltDB database.
|
|
|
|
func (store *Store) Open() error {
|
2018-06-19 11:15:10 +00:00
|
|
|
databasePath := path.Join(store.path, databaseFileName)
|
|
|
|
db, err := bolt.Open(databasePath, 0600, &bolt.Options{Timeout: 1 * time.Second})
|
2016-12-18 05:21:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-04-06 10:08:43 +00:00
|
|
|
store.connection.DB = db
|
2017-06-20 11:00:32 +00:00
|
|
|
|
2021-09-29 00:24:26 +00:00
|
|
|
err = store.initServices()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-01 07:35:43 +00:00
|
|
|
// if we have DBVersion in the database then ensure we flag this as NOT a new store
|
|
|
|
if _, err := store.VersionService.DBVersion(); err == nil {
|
|
|
|
store.isNew = false
|
2021-09-29 00:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes the BoltDB database.
|
2021-08-10 04:59:47 +00:00
|
|
|
// Safe to being called multiple times.
|
2016-12-18 05:21:29 +00:00
|
|
|
func (store *Store) Close() error {
|
2021-04-06 10:08:43 +00:00
|
|
|
if store.connection.DB != nil {
|
|
|
|
return store.connection.Close()
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2017-03-12 16:24:15 +00:00
|
|
|
|
2020-04-16 00:22:08 +00:00
|
|
|
// IsNew returns true if the database was just created and false if it is re-using
|
|
|
|
// existing data.
|
|
|
|
func (store *Store) IsNew() bool {
|
|
|
|
return store.isNew
|
|
|
|
}
|
|
|
|
|
2021-04-06 10:08:43 +00:00
|
|
|
// BackupTo backs up db to a provided writer.
|
|
|
|
// It does hot backup and doesn't block other database reads and writes
|
|
|
|
func (store *Store) BackupTo(w io.Writer) error {
|
|
|
|
return store.connection.View(func(tx *bolt.Tx) error {
|
|
|
|
_, err := tx.WriteTo(w)
|
2018-11-05 20:58:15 +00:00
|
|
|
return err
|
2021-04-06 10:08:43 +00:00
|
|
|
})
|
2020-05-20 05:23:15 +00:00
|
|
|
}
|
2021-09-27 00:52:50 +00:00
|
|
|
|
|
|
|
// CheckCurrentEdition checks if current edition is community edition
|
|
|
|
func (store *Store) CheckCurrentEdition() error {
|
|
|
|
if store.edition() != portainer.PortainerCE {
|
|
|
|
return errors.ErrWrongDBEdition
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|