* feat(openamt): Configuration of the OpenAMT capability [INT-6] (#6071)
Co-authored-by: Sven Dowideit <sven.dowideit@portainer.io>
* fix(openamt): fix IsFeatureFlagEnabled, rename MPS Url to MPS Server [INT-6] (#6172)
* feat(docker): allow docker container resource settings without restart EE-1942 (#6065)
Co-authored-by: sam <sam@allofword>
Co-authored-by: sam@gemibook <huapox@126.com>
Co-authored-by: Prabhat Khera <prabhat.khera@gmail.com>
* fix(registry): fix order of registries in drop down menu EE-1939 (#5960)
Co-authored-by: Prabhat Khera <prabhat.khera@portainer.io>
* fix(docker-event-display): EE-1968: support (event_name)[:extra info] for all event Actions, and append it to the output details (#6092)
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* feat(api-key/backend): introducing support for api-key based auth EE-978 (#6079)
* feat(access-token): Multi-auth middleware support EE-1891 (#5936)
* AnyAuth middleware initial implementation with tests
* using mux.MiddlewareFunc instead of custom definition
* removed redundant comments
* - ExtractBearerToken bouncer func made private
- changed helm token handling functionality to use jwt service to convert token to jwt string
- updated tests
- fixed helm list broken test due to missing token in request context
* rename mwCheckAuthentication -> mwCheckJWTAuthentication
* - introduce initial api-key auth support using X-API-KEY header
- added tests to validate x-api-key request header presence
* updated core mwAuthenticatedUser middleware to support multiple auth paradigms
* - simplified anyAuth middleware
- enforcing authmiddleware to implement verificationFunc interface
- created tests for middleware
* simplify bouncer
Co-authored-by: Dmitry Salakhov <to@dimasalakhov.com>
* feat(api-key): user-access-token generation endpoint EE-1889 EE-1888 EE-1895 (#6012)
* user-access-token generation endpoint
* fix comment
* - introduction of apikey service
- seperation of repository from service logic - called in handler
* fixed tests
* - fixed api key prefix
- added tests
* added another test for digest matching
* updated swagger spec for access token creation
* api key response returns raw key and struct - easing testability
* test for api key prefix length
* added another TODO to middleware
* - api-key prefix rune -> string (rune does not auto-encode when response sent back to client)
- digest -> pointer as we want to allow nil values and omit digest in responses (when nil)
* - updated apikey struct
- updated apikey service to support all common operations
- updated apikey repo
- integration of apikey service into bouncer
- added test for all apikey service functions
- boilerplate code for apikey service integration
* - user access token generation tests
- apiKeyLookup updated to support query params
- added api-key tests for query params
- added api-key tests for apiKeyLookup
* get and remove access token handlers
* get and remove access token handler tests
* - delete user deletes all associated api keys
- tests for this functionality
* removed redundant []byte cast
* automatic api-key eviction set within cache for 1 hour
* fixed bug with loop var using final value
* fixed service comment
* ignore bolt error responses
* case-insensitive query param check
* simplified query var assignment
* - added GetAPIKey func to get by unique id
- updated DeleteAPIKey func to not require user ID
- updated tests
* GenerateRandomKey helper func from github.com/gorilla/securecookie moved to codebase
* json response casing for api-keys fixed
* updating api-key will update the cache
* updated golang LRU cache
* using hashicorps golang-LRU cache for api keys
* simplified jwt check in create user access token
* fixed api-key update logic on cache miss
* Prefix generated api-keys with `ptr_` (#6067)
* prefix api-keys with 'ptr_'
* updated apikey description
* refactor
Co-authored-by: Dmitry Salakhov <to@dimasalakhov.com>
* helm list test refactor
* fixed user delete test
* reduce test nil pointer errors
* using correct http 201 created status code for token creation; updated tests
* fixed swagger doc user id path param for user access token based endpoints
* added api-key security openapi spec to existing jwt secured endpoints (#6091)
* fixed flaky test
* apikey datecreated and lastused attrs converted to unix timestamp
* feat(user): added access token datatable. (#6124)
* feat(user): added access token datatable.
* feat(tokens): only display lastUsed time when it is not the default date
* Update app/portainer/views/account/accountController.js
Co-authored-by: zees-dev <63374656+zees-dev@users.noreply.github.com>
* Update app/portainer/views/account/accountController.js
Co-authored-by: zees-dev <63374656+zees-dev@users.noreply.github.com>
* Update app/portainer/views/account/accountController.js
Co-authored-by: zees-dev <63374656+zees-dev@users.noreply.github.com>
* Update app/portainer/components/datatables/access-tokens-datatable/accessTokensDatatableController.js
Co-authored-by: zees-dev <63374656+zees-dev@users.noreply.github.com>
* Update app/portainer/services/api/userService.js
Co-authored-by: zees-dev <63374656+zees-dev@users.noreply.github.com>
* feat(improvements): proposed datatable improvements to speed up dev time (#6138)
* modal code update
* updated datatable filenames, updated controller to be default class export
* fix(access-token): code improvement.
Co-authored-by: zees-dev <63374656+zees-dev@users.noreply.github.com>
* feat(apikeys): create access token view initial implementation EE-1886 (#6129)
* CopyButton implementation
* Code component implementation
* ToolTip component migration to another folder
* TextTip component implementation - continued
* form Heading component
* Button component updated to be more dynamic
* copybutton - small size
* form control pass tip error
* texttip small text
* CreateAccessToken react feature initial implementation
* create user access token angularjs view implementation
* registration of CreateAccessToken component in AngularJS
* user token generation API request moved to angular service, method passed down instead
* consistent naming of access token operations; clustered similar code together
* any user can add access token
* create access token page routing
* moved code component to the correct location
* removed isadmin check as all functionality applicable to all users
* create access token angular view moved up a level
* fixed PR issues, updated PR
* addressed PR issues/improvements
* explicit hr for horizontal line
* fixed merge conflict storybook build breaking
* - apikey test
- cache test
* addressed testing issues:
- description validations
- remove token description link on table
* fix(api-keys): user role change evicts user keys in cache EE-2113 (#6168)
* user role change evicts user api keys in cache
* EvictUserKeyCache -> InvalidateUserKeyCache
* godoc for InvalidateUserKeyCache func
* additional test line
* disable add access token button after adding token to prevent spam
Co-authored-by: Dmitry Salakhov <to@dimasalakhov.com>
Co-authored-by: fhanportainer <79428273+fhanportainer@users.noreply.github.com>
* fix(k8s/ingress): ensure new ports are only added to ingress only if app is published via ingress (#6153)
* fix(k8s/ingress): ensure new ports are only added to ingress only if app is published via ingress
* refactor(k8s/ingress): removed deleted ports of ingress in a single pass
* Update endpointItem.html (#6142)
feat(home): show cpu and ram for non local endpoints EE-2077
* fix(react): use ctrl directive in WidgetTitle component [EE-2118] (#6181)
* Revert "fix(openamt): fix IsFeatureFlagEnabled, rename MPS Url to MPS Server [INT-6] (#6172)" (#6182)
This reverts commit c267355759.
* fix(openamt): fix IsFeatureFlagEnabled, rename MPS Url to MPS Server (#6185)
Co-authored-by: cheloRydel <marcelorydel26@gmail.com>
* feat(registry) EE-806 add support for AWS ECR (#6165)
* feat(ecr) EE-806 add support for aws ecr
* feat(ecr) EE-806 fix wrong doc for Ecr Region
Co-authored-by: Simon Meng <simon.meng@portainer.io>
* verify repositry URL from template json when coping (#6036) (#6111)
* fix(environments): show kubeconfig env list in dark mode (#6156)
* fix(container): prevent user from editing the portainer container it self EE-917 (#6093)
* fix(container): prevent from editing portainer container
* fix(container): prevent from editing portainer container
* Missing kill operation
* fix(container): enhance creating stack from template
* fix(docker): prevent user from editing the portainer container itself EE-917
* fix(docker): enhance code style
* fix(container): fix issues from code review
* fix(container): enhance creating stack from template
* fix(container): some code review issues
* fix(container): disable leave network when the container is portainer
* fix(container): disable leave network when the container is portainer
* Fix(stack)/update StackUpdateGit swagger info to POST EE-2019 (#6176)
* fix/EE-2019/Fix-stackgitupdate-swagger
Co-authored-by: sunportainer <ericsun@SG1.local>
* feat(config): add base url support EE-506 (#5999)
* feat(openamt): add AMT Devices information in Environments view [INT-8] (#6169)
* feat(openamt): add AMT Devices Ouf of Band Managamenet actions [INT-9] (#6171)
* feat(openamt): add AMT Devices KVM Connection [INT-10] (#6179)
* feat(openamt): Enhance the Environments MX to activate OpenAMT on compatible environments [INT-7] (#6196)
* fallback to depracted copy text if clipboard api not available (#6200) (#6218)
* - standard user cannot delete another users api-keys (#6208) (#6217)
- added new method to get api key by ID
- added tests
* fix app templates symbol (#6221)
* feat(webhook) EE-2125 send registry auth haeder when update swarms service via webhook (#6220)
* feat(webhook) EE-2125 add some helpers to registry utils
* feat(webhook) EE-2125 persist registryID when creating a webhook
* feat(webhook) EE-2125 send registry auth header when executing a webhook
* feat(webhook) EE-2125 send registryID to backend when creating a service with webhook
* feat(webhook) EE-2125 use the initial registry ID to create webhook on editing service screen
* feat(webhook) EE-2125 update webhook when update registry
* feat(webhook) EE-2125 add endpoint of update webhook
* feat(webhook) EE-2125 code cleanup
* feat(webhook) EE-2125 fix a typo
* feat(webhook) EE-2125 fix circle import issue with unit test
Co-authored-by: Simon Meng <simon.meng@portainer.io>
* fix(kubeconfig): show kubeconfig download button for non admin users [EE-2123] (#6204)
Co-authored-by: Simon Meng <simon.meng@portainer.io>
* fix data-cy for k8s cluster menu (#6226)
LGTM
* feat(stack): make stack created from app template editable EE-1941 (#6104)
feat(stack): make stack from app template editable
* feat(openamt): Enable KVM by default [INT-25] (#6228)
* fix(container):disable Duplicate/Edit button when the container is portainer (#6223)
* fix/ee-1909/show-pull-image-error (#6195)
Co-authored-by: sunportainer <ericsun@SG1.local>
* feat(fdo): implement the FDO configuration settings INT-19 (#6238)
feat(fdo): implement the FDO configuration settings INT-19
* feat(fdo): implement Owner client INT-17 (#6231)
feat(fdo): implement Owner client INT-17
* feat(cy): add data-cy to helm install button (#6241)
* feat(cy): add data-cy to add registry button (#6242)
* refactor(app): convert root folder files to es6 (#4159)
* refactor(app): duplicate constants as es6 exports (#4158)
* fix(docker): provide workaround to save network name variable (#6080)
* fix/EE-1862/unable-to-stop-or-remove-stack workaround for var without default value in yaml file
* fix/EE-1862/unable-to-stop-or-remove-stack check yaml file
* fixed func and var names
* wrapper error and used bool for stringset
* UT case for createNetworkEnvFile
* UT case for %s=%s
* powerful StringSet
* wrapper error for extract network name
* wrapper all the return err
* store more env
* put to env file
* make default value None
* feat(openamt): hide wireless config in OpenAMT form (#6250)
* feat(openamt): Increase OpenAMT timeouts [INT-30] (#6253)
* feat(openamt): Disable the ability to use KVM and OOB actions on a MPS disconnected device [INT-36] (#6254)
* feat: gzip static resources (#6258)
* fix(ssl)//handle --sslcert and --sslkey ee-2106 (#6203)
* fix/ee-2106/handle-sslcert-sslkey
Co-authored-by: sunportainer <ericsun@SG1.local>
* fix(server):support disable https only ee-2068 (#6232)
* fix/ee-2068/disable-forcely-https
* refactor(endpoints): remove endpointProvider from views [EE-1136] (#5359)
[EE-1136]
* feat(app): introduce component library in react [EE-1816] (#6236)
* refactor(app): replace notification with es6 service (#6015) [EE-1897]
chore(app): format
* refactor(containers): remove the dependency on angular modal service (#6017) [EE-1898]
* refactor(app): remove angular from http-request [EE-1899] (#6016)
* feat(app): add axios [EE-2035](#6077)
* refactor(feature): remove angular dependency from feature service [EE-2034] (#6078)
* refactor(app): replace box-selector with react component (#6046)
fix: rename angular2react
refactor(app): make box-selector type generic
feat(app): add story for box-selector
feat(app): test box-selector
feat(app): add stories for box selector item
fix(app): remove unneccesary element
refactor(app): remove assign
* feat(feature): add be-indicator in react [EE-2005] (#6106)
* refactor(app): add react components for headers [EE-1949] (#6023)
* feat(auth): provide user context
* feat(app): added base header component [EE-1949]
style(app): reformat
refactor(app/header): use same api as angular
* feat(app): add breadcrumbs component [EE-2024]
* feat(app): remove u element from user links
* fix(users): handle axios errors
Co-authored-by: Chaim Lev-Ari <chiptus@gmail.com>
* refactor(app): convert switch component to react [EE-2005] (#6025)
Co-authored-by: Marcelo Rydel <marcelorydel26@gmail.com>
* feat(fdo): add import device UI [INT-20] (#6240)
feat(fdo): add import device UI INT-20
* release 2.11
* chore(store) EE-1981: Refactor/store/error checking, and other refactoring (#6173)
* use the Store interface IsErrObjectNotFound() to avoid revealing internal errors
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* what happens when you extract the datastore interfaces into their own package
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* Start renaming Storage methods
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* extract the boltdb specific code from the Portainer storage code (example, the others need the same)
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* more extract bolt.Tx from datastore code
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* minimise imports by putting moving the struct definition into the file that needs the Service imports
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* more extraction of boltdb.Tx
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* extract the use of bucket.SetSequence
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* almost done - just endpoint.Synchonise :/
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* so, endpoint.Synchonize looks hard, but i can't find where we use it, so 'delete first refactoring'
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* fix test compile errors
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* test compile fixes after rebase
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* fix a mis-remembering I had wrt deserialisation - last time i used AnyData - jsoniter's bindTo looks interesting for the same reason
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* set us up to make the connection an interface
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* make the db connection a datastore interface, and separate out our datastore services from the bolt ones
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* rename methods to something less oltdb internals specific
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* these errors are not boltdb secific
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* start using the db-backend factory method too
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* export boltdb raw in case we can't export from the service layer
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* add a raw export from boltdb to yaml for broken db's, and an export services to yaml in backup
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* add the version info by hand for now
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* actually, the export from services can be fully typed - its the import that needs to do more work
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* redo raw export, and make import capable of using it
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* add DockerHub
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* migration from anything older than v1.21.0 has been broken for quite a while, deleting the un-tested code
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* fix go test ./... again
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* my goland wasn't setup to gofmt
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* move the two extremely dubious migration tests down into store, so they can use the test store code
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* the migrator is now free of boltdb
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* reverse goland overzealous replcement of internal with boltdb
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* more undo over-zealous goland internal->boltdb
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* yay, now bolt is only mentioned inside the api/database/ dir
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* and this might be the last of the boltdb references?
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* add todo
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* extract the store code into a separate module too
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* don't need the fileService in boltdb anymore
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* use IsErrObjectNotFound()
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* use a string to select what database backend we use
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* make isNew store an ephemeral bool that doesn't stay true after we've initialised it
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* move the import.json wip to a separate file so its more obvious - we'll be using it for testing, emergency fixups, and in the next part of the store work, when we improve migrations and data model lifecycles
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* undo vscode formatting html
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* fix app templates symbol (#6221)
* feat(webhook) EE-2125 send registry auth haeder when update swarms service via webhook (#6220)
* feat(webhook) EE-2125 add some helpers to registry utils
* feat(webhook) EE-2125 persist registryID when creating a webhook
* feat(webhook) EE-2125 send registry auth header when executing a webhook
* feat(webhook) EE-2125 send registryID to backend when creating a service with webhook
* feat(webhook) EE-2125 use the initial registry ID to create webhook on editing service screen
* feat(webhook) EE-2125 update webhook when update registry
* feat(webhook) EE-2125 add endpoint of update webhook
* feat(webhook) EE-2125 code cleanup
* feat(webhook) EE-2125 fix a typo
* feat(webhook) EE-2125 fix circle import issue with unit test
Co-authored-by: Simon Meng <simon.meng@portainer.io>
* fix(kubeconfig): show kubeconfig download button for non admin users [EE-2123] (#6204)
Co-authored-by: Simon Meng <simon.meng@portainer.io>
* fix data-cy for k8s cluster menu (#6226)
LGTM
* feat(stack): make stack created from app template editable EE-1941 (#6104)
feat(stack): make stack from app template editable
* fix(container):disable Duplicate/Edit button when the container is portainer (#6223)
* fix/ee-1909/show-pull-image-error (#6195)
Co-authored-by: sunportainer <ericsun@SG1.local>
* feat(cy): add data-cy to helm install button (#6241)
* feat(cy): add data-cy to add registry button (#6242)
* refactor(app): convert root folder files to es6 (#4159)
* refactor(app): duplicate constants as es6 exports (#4158)
* fix(docker): provide workaround to save network name variable (#6080)
* fix/EE-1862/unable-to-stop-or-remove-stack workaround for var without default value in yaml file
* fix/EE-1862/unable-to-stop-or-remove-stack check yaml file
* fixed func and var names
* wrapper error and used bool for stringset
* UT case for createNetworkEnvFile
* UT case for %s=%s
* powerful StringSet
* wrapper error for extract network name
* wrapper all the return err
* store more env
* put to env file
* make default value None
* feat: gzip static resources (#6258)
* fix(ssl)//handle --sslcert and --sslkey ee-2106 (#6203)
* fix/ee-2106/handle-sslcert-sslkey
Co-authored-by: sunportainer <ericsun@SG1.local>
* fix(server):support disable https only ee-2068 (#6232)
* fix/ee-2068/disable-forcely-https
* feat(store): implement store tests EE-2112 (#6224)
* add store tests
* add some more tests
* Update missing helm user repo methods
* remove redundant comments
* add webhook export
* update webhooks
* use the Store interface IsErrObjectNotFound() to avoid revealing internal errors
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* what happens when you extract the datastore interfaces into their own package
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* Start renaming Storage methods
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* extract the boltdb specific code from the Portainer storage code (example, the others need the same)
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* more extract bolt.Tx from datastore code
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* minimise imports by putting moving the struct definition into the file that needs the Service imports
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* more extraction of boltdb.Tx
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* extract the use of bucket.SetSequence
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* almost done - just endpoint.Synchonise :/
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* so, endpoint.Synchonize looks hard, but i can't find where we use it, so 'delete first refactoring'
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* fix test compile errors
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* test compile fixes after rebase
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* fix a mis-remembering I had wrt deserialisation - last time i used AnyData - jsoniter's bindTo looks interesting for the same reason
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* set us up to make the connection an interface
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* make the db connection a datastore interface, and separate out our datastore services from the bolt ones
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* rename methods to something less oltdb internals specific
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* these errors are not boltdb secific
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* start using the db-backend factory method too
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* export boltdb raw in case we can't export from the service layer
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* add a raw export from boltdb to yaml for broken db's, and an export services to yaml in backup
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* add the version info by hand for now
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* actually, the export from services can be fully typed - its the import that needs to do more work
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* redo raw export, and make import capable of using it
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* add DockerHub
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* migration from anything older than v1.21.0 has been broken for quite a while, deleting the un-tested code
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* fix go test ./... again
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* my goland wasn't setup to gofmt
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* move the two extremely dubious migration tests down into store, so they can use the test store code
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* the migrator is now free of boltdb
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* reverse goland overzealous replcement of internal with boltdb
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* more undo over-zealous goland internal->boltdb
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* yay, now bolt is only mentioned inside the api/database/ dir
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* and this might be the last of the boltdb references?
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* add todo
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* extract the store code into a separate module too
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* don't need the fileService in boltdb anymore
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* use IsErrObjectNotFound()
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* use a string to select what database backend we use
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* make isNew store an ephemeral bool that doesn't stay true after we've initialised it
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* move the import.json wip to a separate file so its more obvious - we'll be using it for testing, emergency fixups, and in the next part of the store work, when we improve migrations and data model lifecycles
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* undo vscode formatting html
Signed-off-by: Sven Dowideit <sven.dowideit@portainer.io>
* Update missing helm user repo methods
* feat(store): implement store tests EE-2112 (#6224)
* add store tests
* add some more tests
* remove redundant comments
* add webhook export
* update webhooks
* fix build issues after rebasing
* move migratorparams
* remove unneeded integer type conversions
* disable the db import/export for now
Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com>
Co-authored-by: cong meng <mcpacino@gmail.com>
Co-authored-by: Simon Meng <simon.meng@portainer.io>
Co-authored-by: Marcelo Rydel <marcelorydel26@gmail.com>
Co-authored-by: Hao Zhang <hao.zhang@portainer.io>
Co-authored-by: sunportainer <93502624+sunportainer@users.noreply.github.com>
Co-authored-by: sunportainer <ericsun@SG1.local>
Co-authored-by: wheresolivia <78844659+wheresolivia@users.noreply.github.com>
Co-authored-by: Chaim Lev-Ari <chiptus@users.noreply.github.com>
Co-authored-by: Chao Geng <93526589+chaogeng77977@users.noreply.github.com>
Co-authored-by: Dmitry Salakhov <to@dimasalakhov.com>
Co-authored-by: Matt Hook <hookenz@gmail.com>
* add switch for react query devtools based on .env (#6280)
* refactor(fdo): fix develop merge issues
* feat(openamt): Do not fetch OpenAMT details for an unassociated Edge endpoint (#6273)
* fix(intel): Fix switches params (#6282)
* feat(cy): add data-cy to add kube volume views (#6285)
* fix(intel): fix switches params [EE-2166] (#6284)
* fix(intel): fix switches params
* feat(settings): prevent openamt panel to render
* feat(openamt): preload existing AMT settings (#6283)
* feat(frontend): upgrade frontend dependencies DTD-11 (#6244)
* upgrade webpack, eslint, storybook and other dependencies
* feat(openamt): Better UI/UX for AMT activation loading [INT-39] (#6290)
* feat(openamt): Remove wireless config related code [INT-41] (#6291)
* fix(db): fix marshalling code so that we're compatible with the existing db (#6286)
* special handling for non-json types
* added tests for json MarshalObject
* another attempt
* Fix marshal/unmarshal code for VERSION bucket
* use short form
* don't discard err
* fix the json_test.go
* remove duplicate string
* added uuid tests
* updated case for strings
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
* feat(service): rebase and recommit (#6245)
* feat(service): duplication validation for configs and secrets EE-1974 (#6266)
feat(service): check if configs or secrets are duplicated
* yarn install
* feat(openamt): change kvm redirection for pop up, always enable features [INT-37] (#6292)
* feat(openamt): change kvm redirection for pop up, always enable features [INT-37] (#6293)
* feat(app): introduce form framework [EE-1946] (#6272)
* fix(modals): upgrade jquery versions (#6303)
* support upgrading (#6256)
* fix(app): main services [EE-1896] (#6279)
[EE-1896]
* chore(build): add script to analyze webpack bundle [EE-2132] (#6259)
* chore(build): add script to analyze webpack bundle
* chore(build): use single dep (lodash,moment)
* Fix(UI): disable autofill username input EE-2140 (#6252)
* fix/ee-2140/disable-autofill-username
* fix scroolbar shown in confirmation dialogs (#6264)
* fix(home): display tags properly [EE-2153] (#6275)
fix(home): display tags properly EE-2153
* fix(teams): create more then one team [EE-2184] (#6305)
fixes [EE-2184]
* feat(openmt): use .ts services with axios for OpenAMT (#6312)
* fix(kubeconfig): fix modal inputType [EE-2325] (#6317)
* Minor code cleanup.
* refactor(app): create a composed header component [EE-2329] (#6326)
* refactor(app): create a composed header component
refactor(app): support single child breadcrumbs
fix(app): fix breadcrumbs warning
* refactor(app): import breadcrumbs
* refactor(app): support object breadcrumbs
* chore(app): write tests for header components
* fix(fdo): move the FDO client code to the hostmanagement folder INT-44 (#6345)
* feat(react): migrate analytics interface to react. (#6296) [EE-2100]
* refactor(containers): replace containers datatable with react component [EE-1815] (#6059)
* feat(react): add FileUploadField and FileUploadForm components [EE-2336] (#6350)
* refactor(intel): Add Edge Compute Settings view (#6351)
* refactor(app): create access-control-form react component [EE-2332] (#6346)
* refactor(app): create access-control-form react component [EE-2332]
fix [EE-2332]
* chore(tests): setup msw for async tests and stories
chore(sb): add msw support for storybook
* refactor(access-control): move loading into component
* fix(app): fix users and teams selector stories
* chore(access-control): write test for validation
* refactor(environments): remove angular dep from service [EE-2346] (#6360)
refactor(environments): parse axios error
* fix(ldap): show BE border correctly (#6357)
* chore(tests): update AccessControlForm snapshots [EE-2348] (#6361)
* feat(fdo): add FDO profiles INT-22 (#6363)
feat(fdo): add FDO profiles INT-22
* feat(k8s): add ingressClassName to payload EE-2129 (#6265)
* add ingressClassName to payload
* add IngressClass.Name into formValues
* feat: bump golang version to 1.17.6 (#6366)
* fix(download-plugin): Image name not available when using watchtower or similar (#6225)
* make plugin version 1.0.22 and correct download-file name
* updated to v2.0.0-rc.2
* rollback download_docker_compose_binary.sh
* fix(edgestacks): create new stack [EE-2178] (#6311)
* fix(edgestacks): create new stack [EE-2178]
[EE-2178]
* refactor(edgestacks): id is required on create
* feat(i18n): add support for multiple languages (#6270)
feat(users): add i18n to create access token
chore(app): remove test code
* refactor: unit tests (#6367)
* fix(registries): sync code with ee [EE-2176] (#6355)
fixes [EE-2176]
* fix(fdo): fix incorrect profile URL INT-45 (#6377)
* fixed husky version
* fix go.mod with go mod tidy
* fix background color for boxselector in dark/high contrast theme (#6378)
* fix(auth): prevent login for non admin for ldap and oauth [EE-648] (#5283)
* fix(stacks): show stack containers [EE-2359] (#6375)
Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>
* fix(azure): parse validation error [EE-2334] (#6341)
fixes [EE-2334]
* feat(edge): migrate OpenAMT devices views to Edge Devices [EE-2322] (#6373)
* chore(i18n): set extract output path (#6384)
* feat(intel): OpenAMT UI/UX adjustments (#6394)
* only allow edge agent as edge device
* show all edge agent environments on Edge Devices view
* fix automatic team membership toggle issue (#6382)
* feat(stack): detach git based stacks from git EE-2143 (#6307)
* feat(stack): detach git based stacks from git
* feat(fdo): add the ability to import multiple ownership vouchers at once EE-2324 (#6395)
* fix(edge): settings edge compute alert (#6402)
* EE-1958 Set default value of auth and auto-update to off in page Manifest and stacks (#6380)
* fix(oauth): change default microsoft logout url [EE-2044] (#6324)
* feat(k8s): Allow mix services for k8s app EE-1791 (#6198)
allow a mix of services for k8s in ui
* fix(docker-compose): add logic control for docker compose force recreate EE-2356
* feat(database): add encryption support EE-1983 (#6316)
* bootstrap encryption key
* secret key message change in cli and secret key file content trimmed
* Migrate encryption code to latest version
* pull in newer code
* tidying up
* working data encryption layer
* fix tests
* remove stray comment
* fix a few minor issues and improve the comments
* split out databasefilename with param to two methods to be more obvious
* DB encryption integration (#6374)
* json methods moved under DBConnection
* store encryption fixed
* cleaned
* review comments addressed
* newstore value fixed
* backup test updated
* logrus format config updated
* Fix for newStore
Co-authored-by: Matt Hook <hookenz@gmail.com>
* Minor improvements
* Improve the export code. Add missing webhook for import
* rename HelmUserRepositorys to HelmUserRepositories
* fix logging messages
* when starting portainer with a key (first use) http is disabled by default. But when starting fresh without a key, http is enabled?
* Fix bug for default settings on new installs
Co-authored-by: Prabhat Khera <prabhat.khera@portainer.io>
Co-authored-by: Prabhat Khera <91852476+prabhat-org@users.noreply.github.com>
* fix(app): add github action for linting and formatting [EE-2344] (#6356)
* remove pagination, add useMemo for devices result array (#6409)
* feat(edge): minor Edge Devices (AMT) UI fixes (#6410)
* chore(eslint): fix versions
* chore(app): reformat codebase
* change add edge agent modal behaviour, fix yarn.lock
* fix use pagination
* remove extractedTranslations folder
* feat(edge): add FDO Profiles Datatable [EE-2406] (#6415)
* feat(edge): add KVM workaround tooltip (#6441)
* yarn install
* fix merge conflicts
* revert .codeclimate.yml change
* gofmt
* use yarn.lock from develop
* remove unused OpenAMT files
* revert Button.tsx changes, delete helm binary
* feat(edge): Add default FDO profile (#6450)
* feat(edge): add settings to disable trust on first connect and enforce Edge ID INT-1 EE-2410 (#6429)
Co-authored-by: Sven Dowideit <sven.dowideit@portainer.io>
Co-authored-by: Prabhat Khera <91852476+prabhat-org@users.noreply.github.com>
Co-authored-by: sam <sam@allofword>
Co-authored-by: sam@gemibook <huapox@126.com>
Co-authored-by: Prabhat Khera <prabhat.khera@gmail.com>
Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com>
Co-authored-by: Prabhat Khera <prabhat.khera@portainer.io>
Co-authored-by: zees-dev <63374656+zees-dev@users.noreply.github.com>
Co-authored-by: Dmitry Salakhov <to@dimasalakhov.com>
Co-authored-by: fhanportainer <79428273+fhanportainer@users.noreply.github.com>
Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>
Co-authored-by: huib-portainer <77944876+huib-portainer@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>
Co-authored-by: Chaim Lev-Ari <chiptus@users.noreply.github.com>
Co-authored-by: Hao Zhang <hao.zhang@portainer.io>
Co-authored-by: sunportainer <93502624+sunportainer@users.noreply.github.com>
Co-authored-by: sunportainer <ericsun@SG1.local>
Co-authored-by: andres-portainer <91705312+andres-portainer@users.noreply.github.com>
Co-authored-by: wheresolivia <78844659+wheresolivia@users.noreply.github.com>
Co-authored-by: Chao Geng <93526589+chaogeng77977@users.noreply.github.com>
Co-authored-by: Anthony Lapenna <anthony.lapenna@portainer.io>
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
Co-authored-by: andres-portainer <andres-portainer@users.noreply.github.com>
Co-authored-by: Hui <arris_li@hotmail.com>
Co-authored-by: Chaim Lev-Ari <chiptus@gmail.com>
674 lines
20 KiB
Go
674 lines
20 KiB
Go
package datastore
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"strconv"
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/portainer/portainer/api/dataservices"
|
|
"github.com/portainer/portainer/api/dataservices/apikeyrepository"
|
|
"github.com/portainer/portainer/api/dataservices/customtemplate"
|
|
"github.com/portainer/portainer/api/dataservices/dockerhub"
|
|
"github.com/portainer/portainer/api/dataservices/edgegroup"
|
|
"github.com/portainer/portainer/api/dataservices/edgejob"
|
|
"github.com/portainer/portainer/api/dataservices/edgestack"
|
|
"github.com/portainer/portainer/api/dataservices/endpoint"
|
|
"github.com/portainer/portainer/api/dataservices/endpointgroup"
|
|
"github.com/portainer/portainer/api/dataservices/endpointrelation"
|
|
"github.com/portainer/portainer/api/dataservices/extension"
|
|
"github.com/portainer/portainer/api/dataservices/fdoprofile"
|
|
"github.com/portainer/portainer/api/dataservices/helmuserrepository"
|
|
"github.com/portainer/portainer/api/dataservices/registry"
|
|
"github.com/portainer/portainer/api/dataservices/resourcecontrol"
|
|
"github.com/portainer/portainer/api/dataservices/role"
|
|
"github.com/portainer/portainer/api/dataservices/schedule"
|
|
"github.com/portainer/portainer/api/dataservices/settings"
|
|
"github.com/portainer/portainer/api/dataservices/ssl"
|
|
"github.com/portainer/portainer/api/dataservices/stack"
|
|
"github.com/portainer/portainer/api/dataservices/tag"
|
|
"github.com/portainer/portainer/api/dataservices/team"
|
|
"github.com/portainer/portainer/api/dataservices/teammembership"
|
|
"github.com/portainer/portainer/api/dataservices/tunnelserver"
|
|
"github.com/portainer/portainer/api/dataservices/user"
|
|
"github.com/portainer/portainer/api/dataservices/version"
|
|
"github.com/portainer/portainer/api/dataservices/webhook"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// Store defines the implementation of portainer.DataStore using
|
|
// BoltDB as the storage system.
|
|
type Store struct {
|
|
connection portainer.Connection
|
|
|
|
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
|
|
FDOProfilesService *fdoprofile.Service
|
|
HelmUserRepositoryService *helmuserrepository.Service
|
|
RegistryService *registry.Service
|
|
ResourceControlService *resourcecontrol.Service
|
|
RoleService *role.Service
|
|
APIKeyRepositoryService *apikeyrepository.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
|
|
}
|
|
|
|
func (store *Store) initServices() error {
|
|
authorizationsetService, err := role.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.RoleService = authorizationsetService
|
|
|
|
customTemplateService, err := customtemplate.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.CustomTemplateService = customTemplateService
|
|
|
|
dockerhubService, err := dockerhub.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.DockerHubService = dockerhubService
|
|
|
|
edgeStackService, err := edgestack.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.EdgeStackService = edgeStackService
|
|
|
|
edgeGroupService, err := edgegroup.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.EdgeGroupService = edgeGroupService
|
|
|
|
edgeJobService, err := edgejob.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.EdgeJobService = edgeJobService
|
|
|
|
endpointgroupService, err := endpointgroup.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.EndpointGroupService = endpointgroupService
|
|
|
|
endpointService, err := endpoint.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.EndpointService = endpointService
|
|
|
|
endpointRelationService, err := endpointrelation.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.EndpointRelationService = endpointRelationService
|
|
|
|
extensionService, err := extension.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.ExtensionService = extensionService
|
|
|
|
fdoProfilesService, err := fdoprofile.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.FDOProfilesService = fdoProfilesService
|
|
|
|
helmUserRepositoryService, err := helmuserrepository.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.HelmUserRepositoryService = helmUserRepositoryService
|
|
|
|
registryService, err := registry.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.RegistryService = registryService
|
|
|
|
resourcecontrolService, err := resourcecontrol.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.ResourceControlService = resourcecontrolService
|
|
|
|
settingsService, err := settings.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.SettingsService = settingsService
|
|
|
|
sslSettingsService, err := ssl.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.SSLSettingsService = sslSettingsService
|
|
|
|
stackService, err := stack.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.StackService = stackService
|
|
|
|
tagService, err := tag.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.TagService = tagService
|
|
|
|
teammembershipService, err := teammembership.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.TeamMembershipService = teammembershipService
|
|
|
|
teamService, err := team.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.TeamService = teamService
|
|
|
|
tunnelServerService, err := tunnelserver.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.TunnelServerService = tunnelServerService
|
|
|
|
userService, err := user.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.UserService = userService
|
|
|
|
apiKeyService, err := apikeyrepository.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.APIKeyRepositoryService = apiKeyService
|
|
|
|
versionService, err := version.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.VersionService = versionService
|
|
|
|
webhookService, err := webhook.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.WebhookService = webhookService
|
|
|
|
scheduleService, err := schedule.NewService(store.connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.ScheduleService = scheduleService
|
|
|
|
return nil
|
|
}
|
|
|
|
// CustomTemplate gives access to the CustomTemplate data management layer
|
|
func (store *Store) CustomTemplate() dataservices.CustomTemplateService {
|
|
return store.CustomTemplateService
|
|
}
|
|
|
|
// EdgeGroup gives access to the EdgeGroup data management layer
|
|
func (store *Store) EdgeGroup() dataservices.EdgeGroupService {
|
|
return store.EdgeGroupService
|
|
}
|
|
|
|
// EdgeJob gives access to the EdgeJob data management layer
|
|
func (store *Store) EdgeJob() dataservices.EdgeJobService {
|
|
return store.EdgeJobService
|
|
}
|
|
|
|
// EdgeStack gives access to the EdgeStack data management layer
|
|
func (store *Store) EdgeStack() dataservices.EdgeStackService {
|
|
return store.EdgeStackService
|
|
}
|
|
|
|
// Environment(Endpoint) gives access to the Environment(Endpoint) data management layer
|
|
func (store *Store) Endpoint() dataservices.EndpointService {
|
|
return store.EndpointService
|
|
}
|
|
|
|
// EndpointGroup gives access to the EndpointGroup data management layer
|
|
func (store *Store) EndpointGroup() dataservices.EndpointGroupService {
|
|
return store.EndpointGroupService
|
|
}
|
|
|
|
// EndpointRelation gives access to the EndpointRelation data management layer
|
|
func (store *Store) EndpointRelation() dataservices.EndpointRelationService {
|
|
return store.EndpointRelationService
|
|
}
|
|
|
|
// FDOProfile gives access to the FDOProfile data management layer
|
|
func (store *Store) FDOProfile() dataservices.FDOProfileService {
|
|
return store.FDOProfilesService
|
|
}
|
|
|
|
// HelmUserRepository access the helm user repository settings
|
|
func (store *Store) HelmUserRepository() dataservices.HelmUserRepositoryService {
|
|
return store.HelmUserRepositoryService
|
|
}
|
|
|
|
// Registry gives access to the Registry data management layer
|
|
func (store *Store) Registry() dataservices.RegistryService {
|
|
return store.RegistryService
|
|
}
|
|
|
|
// ResourceControl gives access to the ResourceControl data management layer
|
|
func (store *Store) ResourceControl() dataservices.ResourceControlService {
|
|
return store.ResourceControlService
|
|
}
|
|
|
|
// Role gives access to the Role data management layer
|
|
func (store *Store) Role() dataservices.RoleService {
|
|
return store.RoleService
|
|
}
|
|
|
|
// APIKeyRepository gives access to the api-key data management layer
|
|
func (store *Store) APIKeyRepository() dataservices.APIKeyRepository {
|
|
return store.APIKeyRepositoryService
|
|
}
|
|
|
|
// Settings gives access to the Settings data management layer
|
|
func (store *Store) Settings() dataservices.SettingsService {
|
|
return store.SettingsService
|
|
}
|
|
|
|
// SSLSettings gives access to the SSL Settings data management layer
|
|
func (store *Store) SSLSettings() dataservices.SSLSettingsService {
|
|
return store.SSLSettingsService
|
|
}
|
|
|
|
// Stack gives access to the Stack data management layer
|
|
func (store *Store) Stack() dataservices.StackService {
|
|
return store.StackService
|
|
}
|
|
|
|
// Tag gives access to the Tag data management layer
|
|
func (store *Store) Tag() dataservices.TagService {
|
|
return store.TagService
|
|
}
|
|
|
|
// TeamMembership gives access to the TeamMembership data management layer
|
|
func (store *Store) TeamMembership() dataservices.TeamMembershipService {
|
|
return store.TeamMembershipService
|
|
}
|
|
|
|
// Team gives access to the Team data management layer
|
|
func (store *Store) Team() dataservices.TeamService {
|
|
return store.TeamService
|
|
}
|
|
|
|
// TunnelServer gives access to the TunnelServer data management layer
|
|
func (store *Store) TunnelServer() dataservices.TunnelServerService {
|
|
return store.TunnelServerService
|
|
}
|
|
|
|
// User gives access to the User data management layer
|
|
func (store *Store) User() dataservices.UserService {
|
|
return store.UserService
|
|
}
|
|
|
|
// Version gives access to the Version data management layer
|
|
func (store *Store) Version() dataservices.VersionService {
|
|
return store.VersionService
|
|
}
|
|
|
|
// Webhook gives access to the Webhook data management layer
|
|
func (store *Store) Webhook() dataservices.WebhookService {
|
|
return store.WebhookService
|
|
}
|
|
|
|
type storeExport struct {
|
|
CustomTemplate []portainer.CustomTemplate `json:"customtemplates,omitempty"`
|
|
EdgeGroup []portainer.EdgeGroup `json:"edgegroups,omitempty"`
|
|
EdgeJob []portainer.EdgeJob `json:"edgejobs,omitempty"`
|
|
EdgeStack []portainer.EdgeStack `json:"edge_stack,omitempty"`
|
|
Endpoint []portainer.Endpoint `json:"endpoints,omitempty"`
|
|
EndpointGroup []portainer.EndpointGroup `json:"endpoint_groups,omitempty"`
|
|
EndpointRelation []portainer.EndpointRelation `json:"endpoint_relations,omitempty"`
|
|
Extensions []portainer.Extension `json:"extension,omitempty"`
|
|
HelmUserRepository []portainer.HelmUserRepository `json:"helm_user_repository,omitempty"`
|
|
Registry []portainer.Registry `json:"registries,omitempty"`
|
|
ResourceControl []portainer.ResourceControl `json:"resource_control,omitempty"`
|
|
Role []portainer.Role `json:"roles,omitempty"`
|
|
Schedules []portainer.Schedule `json:"schedules,omitempty"`
|
|
Settings portainer.Settings `json:"settings,omitempty"`
|
|
SSLSettings portainer.SSLSettings `json:"ssl,omitempty"`
|
|
Stack []portainer.Stack `json:"stacks,omitempty"`
|
|
Tag []portainer.Tag `json:"tags,omitempty"`
|
|
TeamMembership []portainer.TeamMembership `json:"team_membership,omitempty"`
|
|
Team []portainer.Team `json:"teams,omitempty"`
|
|
TunnelServer portainer.TunnelServerInfo `json:"tunnel_server,omitempty"`
|
|
User []portainer.User `json:"users,omitempty"`
|
|
Version map[string]string `json:"version,omitempty"`
|
|
Webhook []portainer.Webhook `json:"webhooks,omitempty"`
|
|
}
|
|
|
|
func (store *Store) Export(filename string) (err error) {
|
|
|
|
backup := storeExport{}
|
|
|
|
if c, err := store.CustomTemplate().CustomTemplates(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Custom Templates")
|
|
}
|
|
} else {
|
|
backup.CustomTemplate = c
|
|
}
|
|
|
|
if e, err := store.EdgeGroup().EdgeGroups(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Edge Groups")
|
|
}
|
|
} else {
|
|
backup.EdgeGroup = e
|
|
}
|
|
|
|
if e, err := store.EdgeJob().EdgeJobs(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Edge Jobs")
|
|
}
|
|
} else {
|
|
backup.EdgeJob = e
|
|
}
|
|
|
|
if e, err := store.EdgeStack().EdgeStacks(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Edge Stacks")
|
|
}
|
|
} else {
|
|
backup.EdgeStack = e
|
|
}
|
|
|
|
if e, err := store.Endpoint().Endpoints(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Endpoints")
|
|
}
|
|
} else {
|
|
backup.Endpoint = e
|
|
}
|
|
|
|
if e, err := store.EndpointGroup().EndpointGroups(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Endpoint Groups")
|
|
}
|
|
} else {
|
|
backup.EndpointGroup = e
|
|
}
|
|
|
|
if r, err := store.EndpointRelation().EndpointRelations(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Endpoint Relations")
|
|
}
|
|
} else {
|
|
backup.EndpointRelation = r
|
|
}
|
|
|
|
if r, err := store.ExtensionService.Extensions(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Extensions")
|
|
}
|
|
} else {
|
|
backup.Extensions = r
|
|
}
|
|
|
|
if r, err := store.HelmUserRepository().HelmUserRepositories(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Helm User Repositories")
|
|
}
|
|
} else {
|
|
backup.HelmUserRepository = r
|
|
}
|
|
|
|
if r, err := store.Registry().Registries(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Registries")
|
|
}
|
|
} else {
|
|
backup.Registry = r
|
|
}
|
|
|
|
if c, err := store.ResourceControl().ResourceControls(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Resource Controls")
|
|
}
|
|
} else {
|
|
backup.ResourceControl = c
|
|
}
|
|
|
|
if role, err := store.Role().Roles(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Roles")
|
|
}
|
|
} else {
|
|
backup.Role = role
|
|
}
|
|
|
|
if r, err := store.ScheduleService.Schedules(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Schedules")
|
|
}
|
|
} else {
|
|
backup.Schedules = r
|
|
}
|
|
|
|
if settings, err := store.Settings().Settings(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Settings")
|
|
}
|
|
} else {
|
|
backup.Settings = *settings
|
|
}
|
|
|
|
if settings, err := store.SSLSettings().Settings(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting SSL Settings")
|
|
}
|
|
} else {
|
|
backup.SSLSettings = *settings
|
|
}
|
|
|
|
if t, err := store.Stack().Stacks(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Stacks")
|
|
}
|
|
} else {
|
|
backup.Stack = t
|
|
}
|
|
|
|
if t, err := store.Tag().Tags(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Tags")
|
|
}
|
|
} else {
|
|
backup.Tag = t
|
|
}
|
|
|
|
if t, err := store.TeamMembership().TeamMemberships(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Team Memberships")
|
|
}
|
|
} else {
|
|
backup.TeamMembership = t
|
|
}
|
|
|
|
if t, err := store.Team().Teams(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Teams")
|
|
}
|
|
} else {
|
|
backup.Team = t
|
|
}
|
|
|
|
if info, err := store.TunnelServer().Info(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Tunnel Server")
|
|
}
|
|
} else {
|
|
backup.TunnelServer = *info
|
|
}
|
|
|
|
if users, err := store.User().Users(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Users")
|
|
}
|
|
} else {
|
|
backup.User = users
|
|
}
|
|
|
|
if webhooks, err := store.Webhook().Webhooks(); err != nil {
|
|
if !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting Webhooks")
|
|
}
|
|
} else {
|
|
backup.Webhook = webhooks
|
|
}
|
|
|
|
v, err := store.Version().DBVersion()
|
|
if err != nil && !store.IsErrObjectNotFound(err) {
|
|
logrus.WithError(err).Errorf("Exporting DB version")
|
|
}
|
|
instance, _ := store.Version().InstanceID()
|
|
backup.Version = map[string]string{
|
|
"DB_VERSION": strconv.Itoa(v),
|
|
"INSTANCE_ID": instance,
|
|
}
|
|
|
|
b, err := json.MarshalIndent(backup, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ioutil.WriteFile(filename, b, 0600)
|
|
}
|
|
|
|
func (store *Store) Import(filename string) (err error) {
|
|
backup := storeExport{}
|
|
|
|
s, err := ioutil.ReadFile(filename)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = json.Unmarshal([]byte(s), &backup)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// TODO: yup, this is bad, and should be in a version struct...
|
|
if dbversion, ok := backup.Version["DB_VERSION"]; ok {
|
|
if v, err := strconv.Atoi(dbversion); err == nil {
|
|
if err := store.Version().StoreDBVersion(v); err != nil {
|
|
logrus.WithError(err).Errorf("DB_VERSION import issue")
|
|
}
|
|
}
|
|
}
|
|
if instanceID, ok := backup.Version["INSTANCE_ID"]; ok {
|
|
if err := store.Version().StoreInstanceID(instanceID); err != nil {
|
|
logrus.WithError(err).Errorf("INSTANCE_ID import issue")
|
|
}
|
|
}
|
|
|
|
for _, v := range backup.CustomTemplate {
|
|
store.CustomTemplate().UpdateCustomTemplate(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.EdgeGroup {
|
|
store.EdgeGroup().UpdateEdgeGroup(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.EdgeJob {
|
|
store.EdgeJob().UpdateEdgeJob(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.EdgeStack {
|
|
store.EdgeStack().UpdateEdgeStack(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.Endpoint {
|
|
store.Endpoint().UpdateEndpoint(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.EndpointGroup {
|
|
store.EndpointGroup().UpdateEndpointGroup(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.EndpointRelation {
|
|
store.EndpointRelation().UpdateEndpointRelation(v.EndpointID, &v)
|
|
}
|
|
|
|
for _, v := range backup.HelmUserRepository {
|
|
store.HelmUserRepository().UpdateHelmUserRepository(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.Registry {
|
|
store.Registry().UpdateRegistry(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.ResourceControl {
|
|
store.ResourceControl().UpdateResourceControl(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.Role {
|
|
store.Role().UpdateRole(v.ID, &v)
|
|
}
|
|
|
|
store.Settings().UpdateSettings(&backup.Settings)
|
|
store.SSLSettings().UpdateSettings(&backup.SSLSettings)
|
|
|
|
for _, v := range backup.Stack {
|
|
store.Stack().UpdateStack(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.Tag {
|
|
store.Tag().UpdateTag(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.TeamMembership {
|
|
store.TeamMembership().UpdateTeamMembership(v.ID, &v)
|
|
}
|
|
|
|
for _, v := range backup.Team {
|
|
store.Team().UpdateTeam(v.ID, &v)
|
|
}
|
|
|
|
store.TunnelServer().UpdateInfo(&backup.TunnelServer)
|
|
|
|
for _, user := range backup.User {
|
|
if err := store.User().UpdateUser(user.ID, &user); err != nil {
|
|
logrus.WithField("user", user).WithError(err).Errorf("User: Failed to Update Database")
|
|
}
|
|
}
|
|
|
|
for _, v := range backup.Webhook {
|
|
store.Webhook().UpdateWebhook(v.ID, &v)
|
|
}
|
|
|
|
return nil
|
|
}
|