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

[C++] Add an Error Handling section to the Authentication page #98

Merged
merged 11 commits into from
Jan 9, 2025

Conversation

rachel-mack
Copy link
Collaborator

@rachel-mack rachel-mack commented Jan 8, 2025

Pull Request Info

PR Reviewing Guidelines

JIRA - https://jira.mongodb.org/browse/DOCSP-NNNNN

Slack conversation with C++ team

Staging Links

  • security/authentication
  • Self-Review Checklist

    • Is this free of any warnings or errors in the RST?
    • Did you run a spell-check?
    • Did you run a grammar-check?
    • Are all the links working?
    • Are the facets and meta keywords accurate?

    Copy link

    netlify bot commented Jan 8, 2025

    Deploy Preview for docs-cpp ready!

    Name Link
    🔨 Latest commit 35ba496
    🔍 Latest deploy log https://app.netlify.com/sites/docs-cpp/deploys/678015cb9333920008d9b159
    😎 Deploy Preview https://deploy-preview-98--docs-cpp.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    Copy link
    Collaborator

    @mongoKart mongoKart left a comment

    Choose a reason for hiding this comment

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

    LGTM w/ 1 change

    source/security/authentication.txt Outdated Show resolved Hide resolved
    @kevinAlbs kevinAlbs requested a review from eramongodb January 9, 2025 14:11
    source/includes/authentication.cpp Show resolved Hide resolved
    source/security/authentication.txt Outdated Show resolved Hide resolved
    source/includes/authentication.cpp Outdated Show resolved Hide resolved
    @rachel-mack rachel-mack requested a review from eramongodb January 9, 2025 16:53
    Copy link
    Collaborator

    @eramongodb eramongodb left a comment

    Choose a reason for hiding this comment

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

    Minor feedback; otherwise, LGTM.

    Comment on lines 51 to 58
    auto uri = mongocxx::uri("mongodb://<db_username>:<db_password>@<hostname>:<port>/?"
    "authSource=admin&authMechanism=SCRAM-SHA-256");
    auto client = mongocxx::client(uri);
    client["db"].run_command(bsoncxx::from_json(R"({"ping": 1})")); // Any command requiring authorization
    } catch (const mongocxx::exception& ex) {
    std::cerr << "Error: " << ex.what() << std::endl;
    }
    Copy link
    Collaborator

    @eramongodb eramongodb Jan 9, 2025

    Choose a reason for hiding this comment

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

    Suggested change
    try {
    auto uri = mongocxx::uri("mongodb://<db_username>:<db_password>@<hostname>:<port>/?"
    "authSource=admin&authMechanism=SCRAM-SHA-256");
    auto client = mongocxx::client(uri);
    client["db"].run_command(bsoncxx::from_json(R"({"ping": 1})")); // Any command requiring authorization
    } catch (const mongocxx::exception& ex) {
    std::cerr << "Error: " << ex.what() << std::endl;
    }
    auto uri = mongocxx::uri("mongodb://<db_username>:<db_password>@<hostname>:<port>/?"
    "authSource=admin&authMechanism=SCRAM-SHA-256");
    auto client = mongocxx::client(uri);
    try {
    // Any command requiring authorization
    client["db"].run_command(bsoncxx::from_json(R"({"ping": 1})"));
    } catch (const mongocxx::exception& ex) {
    std::cerr << "Error: " << ex.what() << std::endl;
    }

    Consider minimizing the scope of code within the try-catch statement to that which is expected to throw the relevant exception.

    @rachel-mack rachel-mack merged commit cc2059a into mongodb:master Jan 9, 2025
    6 checks passed
    @rachel-mack rachel-mack deleted the DOCSP-41348 branch January 9, 2025 18:44
    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