Giter VIP home page Giter VIP logo

Comments (4)

ojarva avatar ojarva commented on June 10, 2024

What would be the usecase for this?

To me, it sounds like a better idea to write whatever data was used as a source when loading authorized_keys to this library. If this library would allow modifying key options, then writing would definitely make sense.

from python-sshpubkeys.

mpounsett avatar mpounsett commented on June 10, 2024

The use case would be for writing code that manages the contents of authorized keys files. So, load an authorized_keys file into an instance of the class, replace one or more keys, then write the file out again.

The class wouldn't necessarily need to do file management itself, but it could have a to_str() method or something that could be redirected to a file.

from python-sshpubkeys.

mpounsett avatar mpounsett commented on June 10, 2024

I threw together an example of what I'm talking about at mpounsett/python-sshpubkeys@34b8d7c

Usage would look something like this (using StringIO in place of a real file):

import io
from sshpubkeys import AuthorizedKeysFile
from tests.valid_keys import keys

# slice 3 keys off the top of the test keys
authorized_keys = "\n".join([x[0] for x in keys][:3])
f = io.StringIO(authorized_keys)
key_file = AuthorizedKeysFile(f, strict=False)
# modify the key list here
f.seek(0)
f.write(str(key_file))
f.seek(0)
print(f.read())

If you really wanted to get fancy, AuthorizedKeysFile could be reimplemented as a context manager, allowing automatic writes to take place on close.

with open(keyfile, mode='w') as f:
   with AuthorizedKeysFile(f, strict=False) as key_list:
      key_list.append(SSHKey(...))

from python-sshpubkeys.

tuxiqae avatar tuxiqae commented on June 10, 2024

Any news on that? It could be quite useful for me.

from python-sshpubkeys.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.