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

Fixing AzureCLI / CloudShell authentication #169

Merged
merged 5 commits into from
Sep 13, 2017

Conversation

tombuildsstuff
Copy link
Contributor

  • Hard-coding the value for expiresIn due to the Azure CLI and CloudShell authentication models having different types
  • Updating expiresOn to be the difference in seconds between the baseDate & now - rather than a date
  • Parsing the AzureCLI time out in the local system timezone, given it's saved in local time but with no timezone info

@msftclas
Copy link

msftclas commented Sep 8, 2017

@tombuildsstuff,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

 - Hard-coding the value for `expiresIn` due to the Azure CLI and CloudShell authentication models having different types
 - Updating `expiresOn` to be the difference in seconds between the baseDate & now - rather than a date
 - Parsing the AzureCLI time out in the local system timezone, given it's saved in local time but with no timezone info

// ParseAzureCLIExpirationDate parses either a Azure CLI or CloudShell date into a time object
func ParseAzureCLIExpirationDate(input string) (*time.Time, error) {
log.Printf("[DEBUG] Token Date: %s", input)
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove this line before we commit this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated :)

ExpiresIn: strconv.Itoa(t.ExpiresIn),
ExpiresOn: t.ExpiresOn,
ExpiresIn: "3600",
ExpiresOn: strconv.Itoa(int(seconds)),
Copy link
Member

Choose a reason for hiding this comment

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

[nit] I think this would be more readable as difference.Seconds() and skipping the declaration of seconds

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated :)

}

// ParseAzureCLIExpirationDate parses either a Azure CLI or CloudShell date into a time object
func ParseAzureCLIExpirationDate(input string) (*time.Time, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: why do you return pointer to time.
time package uses value semantics by default, returning pointer causes one more allocation, moves object from stack to heap and creates work for garbage collector. as it is used only within a calling method it should return value.
this way it would stay on stack and get disposed when method finishes. no additional work for GC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve opted for this approach since we’re returning nil for an invalid/unparseable date; given returning an empty object in addition to an error in the failure case feels misleading as a consumer of the API

Copy link
Member

@marstr marstr Sep 12, 2017

Choose a reason for hiding this comment

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

It seems like you use that pattern pretty religiously, @tombuildsstuff. I'm not really convinced either way, other than sorta general intuitiveness, can you build a case for why it's better to return a pointer? Personally, when I'm writing Go, I just treat retvals that accompany an error as garbage, it doesn't matter if the value is the default or memory with random bits. As you can imagine, in my workflow, changing the return type to a pointer has almost no consequence. What scenario am I missing where it's totally important? :)

edit: this isn't important enough for me to hold up a PR. Don't feel like this comment is holding you hostage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not particularly - I've only opted for this approach to force the consumer to handle the error case, rather than accidental comparing the values returned by the default object (it's more habit than anything else) - but totally happy to switch this out :)

marstr
marstr previously requested changes Sep 12, 2017
@@ -1,16 +1,18 @@
package adal
Copy link
Member

Choose a reason for hiding this comment

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

I thought about this a little this morning, and think that this code would be better off in a cli package. Particularly, I think it makes sense as a child of the azure package. In general, I'd like to have as few Azure specific references in the adal package as possible, that applies doubly to CLI specific code :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated :)

Copy link
Member

@marstr marstr left a comment

Choose a reason for hiding this comment

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

Now that I'm participating in writing this code, I think we should get @jhendrixMSFT to sign off as well.

@marstr marstr dismissed their stale review September 13, 2017 19:56

Because I began contributing to this PR.

@marstr
Copy link
Member

marstr commented Sep 13, 2017

Talked with @jhendrixMSFT offline, he gave us the go-ahead to merge.

@marstr marstr merged commit fdf5888 into Azure:dev Sep 13, 2017
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

Successfully merging this pull request may close these issues.

4 participants