Skip to content
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

Make an importable go package #8

Open
oliverpool opened this issue Nov 28, 2021 · 2 comments
Open

Make an importable go package #8

oliverpool opened this issue Nov 28, 2021 · 2 comments

Comments

@oliverpool
Copy link

oliverpool commented Nov 28, 2021

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:

  • use go modules
  • use very few external dependencies (2)
  • divide the code in two parts: library to talk to the deamon, CLI tool (which uses the library) to get the password from the device

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 mooltipass/moolticute#934 ;)

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

@oliverpool oliverpool changed the title New life for the code Make an importable go package Nov 28, 2021
@raoulh
Copy link
Owner

raoulh commented Nov 29, 2021

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
Copy link
Author

oliverpool commented Nov 29, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants