Skip to content

slcli ssl add souldn't error with no input #2078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
allmightyspiff opened this issue Aug 21, 2023 · 3 comments · Fixed by #2122
Closed

slcli ssl add souldn't error with no input #2078

allmightyspiff opened this issue Aug 21, 2023 · 3 comments · Fixed by #2122
Assignees
Labels

Comments

@allmightyspiff
Copy link
Member

$> slcli  ssl add
An unexpected error has occured:
Traceback (most recent call last):
  File "C:\Users\allmi\Code\py311\Lib\site-packages\SoftLayer\CLI\core.py", line 183, in main
    cli.main(**kwargs)
  File "C:\Users\allmi\Code\py311\Lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\allmi\Code\py311\Lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\allmi\Code\py311\Lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\allmi\Code\py311\Lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\allmi\Code\py311\Lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\allmi\Code\py311\Lib\site-packages\click\decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\allmi\Code\py311\Lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\allmi\Code\py311\Lib\site-packages\SoftLayer\CLI\ssl\add.py", line 31, in cli
    with open(crt, encoding="utf-8") as file_crt:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected str, bytes or os.PathLike object, not NoneType

Feel free to report this error as it is likely a bug:
    https://github.com/softlayer/softlayer-python/issues
The following snippet should be able to reproduce the error

@allmightyspiff
Copy link
Member Author

root@cgalloTest:~# slcli -vvv ssl add --crt cert.pem --key key.pem --notes="test ssl cert"
An unexpected error has occured:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/SoftLayer/CLI/core.py", line 183, in main
    cli.main(**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/SoftLayer/CLI/ssl/add.py", line 35, in cli
    with open(csr, encoding="utf-8") as file_csr:
TypeError: expected str, bytes or os.PathLike object, not NoneType

Feel free to report this error as it is likely a bug:
    https://github.com/softlayer/softlayer-python/issues
The following snippet should be able to reproduce the error

Should also nicely handle this case

@allmightyspiff
Copy link
Member Author

Add a unit test to make sure only having the 2 required options works as well

@allmightyspiff
Copy link
Member Author

$> git diff SoftLayer/CLI/security/cert_add.py
diff --git a/SoftLayer/CLI/security/cert_add.py b/SoftLayer/CLI/security/cert_add.py
index 9115e95c..61be1055 100644
--- a/SoftLayer/CLI/security/cert_add.py
+++ b/SoftLayer/CLI/security/cert_add.py
@@ -32,13 +32,14 @@ def cli(env, crt, csr, icc, key, notes):
         template['certificate'] = file_crt.read()
     with open(key, encoding="utf-8") as file_key:
         template['privateKey'] = file_key.read()
-    with open(csr, encoding="utf-8") as file_csr:
-        if csr:
+    if csr:
+        with open(csr, encoding="utf-8") as file_csr:
             body = file_csr.read()
             template['certificateSigningRequest'] = body

-    with open(icc, encoding="utf-8") as file_icc:
-        if icc:
+    if icc:
+        with open(icc, encoding="utf-8") as file_icc:
+

@allmightyspiff allmightyspiff self-assigned this Sep 12, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in Q3 2023 Sep 12, 2023
@allmightyspiff allmightyspiff removed this from Q3 2023 Oct 4, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in Q4 2023 Oct 4, 2023
allmightyspiff added a commit to allmightyspiff/softlayer-python that referenced this issue Jan 2, 2024
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in Q4 2023 Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant