Api Key Spring boot
I have an api Key in my application.properties file in my spring boot app but when I try it to push on the GitHub so it gives me an error that the secret key will not be pushed to GitHub ! ..
Can someone help me what to do in this case ?
328 Replies
⌛
This post has been reserved for your question.
Hey @Danix! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
just don't include the key in the repository?
Note that if you already committed it, you'll need to remove or amend that comment (not just revert it)
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
i have the api key in the app.properties then what to do in this case?
To address this issue, you have a few options:
Environment Variables: Store the API key in an environment variable and access it using System.getenv() instead of directly reading it from the application.properties file. This way, the key will not be included in your repository.
.gitignore: Exclude the application.properties file from being pushed to GitHub by adding it to a .gitignore file in the project root. This prevents the file from being visible to anyone who doesn't have direct access to your local machine.
External Configuration: Store the API key in an external configuration file (e.g., a properties file or JSON file) that is not committed to your repository. Your application can then read the key from this file at runtime.
Secrets Manager: Use a secrets manager service like Vault or AWS Secrets Manager to securely store and retrieve the API key. This provides a more robust and centralized solution for managing sensitive data.
Masking the API Key: Consider masking the API key in the output of Git commands like git diff or git log. This can help reduce the visibility of the key, even though it's still technically in the repository.
Choose the approach that best suits your project's requirements and security needs.
hey i dont know how while trying to push the changes to the git i lost my yesterday's code
oh sad
i used this commands
you want to get back your code?
yeh
ok wait
Try this
Check Your Local Files:
Look for your yesterday's code in your project directory. Since git rm --cached doesn't delete the files from your computer, they should still be there.
If you find them, add them back to git:
Bash
git add. # Adds all changes in the current directory and its subdirectories
git commit -m "Recover lost changes"
the code is deleted from my local repo not from the remote repo
! idk how this happens
code is also delete from your local pc?
yehh
idk how
you check your recycle bin?
So let me tell you the whole scenerio i have parent folder and it have its own sub folders backend and frontend so the sub folders have the git ignore and git attribute things so i deleted them few mins ago so may be thats how my code got delted from locally
Has this scenario happened to you?
.gitignore Removed: When you deleted the .gitignore file, files previously ignored by Git (like build artifacts, temporary files, or dependencies) became tracked.
.gitattributes Removed: Deleting .gitattributes might have affected how Git handles line endings or other file attributes, potentially leading to unexpected changes in your working directory.
Git Commands: If you executed commands like git add., git commit -m "some message", and git push, those previously ignored files would have been added to your Git history, potentially overwriting your actual code files with unintended changes.
so what to do now at this time ?
1. Recover .gitignore and .gitattributes:
Check Recycle Bin/Trash: Look for the deleted .gitignore and .gitattributes files in your Recycle Bin or Trash and restore them if found.
File Recovery Software: If not in the Recycle Bin, try using file recovery software (like Recuva or TestDisk) to recover them.
Remote Repository: If you have a remote Git repository, you can clone or fetch the latest version to get back the .gitignore and .gitattributes files.
2. Restore Previous Commit:
Once you have the .gitignore and .gitattributes files back, use git reflog to find the commit before you deleted them.
Use git reset --hard <commit-hash> to restore your project to that previous state.
3. Check for Untracked Files:
After restoring the previous commit, check if there are any untracked files in your project directory using git status.
If you find your lost code files among the untracked files, add them back to Git using git add. and commit the changes.
Do this may be it's work for you.
can i show u the screen ?
come in my ib msg i will guide you
u mean dm?
.
yes
yeh coming
@Muhammad Hasnat Please don't post ChatGPT answers here. Doing so is disrespectful towards askers. If someone wants to ask ChatGPT, they can
it's paid version answers and 100% accurate so that's why i share at here
otherwise i don't
No it isn't 100% accurate. And don't share stuff without other people asking for it. See #❗︱how-to-get-help (7).
ok thanks for suggestion
What other commands did you use? Did you commit the files before? Are the files gone both locally and on GitHub?
yes it says removed from both
You might be successful with the reflog. But before doing anything, please copy the entire directory (folder) with the .git and the files (so you have a backup of your current state in case you are executing commands causing git to remove dangling references)
The interesting question is whether they were committed before (even if the commit was rewritten/removed)
yeh i committed the file before but i didnot reach to github bcz of my api key issue and suddenly got deleted from my local repo
Then you can likely recover it using the reflog
First, make a backup of the entire project including the .git folder
Once you have done that, type
git reflog
. That shows you the last commits and similar things you made (even if you overwrote these commits with something else).
It should give you a list of commit hashes
for each of the elements in that list, starting at the top one, type git checkout REF
where REF is the element in that list. Check for the deleted files after executing each of these commands.
if you feel unsure, show the output of the command.It had given me only the first commit
Oh and also check
git status
first. Ensure there are no "untracked" or modified files
Did you delete and re-clone the repository?no
this is how my project looks
and that's the full output?
Did you maybe delete and recreate the .git folder?
What is the output of
git log
and git status
?yeh i recreate this git folder for the parent folder
This is the output
and
git log
?And you are sure the lost files were in that directory?
It doesn't look like there's an application.properties supposed to be there
when i did this before my files code got vanished i was getting all the files in the whole project
What exactly did you run?
and which files disappeared
git rm --cached
on its own doesn't delete any filesthere is no file which has been lost the code of some files got lost and the api key from the app.properties as well
Can you show the ScriptEnhancerBackend directory?
Its like i got my previous code back instead of the lastest one !
yeh
I assume the lost files would be suppised to be there
It would be good to know what you did except
git rm --cached
run git status
and git reflog
in that directorylet me
git status :
Ah I see Eclipse files ❤️
this is the git log
First of all,make a backup of the entire ScriptEnhancerApp directory
u mean copy and paste to another place ?
yes, copy the entire folder
What is it with the changes there? What do you want to do with them?
what ?
When you said you lost files - are the contents gone/changed or are the entire files gone?
git tells you these files are changed without git knowing about these changes
untracked = aren't committed yet but exist on your computer
modified = changed on your computer but the changes aren't committed
hm
i copy and pasted the whole project
?
this is the repo of github in case u need it https://github.com/Deepak2250/scriptenhancerapp
GitHub
GitHub - Deepak2250/scriptenhancerapp
Contribute to Deepak2250/scriptenhancerapp development by creating an account on GitHub.
What did you copy paste from where to where?
like u said make a copy of the whole project
the thing is - if you check for lost files, the current untracked and modified files would kinda be gone
Can you run
git diff HEAD
? That should show some modifications. Do you prefer having these modifications or not?in which folder : parent or any sub folder
backend
we do everything in backend now
What exact files are missing?
Did you make these changes there? You can use the space key to show more and
q
to exit
And do you prefer having these changes or not?in the service folder i have a class called text enhancer.java and the changes that i had made in it yesterday like some more methods are gone and it looks like the code is back to the previous versionn of itself and the modifications i had done in security config and in the controller of textenhancer some methods are also gone there that i had made yesterday !
What about the modifications that are shown in this command? Would you like them or not?
actually we can just stash them and you can access them later
yeh sure
run the following commands:
that saves your current modifications (output of
git diff
) for later
Then you check git status
. That should be empty.
If it is, run git reflog
and show the outputwait i got the whole project that was around 10 days ago !
what the hell
you want the state from yesterday and not 10d ago, right?
yeh
What does
git status
show?nothing to commit
the whole thing
or
git log
you probably need that
the first line of git log
write down the first commit hash there
the e326...
If anything goes bad, running
git checkout e32676e...
followed by git stash apply
gets you back to what you had today (before git stash
). Don't do that right now
Once you have written that down, run git reflog
and show me the outputso first i need to make the
git checkout
then git reflog
are u there @dan1st | Danielyes but I had to fix something with @JavaBot
6397435 HEAD@{4}: reset: moving to HEADthat doesn't look that good but we can try
can u please help bcz now it becomes even worse
so, you run
then you check for the lost files
that's why I told you to make a backup and stash the changes - so you can get back if it doesn't work
Can you try
git checkout "HEAD@{1}"
?
With double quotes like thatThat one looks like you might have never committed the files you said are lost in which case git didn't record anything about these files
now check for the files
oh can you please enter the following commands and show me the output?
.
I assume you checked for the lost files and they aren't there?
if yes, run
and check again
I already had made a backup of this project when u told me to do and now i can delete this project and can work on the backup porject but i need your help in that too aswell bcz i am not able to push my code to github
you might still be able to recover it
with these commands
or similar
like the yesterday's code as well ?
possibly
so can i make another backup of the backup project and try it in it and can recover the yesterdays code !
this is the current folder
with all the class and code expect the methods and code which were vanished before
After doing that, yesterday's code was still not here, right?
yeh
then, run
in the backend directory
but now we have the backup project
and check again
we first check for yesterday's code
no i cant bcz i deleted the bad project
Why????
now we have to work with these project
the
backup
now you need a copy of the backup (not the actual backup) and do the same things again
and don't delete stuff
the whole point was going back to see what information git has about the past
so what to do now for this backup
create a copy of the backup
don't change anything within the backup
ok done
ok
now
so in the copy of the backup, you have a ScriptEnhancerBackend directory
yeh
there, you again run the following commands
ok so you first run
This gets you back to 10 days ago and that's intended
and then you run
git status
and git reflog --all
again
ok done
Good. Then you run the following:
then you check for the lost files
my fault, it should be
now check for the lost files
i cant see any files !
?
as u said look for the lost files ! There is no file here in the output from the command
Not in the command
in explorer
I said u before that there are no files that had been lost ! Some code from the files like the controller , service that i had made yesterday is lost
.
I don't expect any files in the command
then you can run
and check again
now check the files in explorer
same as before
Then
and check again - it might still be the same as before but please still check
nahh same
even i checked the 2 or 3 as well
then
same
100% exact same?
yeh
then you should be able to get back with
then you should have the state you had earlier today
But from what you have shown, you have either deleted the git repository in some way or you executed commands other than
git rm --cached
please check that i even did this
that one actually removes stuff without you being able to recover it if you haven't committed it before
these are the commits i did before
is there any way to recover it now ?
and that can also result in you losing data
if you haven't committed it, you cannot recover it
oh
felt bad for me
src/main/resources/application.properties
is one of the lost files, right?
There is one thing you could try but if you have never committed it, it wouldn't help muchit is not lost the api key that i had set in it is lost
what
You first need to know the exact path of one of the lost files
and then you can tell git to search for it
how ?
Do you have such a path?
for example
i didnot get it ?
.
?
You first need to know the exact path of one of the lost files
but it likely doesn't find anything
like this one
then you can try executing
inside
ScriptEnhancerBackend
and also
outside of itoh
run
Did the state from 10 days ago have an application.properties?
yeh
I see
try running
not the whole path with C:
just
to specifically check the application.properties changes
that doesn't seem like a very useful change
you could also try
but ig it doesn't show you much either
ig that's the original file without any of the changes you want
like the state of 10 days ago?
listen ig the lost is recoverable by me manually so just tell me : So as you had watched my git hub and any local project strcture so what should i have to do to push the rest of the code to the GitHub bcz before i was getting issue ! for ex: i want the whole backend folder to be committed and pushed so what to do ? without the app.properties inside it .. bcz i had lost my file just while doing push the code to github
ok so currently you have multiple .git directories - one in the project root and one in the backend directory
You want to push the files you have right now, right?
Yeh
then you can delete the
.git
directory in ScriptEnhancerBackend (again, make sure you have a backup)
and then you can git add
and git commit
the files
but if you have nested .git directories, you cannot push the inner one pretty much (it's a bit more complicated than that - git would assume these are different repositories)ok now i had deleted the .git from the basckend folder so should i have to go to the parent folder to git add ?
yes
you can do
git add .
and git status
there - it should then show you the changes it wants to commit
make sure these don't contain anything you don't want to commit (if there is a token somewhere, don't commit it) i am doing this
you can just do
git add ScriptEnhancerBackend
but ig your command works as wellthis is an issue ?
Can you show your
.gitignore
?
Does your ScriptEnhancerBackend
really contain stuff you want to commit and not have its own .git folder?the backend folder gitignore :
parent folder gitignore : is empty
Do you have a .git folder in ScriptEnhancerBackend?
no
What is the output of
git status
in ScriptEnhancerBackend?
Does it really contain the files you want to commit?
like the files from earlier todayit seems all files you have there currently are already committed
What's the output of
git log
?in backend?
doesn't matter
but I'd do it in the root directory
it seems like you currently have the state from Jan 21
and not the state from earlier today as you have said
hm
I literally asked you that multiple times
so ig just make a copy of the backup again
yeh
and in that copy of the backup (again, don't touch anything with the backup), remove the .git folder inside the ScriptEnhancerBackend and run
git status
What's the output of
git remote
?in the backend its : origin
same with the parent
What happens when running
git push origin main
?
it seems like all changes you have locally are already committedRun the following commands
this creates a new branch with your current state and pushes that
so you would then have a main and test branch on GitHub you can use to investigate and choose what you prefer
ok
now how to integrate with the main and the test
oh ok
Can you try running the following commands in the root?
i.e. run the commands in ScriptEnhancerApp
and then
git status
Also do you have a .gitattributes file?in backend and frontend folder yes
ok now that one looks good
now you can commit and push that
it think here is the issue
git push origin test
you are on the test
branch
because I didn't want you overwriting the main branch for nowdone
GitHub
GitHub - Deepak2250/scriptenhancerapp at test
Contribute to Deepak2250/scriptenhancerapp development by creating an account on GitHub.
yeh if we only talk about the backend
?
i mean we only pushed the backend folder not the frontend one
What is the output of
git status
?you can add and commit them as well
ok but for now what to do ?
?
If you want to commit the frontend, do it
ok i pushed it to the test branch and now how to integrate with the main ?
Does the test branch have everything as you want it to?
GitHub
scriptenhancerapp/ScriptEnhancerFrontend at test · Deepak2250/scrip...
Contribute to Deepak2250/scriptenhancerapp development by creating an account on GitHub.
I think you have both a ScriptEnhancerFrontend directory and that also has a ScriptEnhancerFrontend inside it
the frontend have multiple folders of frontend
Is the test branch looking perfectly as it should?
yehh i dont know how it comes should in have to delete it ?
the one with no code or less code
if you don't want it, delete the inner one, add the change to git, commit and push it
and also want to remove it from the remote branch test
assuming you want to get rid of the inner one
yes
ok so now the test have everything i want but i dont want the app.properties
then you run
git rm --cached ScriptEnhancerBackend/src/main/resources/application.properties
and after that, you add ScriptEnhancerBackend/src/main/resources/application.properties
to the .gitignore of scriptenhancerapp
then run git status
after git rm --cached ScriptEnhancerBackend/src/main/resources/application.properties should i have to push the chanhe to guithub or not ?
first check
git status
add
ScriptEnhancerBackend/src/main/resources/application.properties
to the .gitignoremanually ?
also I think you probably want to add
.project
and .settings
to the gitignoreo mamma mia is this thread gonna have the most messages in java help
yes
😱
I think we had more in the past
perhaps
whats such a big problem with ignoring the secret key btw
ok done
did u delete some commit
git add .gitignore?
git status
?
the issues that happened afterwards'
should i push it ?
looks good - you can commit and
git push
actually there is something a bit weird
can you show your .gitignore?Can you show the .gitignore in ScriptEnhancerBackend?
idk why
ScriptEnhancerBackend/src/main/resources/application.properties
is shown as untracked
you could also try to add the application.properties
to the .gitignore of ScriptEnhancerBackendyeh did it
Output of
git status
?Can you show that file?
without the
ScriptEnhancerBackend
there
and also use forward slashes and not backslashes
?
the leading slash isn't necessary
but yes
and then check
git status
againperfect
you can add the gitignore, commit and push
from parent right ?
both work
form parent, it's
git add ScriptEnhancerBackend
, from ScriptEnhancerBackend it's git add .
issue
oh I think you added the .project and .settings directories
run the following commands once
ok
done
git status
ok now you're safe again
the issue is that the gitignore doesn't seem to work properly
Do you have a "how 9864b4a:15" file?
again ? how
the commands removed the commit causing the error without touching your files
yeh
idk how it comes
but committing again might reintroduce the error
Do you need it?
no
then delete it
vooooooo
1 sec
i got my api key here
that file contains the token preventing you from pushing, yes
alternatively you can rename it to
token.txt
or something similar
and then add that to the .gitignorecan i add my api key to the app.properties ?
and gitignore it
?
the application.properties is already in the gitignore
yeh sorry
so yes just add it there
and then you can also delete that "how" file
ok delete it
git status
?ok so the
ScriptEnhancerBackend/src/main/resources/META-INF/additional-spring-configuration-metadata.json
contains a changeyeh
you can use
git diff ScriptEnhancerBackend
to view that change
Do you want to commit it?yeh
then you can do so
Can you enter
git rm --cached .project
? Does that do anything?
and does it change git status
?oh I think you just accidentially added .project and .settings
it seems like the .gitignore doesn't work for these
you can try adding
/.project
to the gitignore maybe
Do you have a file index/exclude
in your .git directory?
or info/excludeyeh
Can you show its contents?
ok
Can you try that?
same as before
git is not getting it !
git status
still showing the file as untracked?up to date
?
Can you run
git rm --cached .project
and git rm -r --cached .settings
?
and git status
againCan you show your .gitignore again?
Did you add
/.project
and /.settings
there?Can you run
git rm --cached .settings
and show git status
again?
For some reason it seems like git is ignoring that .gitignore fileweird
you could try deleting and recreating the .gitignore file but I have no idea why it isn't ignoring these files
its ok no worries i will search upon it later
but how to integrate the test branch with main
Do you want to completely overwrite the content of
main
with the content of test
?yeh
ok then first tery
git add .
and execute git status
- it's safer/easier if you have a clean statefrom the test branch ?
ok you can just reset the gitignore to the previous state using
git checkout .gitignore
and then check git status
againoh, it needs to be
git checkout HEAD .gitignore
ok then you can do the following
The first command checks out main
After that, the second command sets the current branch (main) to the test branch (i.e. it completely overwrites the current branch with the content of
test
).
Then, the third command completely overwrites main on GitHub with your local mainok done
looks good
ig you can delete the
test
branchhm but got confused a lot that why those errors and should i have to continue pushing code with main ?
which errors?
pushing to main should be fine now
we are here with alot of errors !
Which errors?
whats the reason to make another branch and push our code in it
What is the output of git branch
?
the
--force-with-lease` bypassed these by overwriting the branch on GitHubok
not able to delete the test!
What's the output of
git branch
?main
then it's already deleted locally but not on GitHub
you can delete it here: https://github.com/Deepak2250/scriptenhancerapp/branches
GitHub
Branches · Deepak2250/scriptenhancerapp
Contribute to Deepak2250/scriptenhancerapp development by creating an account on GitHub.
ok
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
hey 0ne last question ! in future i have to commit the or add or push the code from the backend folder or otherr subfolder where the changes occured or from the parent app folder ?
in principle, both would work but the path can be different
In general, I'd recommend using the parent folder in most cases
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.