diff --git a/README.md b/README.md index f7e3337..e158a79 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Powered by [Ilhasoft's Web Team](http://www.ilhasoft.com.br/en/). -Portainer CLI is a Python software to use in command line. Use this command line interface to easy communicate to your [Portainer](https://portainer.io/) application, like in a continuous integration and continuous deploy environments. +Portainer CLI is a Python software to use in command line. Use this command line interface to easy communicate with your [Portainer](https://portainer.io/) application, like in a continuous integration and continuous deployment environments. ## Install @@ -61,13 +61,13 @@ portainer-cli update_stack id endpoint_id [stack_file] portainer-cli update_stack 2 1 docker-compose.yml ``` -#### update_stack command environment variables arguments +#### Environment variables arguments ```bash portainer-cli update_stack id endpoint_id [stack_file] --env.var=value ``` -Where `var` is environment variable name and `value` is the environment variable value. +Where `var` is the environment variable name and `value` is the environment variable value. #### Flags @@ -76,6 +76,28 @@ Where `var` is environment variable name and `value` is the environment variable | `-p` or `--prune` | Prune services | | `-c` or `--clear-env` | Clear all environment variables | +### update_registry command + +Update registry. + +```bash +portainer-cli update_registry id [-name] [-url] +``` + +**E.g:** + +```bash +portainer-cli update_registry 1 -name="Some registry" -url="some.url.com/r" +``` + +#### Authentication + +You can use authentication passing `-a` or `--authentication` flag, but you must pass the `-username` and `-password` options. + +```bash +portainer-cli update_registry 1 -a -username=douglas -password=d1234 +``` + ### request command Make a request. diff --git a/portainer_cli/__init__.py b/portainer_cli/__init__.py index fd90d84..b1e5fca 100755 --- a/portainer_cli/__init__.py +++ b/portainer_cli/__init__.py @@ -33,11 +33,13 @@ class PortainerCLI(object): COMMAND_LOGIN = 'login' COMMAND_REQUEST = 'request' COMMAND_UPDATE_STACK = 'update_stack' + COMMAND_UPDATE_REGISTRY = 'update_registry' COMMANDS = [ COMMAND_CONFIGURE, COMMAND_LOGIN, COMMAND_REQUEST, COMMAND_UPDATE_STACK, + COMMAND_UPDATE_REGISTRY, ] METHOD_GET = 'GET' @@ -156,6 +158,31 @@ class PortainerCLI(object): data, ) + @plac.annotations( + name=('Name', 'option'), + url=('URL', 'option'), + authentication=('Use authentication', 'flag', 'a'), + username=('Username', 'option'), + password=('Password', 'option'), + ) + def update_registry(self, id, name='', url='', authentication=False, + username='', password=''): + assert not authentication or (authentication and username and password) + registry_url = f'registries/{id}' + current = self.request(registry_url).json() + data = { + 'Name': name or current.get('Name'), + 'URL': url or current.get('URL'), + 'Authentication': authentication, + 'Username': username or current.get('Username'), + 'Password': password, + } + self.request( + registry_url, + self.METHOD_PUT, + data, + ) + @plac.annotations( printc=('Print response content', 'flag', 'p'), ) @@ -206,5 +233,7 @@ class PortainerCLI(object): plac.call(self.login, args) elif command == self.COMMAND_UPDATE_STACK: plac.call(self.update_stack, args) + elif command == self.COMMAND_UPDATE_REGISTRY: + plac.call(self.update_registry, args) elif command == self.COMMAND_REQUEST: plac.call(self.request, args)