-
Notifications
You must be signed in to change notification settings - Fork 11
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
Hidden agent id flag #160
Hidden agent id flag #160
Conversation
599e9e7
to
f55935f
Compare
f55935f
to
fcdf523
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, the only thing: maybe having something more explicit like --force-agent-id
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, even if I am not a fan either of passing afero around, however, that's what we have 😅
I find more compelling the changes that this PR requires to make, at least for me, to the id
command.
@@ -12,7 +13,7 @@ func NewAgentIDCmd() *cobra.Command { | |||
Use: "id", | |||
Short: "Print the agent identifier", | |||
RunE: func(cmd *cobra.Command, args []string) error { | |||
agentID, err := agent.GetAgentID() | |||
agentID, err := agent.GetAgentID(afero.NewOsFs()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR opens the need to refactor also id
command I guess, because as of now it will always get the real agent id.
What I would expect is that when ./trento-agent id
is executed it returns either what has been configured in agent's config file or the real agent id.
As an addition I wouldn't expect ./trento-agent id --force-agent-id=blaa
, as it would be fancy 😅
Finally we'd need to take care of having the same defaults for both the commands, otherwise in one case viper would complain about not having some expected flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't go in this direction. This force-agent-id
is a hidden flag for development/test purposes, and it shouldn't be used together with the id
command, which is used to get the real id. It is only for the start
function, which is the one that it makes sense.
Using ./trento-agent id --force-agent-id=blaa
doesn't make any sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah true, that's just for test/dev so if that's how it has to be I can live with this little inconsistency 😉
Using ./trento-agent id --force-agent-id=blaa doesn't make any sense.
Yes, we're saying the same about this 😄
) | ||
|
||
// MockMachineIDFile mocks the /etc/machine-id file to have a known value | ||
func MockMachineIDFile() afero.Fs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this a bit misleading as we're mocking the whole filesystem, not only the file 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you call it?
I find the name together with the docstring pretty meaningful, but I wrote msyelf the function, so I'm biased
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't call it 😜
However, I can think of MockFilesystemWithMachineID
, MockFilesystemMachineID
, which are by no means any better than MockMachineIDFile
at the end 😅
So up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good to me, but maybe considering issuing a warning when force-agent-id
is used.
Add a new hidden
agent-id
flag to have the option to fake the agent id.This comes handy during development/testing, as you can have predefined IDs, for whatever need you have.
I have added some dependency injection with Afero to manage the filesystem in the
GetAgentID
function. Not so nice to be passing this value all over the places, but well, it makes testing way better.PD: Finally, I have changed the horrible testing of the
config_test.go
file using the teardown 🤦