From 828ae537da5d7eb7a2a5c9f976b90975adfe1f43 Mon Sep 17 00:00:00 2001 From: Inga Feick Date: Thu, 4 Apr 2019 00:01:14 +0200 Subject: [PATCH] Docker login (#894) * Add docker_login rule * Add docker_login rule * Whitespace fix * Fix typo in test case * Fix typo in test case * Add test cases --- README.md | 1 + tests/rules/test_docker_login.py | 37 ++++++++++++++++++++++++++++++++ thefuck/rules/docker_login.py | 12 +++++++++++ 3 files changed, 50 insertions(+) create mode 100644 tests/rules/test_docker_login.py create mode 100644 thefuck/rules/docker_login.py diff --git a/README.md b/README.md index 53cfebae..bb1d8df2 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,7 @@ following rules are enabled by default: * `dirty_unzip` – fixes `unzip` command that unzipped in the current directory; * `django_south_ghost` – adds `--delete-ghost-migrations` to failed because ghosts django south migration; * `django_south_merge` – adds `--merge` to inconsistent django south migration; +* `docker_login` – executes a `docker login` and repeats the previous command; * `docker_not_command` – fixes wrong docker commands like `docker tags`; * `dry` – fixes repetitions like `git git push`; * `fab_command_not_found` – fix misspelled fabric commands; diff --git a/tests/rules/test_docker_login.py b/tests/rules/test_docker_login.py new file mode 100644 index 00000000..2e62ae2a --- /dev/null +++ b/tests/rules/test_docker_login.py @@ -0,0 +1,37 @@ +from thefuck.rules.docker_login import match, get_new_command +from thefuck.types import Command + + +def test_match(): + err_response1 = """ + Sending build context to Docker daemon 118.8kB +Step 1/6 : FROM foo/bar:fdb7c6d +pull access denied for foo/bar, repository does not exist or may require 'docker login' +""" + assert match(Command('docker build -t artifactory:9090/foo/bar:fdb7c6d .', err_response1)) + + err_response2 = """ + The push refers to repository [artifactory:9090/foo/bar] +push access denied for foo/bar, repository does not exist or may require 'docker login' +""" + assert match(Command('docker push artifactory:9090/foo/bar:fdb7c6d', err_response2)) + + err_response3 = """ + docker push artifactory:9090/foo/bar:fdb7c6d +The push refers to repository [artifactory:9090/foo/bar] +9c29c7ad209d: Preparing +71f3ad53dfe0: Preparing +f58ee068224c: Preparing +aeddc924d0f7: Preparing +c2040e5d6363: Preparing +4d42df4f350f: Preparing +35723dab26f9: Preparing +71f3ad53dfe0: Pushed +cb95fa0faeb1: Layer already exists +""" + assert not match(Command('docker push artifactory:9090/foo/bar:fdb7c6d', err_response3)) + + +def test_get_new_command(): + assert get_new_command(Command('docker build -t artifactory:9090/foo/bar:fdb7c6d .', '')) == 'docker login && docker build -t artifactory:9090/foo/bar:fdb7c6d .' + assert get_new_command(Command('docker push artifactory:9090/foo/bar:fdb7c6d', '')) == 'docker login && docker push artifactory:9090/foo/bar:fdb7c6d' diff --git a/thefuck/rules/docker_login.py b/thefuck/rules/docker_login.py new file mode 100644 index 00000000..5a96b6c3 --- /dev/null +++ b/thefuck/rules/docker_login.py @@ -0,0 +1,12 @@ +from thefuck.utils import for_app + + +@for_app('docker') +def match(command): + return ('docker' in command.script + and "access denied" in command.output + and "may require 'docker login'" in command.output) + + +def get_new_command(command): + return 'docker login && {}'.format(command.script)