Skip to content

Conversation

@antonlisovenko
Copy link
Contributor

@antonlisovenko antonlisovenko commented Feb 8, 2021

(This PR should be reviewed after the #90)

This adds more fixes and tests for project IP access list (especially for the date field as it wasn't trivial to parse ISO8601)

This doesn't handle the "expired" lists though - will be addressed in the next PR

@antonlisovenko antonlisovenko marked this pull request as ready for review February 8, 2021 11:57
IPAddress string `json:"ipAddress,omitempty"`
}

// ToAtlas converts the ProjectIPAccessList to native Atlas client format.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just moved these two methods below the ones for AtlasProject

// so we have to list all possible formats
func ParseISO8601(dateTime string) (time.Time, error) {
return time.Parse(dateTime, "2006-01-02T15:04:05-0700")
parse, err := time.Parse("2006-01-02T15:04:05-07", dateTime)
Copy link
Contributor

Choose a reason for hiding this comment

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

[q] Do we really need all of these? As per the docs, Atlas will always use UTC for Access Lists & DB Users

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, the docs say about "Timestamp in ISO 8601" and in practice this means different variations including the time zones

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think Atlas returns UTC only, but thinking about it - this might be useful in the future if we decide to change/validate user input somehow since user input can contain a timezone shift.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, Atlas returns UTC only but accepts any valid ISO 8601 date - so I tried to cover all possible formats :)

Base automatically changed from CLOUDP-78181_ip-access-list to main February 8, 2021 15:48
antonlisovenko added 3 commits February 8, 2021 15:50
Copy link
Contributor

@vasilevp vasilevp left a comment

Choose a reason for hiding this comment

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

LGTM with an optional suggestion

Comment on lines +63 to +66
allSpecified := isNotEmpty(list.AwsSecurityGroup) && isNotEmpty(list.CIDRBlock) && isNotEmpty(list.IPAddress)
if !onlyOneSpecified || allSpecified {
return errors.New("only one of the 'awsSecurityGroup', 'cidrBlock' or 'ipAddress' is required be specified")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] May I suggest we replace this with a function? I know this is a one-time special thing, but this is really hard to read.

Maybe something like this: https://goplay.space/#889tv6pZ7l-

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure!

// so we have to list all possible formats
func ParseISO8601(dateTime string) (time.Time, error) {
return time.Parse(dateTime, "2006-01-02T15:04:05-0700")
parse, err := time.Parse("2006-01-02T15:04:05-07", dateTime)
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think Atlas returns UTC only, but thinking about it - this might be useful in the future if we decide to change/validate user input somehow since user input can contain a timezone shift.

@antonlisovenko antonlisovenko merged commit 5626e87 into main Feb 9, 2021
@antonlisovenko antonlisovenko deleted the CLOUDP-78181-ip-access-list-2 branch February 9, 2021 17:33
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.

3 participants