raoulh / mc-cli

Moolticute CLI tool
GNU General Public License v3.0
5 stars 3 forks source link

Make an importable go package #8

Open oliverpool opened 2 years ago

oliverpool commented 2 years ago

Bonsoir,

thanks for your work on this, I adapted your code to try to be simpler and more idiomatic go. I made the following modifications:

https://git.sr.ht/~oliverpool/go-moolticute (doc: https://pkg.go.dev/git.sr.ht/~oliverpool/go-moolticute)

Your CLI tools do much more, but I think it would be nice for the ecosystem to have an importable library.

Do you think it would be a good move to have an official github.com/mooltipass/go-moolticute package, which could be imported by many other tools? (mc-cli, mc-get, ...)

This could also be a good opportunity to add some documentation reference (see https://github.com/mooltipass/moolticute/issues/934 ;)

I would be willing to help this effort if you want.

raoulh commented 2 years ago

Hi,

I think it would be a good idea to do that. I don't have any time to work on that but if you are willing to do it I can do some review and help to create an official package. For now I only maintain https://github.com/raoulh/mc-agent because I use it all the time for SSH

oliverpool commented 2 years ago

if you are willing to do it I can do some review and help to create an official package

thanks for your proposition, I would like to give it a try!

How do you want me to proceed?

My repo is currently living at sr.ht: https://git.sr.ht/~oliverpool/go-moolticute Package file: https://git.sr.ht/~oliverpool/go-moolticute/tree/main/item/client.go Usage example with mc-get: https://git.sr.ht/~oliverpool/go-moolticute/tree/main/item/cmd/mc-get/main.go

I can move it to github if you prefer (as previously stated, I think it would be great to put it under the mooltipass organization to show that it is somehow official). Then I could propose changes to the mc-agent repo, to use the go-moolticute package.

For instance, the McSetKeys function would become:

func McSetKeys(keys *McBinKeys) error {
    var buffer bytes.Buffer
    if err := gob.NewEncoder(&buffer).Encode(keys); err != nil {
        return fmt.Errorf("could not encode with encoding/gob: %v", err)
    }

    resp, err := moolticute.MakeRequest(*mcUrl, "set_data_node", moolticute.Data{
        Service:  "Moolticute SSH Keys",
        NodeData: base64.StdEncoding.EncodeToString(buffer.Bytes()),
    }, moolticute.HandleOtherMsg(printProgressForMoolticute))
    if err != nil {
        return fmt.Errorf("could not set data: %#v %w", resp, err)
    }
    return nil
}

Edit: I mentionned "this repo" instead of the mc-agent repo