I am trying to design a command-line interface in Go based on the cobra package which mimics the functionalities available in the user interface. I am facing a problem when the user provides the initial credentials for login in one command and then he executes the next set of commands. In this scenario, I either need to store credentials that are not safe to store or I would need to store the session object which I have created, but now sure how to store the session object as the program is not constantly running.
Asked
Active
Viewed 267 times
0
-
What is "the session object"? Can you show what you're talking about? Most likely it's a client struct, which you probably can't serialize/deserialize effectively. You'll need to store either some kind of session token, or the credentials themselves; either way, you're going to be creating a potential security issue by storing it on disk. – Adrian Dec 22 '20 at 14:12
-
Yes, Your understanding is correct. But then what should be done in order to pass this session information to the next commands? – kushal agrawal Dec 23 '20 at 03:31
1 Answers
-2
you can use https://github.com/docker/docker-credential-helpers
like in this example
p := NewShellProgramFunc("docker-credential-secretservice")
c := &credentials.Credentials{
ServerURL: "https://example.com",
Username: "calavera",
Secret: "my super secret token",
}
if err := Store(p, c); err != nil {
fmt.Println(err)
}

Dharman
- 30,962
- 25
- 85
- 135

Mauricio De La Quintana
- 2,362
- 16
- 14