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

fix: Avoids import error for database_user when both username and auth database contain hyphens #2928

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

EspenAlbert
Copy link
Collaborator

@EspenAlbert EspenAlbert commented Dec 26, 2024

Description

  • Avoids import error for database_user when both username and auth database contain hyphens
  • Adds ImportSplit3 helper function for splitting id by /. See details on why / in issue

Link to any related issue(s): CLOUDP-289266 #2876

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

@github-actions github-actions bot added the bug label Dec 26, 2024
@EspenAlbert EspenAlbert marked this pull request as ready for review December 26, 2024 10:38
@EspenAlbert EspenAlbert requested review from a team as code owners December 26, 2024 10:38
Copy link
Contributor

APIx bot: a message has been sent to Docs Slack channel

Copy link

@erabil-mdb erabil-mdb left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +13 to +20
func ImportSplit3(importRaw string) (ok bool, part1, part2, part3 string) {
parts := strings.Split(importRaw, "/")
if len(parts) != 3 {
return false, "", "", ""
}
return true, parts[0], parts[1], parts[2]
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

[Curious] Is the use of / as a separator for import applied to all the resources? Besides this question, I think you should add additional documentation to highlight this change in the TF doc

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 would update the resource documentation import section.

@@ -364,3 +365,69 @@ func getDatabaseUserModel(roles, labels, scopes basetypes.SetValue, password typ
Scopes: scopes,
}
}

func TestSplitDatabaseUserImportID(t *testing.T) {
const invalidDefaultString = "import format error: to import a Database User, use the format {project_id}-{username}-{auth_database_name} OR {project_id}/{username}/{auth_database_name}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we export this error message to a common const and re-use here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants