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 of database connection node js script #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bilalmohib
Copy link

@bilalmohib bilalmohib commented Jul 21, 2023

🚀 Improved Database Connection Security and Error Fix 🚀

🔒 AuthenticationError: As you've Strengthened Your Database Security I have updated your database conn code!

Hello DataStax Team! 👋

  • I hope this message finds you well. 🌟 I wanted to share some required updates regarding the Astra CLI connection code.
  • 🚀 I recently encountered an AuthenticationError while using this repository, and after some investigation, I discovered that your team had recently improved the database security policies. 💪
  • Because of which now support for username and password auth is over so for that I have updated this repo code that is working and is according to the latest best practises.
  • The code is tested and running successfully
  • It would be a great honour for me if you would please merge and it and it will save other developers time as well. Thanks.

🌐 Documentation Reference:
To find out more about these exciting security enhancements and how to handle them gracefully, I referred to the helpful documentation provided by DataStax. 📖 You can check it out here: Manage Application Tokens - Astra Docs.

👨‍💻 Identifying the Issue:
The error message indicated that the existing connection code required some updates to comply with the latest security policies. Upon closer inspection, I found that the client authentication process needed to be revised to accommodate the new changes. And support for username and password auth is over so for that I found it helpful for others to share my code.

💡 The Fix:
After thorough research and experimentation, I successfully updated the Astra CLI connection code to adapt to the enhanced security requirements. 🔧. And use the authentication tokens instead of the removed user name and passsword authentication.

✨ The Improved Connection:

const cassandra = require("cassandra-driver");

// This is the Zip file you downloaded
const SECURE_CONNECT_BUNDLE = '/workspace/crud-with-python-and-node/crud-nodejs/creds.zip';

// Your Astra-specific credentials and keyspace
// Here is the fix where i have used the Token Authentication instead of the username and password authentication because of the updated policy by Cassandra DB.
const CLIENT_ID = "kxPbavsfqWoZaBxqHceZxxeq";
const CLIENT_SECRET =
  "tCP7.jnWxa1YHyxsblH4nd2ymsct9UgZj+RxF6d0ruKB1f,z-EdPOL3b2K4w6OQkhdMbkoCMk77D4sNuqXXe4TBRvuLDQS3wkwuTY8uk-5sb+ELC0d8Wws.GCSWPmqe4";
const KEYSPACE = "spacecraft";

// Init the connection and return the client
function init_connection() {
  var connection = {};
  connection.client = new cassandra.Client({
    cloud: { secureConnectBundle: SECURE_CONNECT_BUNDLE },
    keyspace: KEYSPACE,
    authProvider: new cassandra.auth.PlainTextAuthProvider(
      CLIENT_ID,
      CLIENT_SECRET
    ),
  });
  return connection;
}

connection = init_connection();
module.exports = connection;

🎉 Ready for Your Review!
I am thrilled to share this updated connection code with you, and I am confident that it complies with the latest security policies. 🔒 I believe this fix will ensure a seamless and secure experience for all Astra CLI users. And it will save great time for newbies and begginer developers.

🙏 Request for Your Review:
I would be extremely grateful if the DataStax Team could kindly review this updated code and consider accepting the pull request. Your expert feedback and approval would mean a lot to the Astra CLI community, and it would signify a successful collaboration towards maintaining top-notch security standards. 🌟

Thank you for your time and consideration! 🙌 If you have any questions or require further clarifications, please do not hesitate to reach out. I am eager to contribute to the Astra CLI and make it even more secure and efficient for users worldwide. 🌍

Looking forward to your response and hoping for a positive outcome! 🚀

Best regards,
Muhammad Bilal
Muhammad-Bilal-7896

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.

1 participant