Using MongoDB connection string in a Github repo - mongodb

This might be kind of a weird question, but I have a full-stack project that I am using MongoDB for the database. I am about to put it on a local Github repository. Obviously in the connection string, I have a username & password which I would rather not make public. Does anyone know of a more secure way of doing this?
The whole purpose of this project is to add it to my portfolio, so future employers can see it and potentially try it out. Which means I want it to be as hassle free as possible. I've never done this before so I don't even know if someone who wants to use it would have to set up their own Mongo database just to get it to work properly or if my database can be use for everybody who would potentially want to try it out.
I don't really know what I am doing here.

You need to setup environments files and add them in gitignore file.
Then use dotenv for reading the values inside the file.
Article for step by step guide: https://www.coderrocketfuel.com/article/store-mongodb-credentials-as-environment-variables-in-nodejs

You can use mongodb://localhost as the default connection string, committing this to the repository and using something like dotenv to override the connection string in your application at runtime.

Related

How do I set up a postgres connection on airflow for the postgres operator

For the rtfm crowd, let me document my suffering.
I went here:
https://betterdatascience.com/apache-airflow-postgres-database/
But my ui has UNAUTHORIZED in pink after I add the info.
I also went here:
https://airflow.apache.org/docs/apache-airflow-providers-postgres/stable/connections/postgres.html
But obvious questions remain. Which file? what is the format of the default data. Why can't I just make a connection string and put it somewhere.
I also read this, which doesn't tell us where to put this information, it only tells us how to programmatically override it. It did give me this golden nugget:
Which would have been another stack overflow question.
Is there a file I should type my connection information or connection string into that has examples already?
I solved it. There's no secret file like airflow.cfg. It's hidden away a database somewhere I set up long ago familiar to nobody who doesn't do this full time. To update or add connections, you either have to use the ui, which doesn't work for me, or you have to use the cli and type airflow connections add --conn-uri and the string we all know and love.
Since I wasn't born with the knowledge of all the commands available under the cli, I googled here:
https://airflow.apache.org/docs/apache-airflow/stable/howto/connection.html

Clone rep:policy on AEM

I am currently working on with a solution that would be able to clone/copy/backup my existing rep:policy. 'Cause when we do some jobs it accidentally removed. I am trying to apply this kind of fix, but am failing to. It says it is an invalid path.
javax.jcr.security.AccessControlException: OakAccessControl0006: Isolated policy node. Parent is not of type [rep:AccessControllable]
final Workspace ws = session.getWorkspace();
ws.copy("/etc/commerce/products/abccompany/TvPackChannelMap/rep:policy","/tmp/nxt/TvPackChannelMap/rep:policy");
Are there other ways that I can be able to take the rep:policy thru code?
You need to make sure that your job does not touch the permissions or the rep:policy, this is the best way forward for you.
The exception could be because of /etc/commerce/products/abccompany/TvPackChannelMap/rep:policy does not exist or the user whose session you are using does not have read access to the node.
Make sure the path is correct, copy paste it to your CRX/DE to make sure it exists.
I have tried to use your code to copy a rep:policy from one node to another, works fine. But I would not* recommend copying permissions that way. The best practice is to use the Access Control Management API for all things permissions.
You can check, install and use the access control tool from netcentric. It offers a jmx interface for exporting AC entries and maybe also some APIs you could use to implement your custom solution.
The Other approach is to retrieve the ACL permissions through the query language.
For example, SELECT * FROM [rep:ACL] or SELECT * FROM [rep:ACE] where [rep:principalName] is not null should give you the results.
For more information, I would recommend you to check the ACS commons ACL Packager Implementation which is available on GitHub.
Reference Link - https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/adobe/acs/commons/packaging/impl/ACLPackagerServletImpl.java

Collecting GitHub project issues statistics programmatically?

I'm collecting GitHub issue statistics over time on our project: total number of issues, number of issues with a particular label, number of issues in a given state (open/closed). Right now, I have a Python script to parse the project webpage with the desired labeling/state for the info I want, e.g., http://github.com/<projectname>/issues?label=<label_of_interest>&state=<state_of_interest>
However, parsing the HTML is fragile since if the GitHub API changes, more often than not, my code fails.
Does someone describe how to use the GitHub API (or barring that, know of some other way, preferably in Python) to collect these statistics without relying on the underlying HTML?
May I be so forward as to suggest that you use my wrapper around the GitHub API for this? With github3.py, you can do the following:
import github3
github = github3.login("braymp", "braymp's super secret password")
repo = github.repository("owner", "reponame")
open_issues = [i for i in repo.iter_issues()]
closed_issues = [i for i in repo.iter_issues(state='closed')]
A call to refresh may be necessary because I don't honestly recall if GitHub sends all of the issue information upon the iteration like that (e.g., replace i.refresh() for i in <generator> as the body of the list comprehensions above).
With those, you can iterate over the two lists and you will be able to use the labels attribute on each issue to figure out which labels are on an issue. If you decide to merge the two lists, you can always check the status of the issue with the is_closed method.
I suspect the actual statistics you can do yourself. :)
The documentation for github3.py can be found on ReadTheDocs and you'll be particularly interested in Issue and Repository objects.
You can also ask further questions about github3.py by adding the tag for it in your StackOverflow question.
Cheers!
I'd take a look at Octokit. Which doesn't support Python currently, but does provide a supported interface to the GitHub API for Ruby.
https://github.com/blog/1517-introducing-octokit
Although this doesn't fully meet your specifications (the "preferably Python" part), Octokit is a fantastic (and official - it's developed by GitHub) way of interacting with the GitHub API. You wrote you'd like to get Issues data. It's as easy as installing, requiring the library, and getting the data (no need for authentication if the project is public).
Install:
gem install octokit
Add this to your Ruby file to require the Octokit library:
require 'octokit'
Although there are a lot of things you can get from Octokit::Client::Issues, you may want to get a paginated list of all the issues in a repository:
Octokit.list_issues('octokit/octokit.rb')
# => [Array<Sawyer::Resource>] A list of issues for a repository.
If you're really keen on using Python, you might want to have a look at the GitHub API docs for Issues. Really, it's as easy as getting a URL like: https://api.github.com/repos/octokit/octokit.rb/issues and get the JSON data (although I'm not familiar with Python, I'm sure these some JSON parsing library); no need for authentication for public repos.

Enforcing policies from Atlassian Stash Repository merge request check plugin

I need help on how to successfully create a RepositoryMergeRequestCheck
As part of our merge workflow, we need to ensure some policies about some files. Policies includes among others:
File naming conventions of individual files
File naming conventions between multiple files (for example, correlative-named files)
Inspection of files to enforce or disallow usage of statements or functions
I want to be able to check for this policies on a repository merge request check so I’m building a plugin for Astlassian Stash
I have tried the following approaches:
Using the RepositoryMergeRequestCheckContext parameter of RepositoryMergeRequestCheck.check()
Since the method signature is:
#Override
public void check(RepositoryMergeRequestCheckContext context)
The first thing I tried using was the context parameter. I can say context.getMergeRequest().getPullRequest().getFromRef().getRepository()
Now I get a Repository instance and I’m not sure how to extract commit info from it.
Calling Git directly: Since this check was originally developed as a git hook script, calling git from the SDK made sense to me. It led me to this situation:
String result = gitScm.getCommandBuilderFactory().builder().lsTree().build(…).call();
Where gitScm gets dependency injected in the plugin’s constructor.
Notice the build parameter? It expects a CommandOutputHandler<T> in this case T is string, but that’s an interface, and I’m not sure how to get an instance that implements that interface or how to create one.
REST API
REST API looks the easiest of them but it still doesn’t help with the third requirement of inspecting file’s source code and also, spawning web requests from the merge request check that is itself a web request from stash doesn’t seem to be a good idea from the performance side.
What path should I follow or how can I do it?
I started writing you a response, and then realised that I'd already answered this on Answers (which was what I was going to suggest as well).
https://answers.atlassian.com/questions/182943/enforcing-policies-from-repository-merge-request-check-plugin
Cheers,
Charles

EF Code First not working on deploy hosting

I've an application using MVC and Code First for persistence.
Everything works fine in my development, but when I'm uploading to server, it doesnt work.
In any place i try to create a database, but it keeps me returning the following error: CREATE DATABASE permission denied in database 'master'.
The only thing that i do is override the OnModelCreating method just to map my app.
Anyone has this error?
Thanks
For a tutorial series that shows how to publish your Code First database and prevent Code First from trying to re-create the database in production, see
http://www.asp.net/mvc/tutorials/deployment-to-a-hosting-provider
The third tutorial in the series shows how to set up the Web.config file. The second shows how to deploy if you are using SQL Server Compact, the tenth shows how to deploy to full SQL Server.
You'll need to publish your database out to your hosting provider. Visual Studio has an easy way of doing this. In the server explorer tab, you can navigate to your database, right click and choose publish to provider. By doing this, you will not only export the scheme of your database, but you can also export out all data, stored procs, views etc.
You will need to adjust your code so that you are no longer trying to create a database on code run. Typically this approach is used for development, and you are no longer in development if you're moving to a hosting company. The changes may be in your global.asax, the dbcontext of your solution and any other place where you modified it to create the scheme for the database.
Hope this helps you some, and good luck on your project.