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

Add device code print to console functionality #15332

Merged
merged 16 commits into from
Sep 28, 2020

Conversation

g2vinay
Copy link
Member

@g2vinay g2vinay commented Sep 17, 2020

Fixes #13461

@ghost ghost added the Azure.Identity label Sep 17, 2020
Comment on lines 585 to 589
if (deviceCodeConsumer != null) {
deviceCodeInfoConsumer = deviceCodeConsumer;
} else {
deviceCodeInfoConsumer = deviceCodeInfo -> System.out.println(deviceCodeInfo.getMessage());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the consumer is set on the DeviceCodeCredentialBuilder it would be good to have defaults also set in the builder. That's the general pattern we are following for other configurable options like httpclient, retry policies etc. So, we have one place for all defaults.

Copy link
Member Author

@g2vinay g2vinay Sep 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That approach comes with the drawback of the configured default living in the memory until the credential object is garbage collected.

This approach will ensure that the default value gets created and garbage collected after the method call finishes.
Given that in memory token cache will be active in our auth policies too, so invocation of this method will not be frequent as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This consumer can be a static constant. I don't think the consumer has to be tied to the lifetime of the credential.
private static final Consumer<DeviceCodeInfo> DEVICE_CODE_CONSUMER = deviceCodeInfo -> System.out.println(deviceCodeInfo.getMessage());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, statics are common and from a functionality point of view will work fine.

But, making it static, will prevent it from being garbage collected until the application terminates.
So, from memory point of view, static is worse compared to localizing the variable. In this scenario, the more we localize, the better the situation becomes from memory consumption aspect.

@g2vinay g2vinay merged commit 846265f into Azure:master Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "Use Console" Option to DeviceCodeCredential
2 participants