* 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 filesystem
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"encoding/pem"
|
|
"errors"
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/gofrs/uuid"
|
|
portainer "github.com/portainer/portainer/api"
|
|
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
const (
|
|
// TLSStorePath represents the subfolder where TLS files are stored in the file store folder.
|
|
TLSStorePath = "tls"
|
|
// LDAPStorePath represents the subfolder where LDAP TLS files are stored in the TLSStorePath.
|
|
LDAPStorePath = "ldap"
|
|
// TLSCACertFile represents the name on disk for a TLS CA file.
|
|
TLSCACertFile = "ca.pem"
|
|
// TLSCertFile represents the name on disk for a TLS certificate file.
|
|
TLSCertFile = "cert.pem"
|
|
// TLSKeyFile represents the name on disk for a TLS key file.
|
|
TLSKeyFile = "key.pem"
|
|
// ComposeStorePath represents the subfolder where compose files are stored in the file store folder.
|
|
ComposeStorePath = "compose"
|
|
// ComposeFileDefaultName represents the default name of a compose file.
|
|
ComposeFileDefaultName = "docker-compose.yml"
|
|
// ManifestFileDefaultName represents the default name of a k8s manifest file.
|
|
ManifestFileDefaultName = "k8s-deployment.yml"
|
|
// EdgeStackStorePath represents the subfolder where edge stack files are stored in the file store folder.
|
|
EdgeStackStorePath = "edge_stacks"
|
|
// FDOProfileStorePath represents the subfolder where FDO profiles files are stored in the file store folder.
|
|
FDOProfileStorePath = "fdo_profiles"
|
|
// PrivateKeyFile represents the name on disk of the file containing the private key.
|
|
PrivateKeyFile = "portainer.key"
|
|
// PublicKeyFile represents the name on disk of the file containing the public key.
|
|
PublicKeyFile = "portainer.pub"
|
|
// BinaryStorePath represents the subfolder where binaries are stored in the file store folder.
|
|
BinaryStorePath = "bin"
|
|
// EdgeJobStorePath represents the subfolder where schedule files are stored.
|
|
EdgeJobStorePath = "edge_jobs"
|
|
// DockerConfigPath represents the subfolder where docker configuration is stored.
|
|
DockerConfigPath = "docker_config"
|
|
// ExtensionRegistryManagementStorePath represents the subfolder where files related to the
|
|
// registry management extension are stored.
|
|
ExtensionRegistryManagementStorePath = "extensions"
|
|
// CustomTemplateStorePath represents the subfolder where custom template files are stored in the file store folder.
|
|
CustomTemplateStorePath = "custom_templates"
|
|
// TempPath represent the subfolder where temporary files are saved
|
|
TempPath = "tmp"
|
|
// SSLCertPath represents the default ssl certificates path
|
|
SSLCertPath = "certs"
|
|
// DefaultSSLCertFilename represents the default ssl certificate file name
|
|
DefaultSSLCertFilename = "cert.pem"
|
|
// DefaultSSLKeyFilename represents the default ssl key file name
|
|
DefaultSSLKeyFilename = "key.pem"
|
|
)
|
|
|
|
// ErrUndefinedTLSFileType represents an error returned on undefined TLS file type
|
|
var ErrUndefinedTLSFileType = errors.New("Undefined TLS file type")
|
|
|
|
// Service represents a service for managing files and directories.
|
|
type Service struct {
|
|
dataStorePath string
|
|
fileStorePath string
|
|
}
|
|
|
|
// JoinPaths takes a trusted root path and a list of untrusted paths and joins
|
|
// them together using directory separators while enforcing that the untrusted
|
|
// paths cannot go higher up than the trusted root
|
|
func JoinPaths(trustedRoot string, untrustedPaths ...string) string {
|
|
if trustedRoot == "" {
|
|
trustedRoot = "."
|
|
}
|
|
|
|
p := filepath.Join(trustedRoot, filepath.Join(append([]string{"/"}, untrustedPaths...)...))
|
|
|
|
// avoid setting a volume name from the untrusted paths
|
|
vnp := filepath.VolumeName(p)
|
|
if filepath.VolumeName(trustedRoot) == "" && vnp != "" {
|
|
return strings.TrimPrefix(strings.TrimPrefix(p, vnp), `\`)
|
|
}
|
|
|
|
return p
|
|
}
|
|
|
|
// NewService initializes a new service. It creates a data directory and a directory to store files
|
|
// inside this directory if they don't exist.
|
|
func NewService(dataStorePath, fileStorePath string) (*Service, error) {
|
|
service := &Service{
|
|
dataStorePath: dataStorePath,
|
|
fileStorePath: JoinPaths(dataStorePath, fileStorePath),
|
|
}
|
|
|
|
err := os.MkdirAll(dataStorePath, 0755)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = service.createDirectoryInStore(SSLCertPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = service.createDirectoryInStore(TLSStorePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = service.createDirectoryInStore(ComposeStorePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = service.createDirectoryInStore(BinaryStorePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = service.createDirectoryInStore(DockerConfigPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return service, nil
|
|
}
|
|
|
|
// GetBinaryFolder returns the full path to the binary store on the filesystem
|
|
func (service *Service) GetBinaryFolder() string {
|
|
return JoinPaths(service.fileStorePath, BinaryStorePath)
|
|
}
|
|
|
|
// GetDockerConfigPath returns the full path to the docker config store on the filesystem
|
|
func (service *Service) GetDockerConfigPath() string {
|
|
return JoinPaths(service.fileStorePath, DockerConfigPath)
|
|
}
|
|
|
|
// RemoveDirectory removes a directory on the filesystem.
|
|
func (service *Service) RemoveDirectory(directoryPath string) error {
|
|
return os.RemoveAll(directoryPath)
|
|
}
|
|
|
|
// GetStackProjectPath returns the absolute path on the FS for a stack based
|
|
// on its identifier.
|
|
func (service *Service) GetStackProjectPath(stackIdentifier string) string {
|
|
return JoinPaths(service.wrapFileStore(ComposeStorePath), stackIdentifier)
|
|
}
|
|
|
|
// Copy copies the file on fromFilePath to toFilePath
|
|
// if toFilePath exists func will fail unless deleteIfExists is true
|
|
func (service *Service) Copy(fromFilePath string, toFilePath string, deleteIfExists bool) error {
|
|
exists, err := service.FileExists(fromFilePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if !exists {
|
|
return errors.New("File doesn't exist")
|
|
}
|
|
|
|
finput, err := os.Open(fromFilePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defer finput.Close()
|
|
|
|
exists, err = service.FileExists(toFilePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if exists {
|
|
if !deleteIfExists {
|
|
return errors.New("Destination file exists")
|
|
}
|
|
|
|
err := os.Remove(toFilePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
foutput, err := os.Create(toFilePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defer foutput.Close()
|
|
|
|
buf := make([]byte, 1024)
|
|
for {
|
|
n, err := finput.Read(buf)
|
|
if err != nil && err != io.EOF {
|
|
return err
|
|
}
|
|
if n == 0 {
|
|
break
|
|
}
|
|
|
|
if _, err := foutput.Write(buf[:n]); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// StoreStackFileFromBytes creates a subfolder in the ComposeStorePath and stores a new file from bytes.
|
|
// It returns the path to the folder where the file is stored.
|
|
func (service *Service) StoreStackFileFromBytes(stackIdentifier, fileName string, data []byte) (string, error) {
|
|
stackStorePath := JoinPaths(ComposeStorePath, stackIdentifier)
|
|
err := service.createDirectoryInStore(stackStorePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
composeFilePath := JoinPaths(stackStorePath, fileName)
|
|
r := bytes.NewReader(data)
|
|
|
|
err = service.createFileInStore(composeFilePath, r)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return service.wrapFileStore(stackStorePath), nil
|
|
}
|
|
|
|
// GetEdgeStackProjectPath returns the absolute path on the FS for a edge stack based
|
|
// on its identifier.
|
|
func (service *Service) GetEdgeStackProjectPath(edgeStackIdentifier string) string {
|
|
return JoinPaths(service.wrapFileStore(EdgeStackStorePath), edgeStackIdentifier)
|
|
}
|
|
|
|
// StoreEdgeStackFileFromBytes creates a subfolder in the EdgeStackStorePath and stores a new file from bytes.
|
|
// It returns the path to the folder where the file is stored.
|
|
func (service *Service) StoreEdgeStackFileFromBytes(edgeStackIdentifier, fileName string, data []byte) (string, error) {
|
|
stackStorePath := JoinPaths(EdgeStackStorePath, edgeStackIdentifier)
|
|
err := service.createDirectoryInStore(stackStorePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
composeFilePath := JoinPaths(stackStorePath, fileName)
|
|
r := bytes.NewReader(data)
|
|
|
|
err = service.createFileInStore(composeFilePath, r)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return service.wrapFileStore(stackStorePath), nil
|
|
}
|
|
|
|
// StoreRegistryManagementFileFromBytes creates a subfolder in the
|
|
// ExtensionRegistryManagementStorePath and stores a new file from bytes.
|
|
// It returns the path to the folder where the file is stored.
|
|
func (service *Service) StoreRegistryManagementFileFromBytes(folder, fileName string, data []byte) (string, error) {
|
|
extensionStorePath := JoinPaths(ExtensionRegistryManagementStorePath, folder)
|
|
err := service.createDirectoryInStore(extensionStorePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
file := JoinPaths(extensionStorePath, fileName)
|
|
r := bytes.NewReader(data)
|
|
|
|
err = service.createFileInStore(file, r)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return service.wrapFileStore(file), nil
|
|
}
|
|
|
|
// StoreTLSFileFromBytes creates a folder in the TLSStorePath and stores a new file from bytes.
|
|
// It returns the path to the newly created file.
|
|
func (service *Service) StoreTLSFileFromBytes(folder string, fileType portainer.TLSFileType, data []byte) (string, error) {
|
|
storePath := JoinPaths(TLSStorePath, folder)
|
|
err := service.createDirectoryInStore(storePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
var fileName string
|
|
switch fileType {
|
|
case portainer.TLSFileCA:
|
|
fileName = TLSCACertFile
|
|
case portainer.TLSFileCert:
|
|
fileName = TLSCertFile
|
|
case portainer.TLSFileKey:
|
|
fileName = TLSKeyFile
|
|
default:
|
|
return "", ErrUndefinedTLSFileType
|
|
}
|
|
|
|
tlsFilePath := JoinPaths(storePath, fileName)
|
|
r := bytes.NewReader(data)
|
|
err = service.createFileInStore(tlsFilePath, r)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return service.wrapFileStore(tlsFilePath), nil
|
|
}
|
|
|
|
// GetPathForTLSFile returns the absolute path to a specific TLS file for an environment(endpoint).
|
|
func (service *Service) GetPathForTLSFile(folder string, fileType portainer.TLSFileType) (string, error) {
|
|
var fileName string
|
|
switch fileType {
|
|
case portainer.TLSFileCA:
|
|
fileName = TLSCACertFile
|
|
case portainer.TLSFileCert:
|
|
fileName = TLSCertFile
|
|
case portainer.TLSFileKey:
|
|
fileName = TLSKeyFile
|
|
default:
|
|
return "", ErrUndefinedTLSFileType
|
|
}
|
|
return JoinPaths(service.wrapFileStore(TLSStorePath), folder, fileName), nil
|
|
}
|
|
|
|
// DeleteTLSFiles deletes a folder in the TLS store path.
|
|
func (service *Service) DeleteTLSFiles(folder string) error {
|
|
storePath := JoinPaths(service.wrapFileStore(TLSStorePath), folder)
|
|
return os.RemoveAll(storePath)
|
|
}
|
|
|
|
// DeleteTLSFile deletes a specific TLS file from a folder.
|
|
func (service *Service) DeleteTLSFile(folder string, fileType portainer.TLSFileType) error {
|
|
var fileName string
|
|
switch fileType {
|
|
case portainer.TLSFileCA:
|
|
fileName = TLSCACertFile
|
|
case portainer.TLSFileCert:
|
|
fileName = TLSCertFile
|
|
case portainer.TLSFileKey:
|
|
fileName = TLSKeyFile
|
|
default:
|
|
return ErrUndefinedTLSFileType
|
|
}
|
|
|
|
filePath := JoinPaths(service.wrapFileStore(TLSStorePath), folder, fileName)
|
|
|
|
return os.Remove(filePath)
|
|
}
|
|
|
|
// GetFileContent returns the content of a file as bytes.
|
|
func (service *Service) GetFileContent(trustedRoot, filePath string) ([]byte, error) {
|
|
content, err := os.ReadFile(JoinPaths(trustedRoot, filePath))
|
|
if err != nil {
|
|
if filePath == "" {
|
|
filePath = trustedRoot
|
|
}
|
|
return nil, fmt.Errorf("could not get the contents of the file '%s'", filePath)
|
|
}
|
|
|
|
return content, nil
|
|
}
|
|
|
|
// Rename renames a file or directory
|
|
func (service *Service) Rename(oldPath, newPath string) error {
|
|
return os.Rename(oldPath, newPath)
|
|
}
|
|
|
|
// WriteJSONToFile writes JSON to the specified file.
|
|
func (service *Service) WriteJSONToFile(path string, content interface{}) error {
|
|
jsonContent, err := json.Marshal(content)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return os.WriteFile(path, jsonContent, 0644)
|
|
}
|
|
|
|
// FileExists checks for the existence of the specified file.
|
|
func (service *Service) FileExists(filePath string) (bool, error) {
|
|
return FileExists(filePath)
|
|
}
|
|
|
|
// KeyPairFilesExist checks for the existence of the key files.
|
|
func (service *Service) KeyPairFilesExist() (bool, error) {
|
|
privateKeyPath := JoinPaths(service.dataStorePath, PrivateKeyFile)
|
|
exists, err := service.FileExists(privateKeyPath)
|
|
if err != nil || !exists {
|
|
return false, err
|
|
}
|
|
|
|
publicKeyPath := JoinPaths(service.dataStorePath, PublicKeyFile)
|
|
exists, err = service.FileExists(publicKeyPath)
|
|
if err != nil || !exists {
|
|
return false, err
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
// StoreKeyPair store the specified keys content as PEM files on disk.
|
|
func (service *Service) StoreKeyPair(private, public []byte, privatePEMHeader, publicPEMHeader string) error {
|
|
err := service.createPEMFileInStore(private, privatePEMHeader, PrivateKeyFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return service.createPEMFileInStore(public, publicPEMHeader, PublicKeyFile)
|
|
}
|
|
|
|
// LoadKeyPair retrieve the content of both key files on disk.
|
|
func (service *Service) LoadKeyPair() ([]byte, []byte, error) {
|
|
privateKey, err := service.getContentFromPEMFile(PrivateKeyFile)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
publicKey, err := service.getContentFromPEMFile(PublicKeyFile)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
return privateKey, publicKey, nil
|
|
}
|
|
|
|
// createDirectoryInStore creates a new directory in the file store
|
|
func (service *Service) createDirectoryInStore(name string) error {
|
|
path := service.wrapFileStore(name)
|
|
return os.MkdirAll(path, 0700)
|
|
}
|
|
|
|
// createFile creates a new file in the file store with the content from r.
|
|
func (service *Service) createFileInStore(filePath string, r io.Reader) error {
|
|
path := service.wrapFileStore(filePath)
|
|
|
|
out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer out.Close()
|
|
|
|
_, err = io.Copy(out, r)
|
|
return err
|
|
}
|
|
|
|
func (service *Service) createPEMFileInStore(content []byte, fileType, filePath string) error {
|
|
path := service.wrapFileStore(filePath)
|
|
block := &pem.Block{Type: fileType, Bytes: content}
|
|
|
|
out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer out.Close()
|
|
|
|
return pem.Encode(out, block)
|
|
}
|
|
|
|
func (service *Service) getContentFromPEMFile(filePath string) ([]byte, error) {
|
|
path := service.wrapFileStore(filePath)
|
|
|
|
fileContent, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
block, _ := pem.Decode(fileContent)
|
|
return block.Bytes, nil
|
|
}
|
|
|
|
// GetCustomTemplateProjectPath returns the absolute path on the FS for a custom template based
|
|
// on its identifier.
|
|
func (service *Service) GetCustomTemplateProjectPath(identifier string) string {
|
|
return JoinPaths(service.wrapFileStore(CustomTemplateStorePath), identifier)
|
|
}
|
|
|
|
// StoreCustomTemplateFileFromBytes creates a subfolder in the CustomTemplateStorePath and stores a new file from bytes.
|
|
// It returns the path to the folder where the file is stored.
|
|
func (service *Service) StoreCustomTemplateFileFromBytes(identifier, fileName string, data []byte) (string, error) {
|
|
customTemplateStorePath := JoinPaths(CustomTemplateStorePath, identifier)
|
|
err := service.createDirectoryInStore(customTemplateStorePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
templateFilePath := JoinPaths(customTemplateStorePath, fileName)
|
|
r := bytes.NewReader(data)
|
|
|
|
err = service.createFileInStore(templateFilePath, r)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return service.wrapFileStore(customTemplateStorePath), nil
|
|
}
|
|
|
|
// GetEdgeJobFolder returns the absolute path on the filesystem for an Edge job based
|
|
// on its identifier.
|
|
func (service *Service) GetEdgeJobFolder(identifier string) string {
|
|
return JoinPaths(service.wrapFileStore(EdgeJobStorePath), identifier)
|
|
}
|
|
|
|
// StoreEdgeJobFileFromBytes creates a subfolder in the EdgeJobStorePath and stores a new file from bytes.
|
|
// It returns the path to the folder where the file is stored.
|
|
func (service *Service) StoreEdgeJobFileFromBytes(identifier string, data []byte) (string, error) {
|
|
edgeJobStorePath := JoinPaths(EdgeJobStorePath, identifier)
|
|
err := service.createDirectoryInStore(edgeJobStorePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
filePath := JoinPaths(edgeJobStorePath, createEdgeJobFileName(identifier))
|
|
r := bytes.NewReader(data)
|
|
err = service.createFileInStore(filePath, r)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return service.wrapFileStore(filePath), nil
|
|
}
|
|
|
|
func createEdgeJobFileName(identifier string) string {
|
|
return "job_" + identifier + ".sh"
|
|
}
|
|
|
|
// ClearEdgeJobTaskLogs clears the Edge job task logs
|
|
func (service *Service) ClearEdgeJobTaskLogs(edgeJobID string, taskID string) error {
|
|
path := service.getEdgeJobTaskLogPath(edgeJobID, taskID)
|
|
return os.Remove(path)
|
|
}
|
|
|
|
// GetEdgeJobTaskLogFileContent fetches the Edge job task logs
|
|
func (service *Service) GetEdgeJobTaskLogFileContent(edgeJobID string, taskID string) (string, error) {
|
|
path := service.getEdgeJobTaskLogPath(edgeJobID, taskID)
|
|
|
|
fileContent, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return string(fileContent), nil
|
|
}
|
|
|
|
// StoreEdgeJobTaskLogFileFromBytes stores the log file
|
|
func (service *Service) StoreEdgeJobTaskLogFileFromBytes(edgeJobID, taskID string, data []byte) error {
|
|
edgeJobStorePath := JoinPaths(EdgeJobStorePath, edgeJobID)
|
|
err := service.createDirectoryInStore(edgeJobStorePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
filePath := JoinPaths(edgeJobStorePath, fmt.Sprintf("logs_%s", taskID))
|
|
r := bytes.NewReader(data)
|
|
return service.createFileInStore(filePath, r)
|
|
}
|
|
|
|
func (service *Service) getEdgeJobTaskLogPath(edgeJobID string, taskID string) string {
|
|
return fmt.Sprintf("%s/logs_%s", service.GetEdgeJobFolder(edgeJobID), taskID)
|
|
}
|
|
|
|
// GetTemporaryPath returns a temp folder
|
|
func (service *Service) GetTemporaryPath() (string, error) {
|
|
uid, err := uuid.NewV4()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return JoinPaths(service.wrapFileStore(TempPath), uid.String()), nil
|
|
}
|
|
|
|
// GetDataStorePath returns path to data folder
|
|
func (service *Service) GetDatastorePath() string {
|
|
return service.dataStorePath
|
|
}
|
|
|
|
func (service *Service) wrapFileStore(filepath string) string {
|
|
return JoinPaths(service.fileStorePath, filepath)
|
|
}
|
|
|
|
func defaultCertPathUnderFileStore() (string, string) {
|
|
certPath := JoinPaths(SSLCertPath, DefaultSSLCertFilename)
|
|
keyPath := JoinPaths(SSLCertPath, DefaultSSLKeyFilename)
|
|
return certPath, keyPath
|
|
}
|
|
|
|
// GetDefaultSSLCertsPath returns the ssl certs path
|
|
func (service *Service) GetDefaultSSLCertsPath() (string, string) {
|
|
certPath, keyPath := defaultCertPathUnderFileStore()
|
|
return service.wrapFileStore(certPath), service.wrapFileStore(keyPath)
|
|
}
|
|
|
|
// StoreSSLCertPair stores a ssl certificate pair
|
|
func (service *Service) StoreSSLCertPair(cert, key []byte) (string, string, error) {
|
|
certPath, keyPath := defaultCertPathUnderFileStore()
|
|
|
|
r := bytes.NewReader(cert)
|
|
err := service.createFileInStore(certPath, r)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
r = bytes.NewReader(key)
|
|
err = service.createFileInStore(keyPath, r)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
return service.wrapFileStore(certPath), service.wrapFileStore(keyPath), nil
|
|
}
|
|
|
|
// CopySSLCertPair copies a ssl certificate pair
|
|
func (service *Service) CopySSLCertPair(certPath, keyPath string) (string, string, error) {
|
|
defCertPath, defKeyPath := service.GetDefaultSSLCertsPath()
|
|
|
|
err := service.Copy(certPath, defCertPath, true)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
err = service.Copy(keyPath, defKeyPath, true)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
return defCertPath, defKeyPath, nil
|
|
}
|
|
|
|
// FileExists checks for the existence of the specified file.
|
|
func FileExists(filePath string) (bool, error) {
|
|
if _, err := os.Stat(filePath); err != nil {
|
|
if os.IsNotExist(err) {
|
|
return false, nil
|
|
}
|
|
return false, err
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
func MoveDirectory(originalPath, newPath string) error {
|
|
if _, err := os.Stat(originalPath); err != nil {
|
|
return err
|
|
}
|
|
|
|
alreadyExists, err := FileExists(newPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if alreadyExists {
|
|
return errors.New("Target path already exists")
|
|
}
|
|
|
|
return os.Rename(originalPath, newPath)
|
|
}
|
|
|
|
// StoreFDOProfileFileFromBytes creates a subfolder in the FDOProfileStorePath and stores a new file from bytes.
|
|
// It returns the path to the folder where the file is stored.
|
|
func (service *Service) StoreFDOProfileFileFromBytes(fdoProfileIdentifier string, data []byte) (string, error) {
|
|
err := service.createDirectoryInStore(FDOProfileStorePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
filePath := JoinPaths(FDOProfileStorePath, fdoProfileIdentifier)
|
|
err = service.createFileInStore(filePath, bytes.NewReader(data))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return service.wrapFileStore(filePath), nil
|
|
}
|