If Debbie is deployed for the first time on the server follow the below steps:
Create an admin account: docker exec -it debbie-django python manage.py createsuperuser
Enter the username and password for the admin account (keep the username and password the same as Mongo for better accessibility).
Go to http://<server-ip>:8000/admin and login using the credentials entered above to login.
After login select the API keys option and select the ADD API KEY button highlighted below.
Copy the API key generated and save it as it will be only displayed once.
There is also an alternative for steps c,d, and e if those don’t work in case URL is inaccessible:
SSH to the VM where KnowHOW or Debbie is installed and then in the console enter this cmd docker exec -it debbie-django python manage.py shell_plus --ipython
Once the python shell opens enter the following code:
from rest_framework_api_key.models import APIKey api_key, key = APIKey.objects.create_key(name="my-key") print(key)
The above code will give the API key as output, copy it
In the server files do vim /app/apps/.env and paste the below lines:
BASE_HOST_URL=https://4bdf-89-136-52-54.ngrok-free.app
DEBBIE_INTERNAL_API_KEY=<enter the copied API key>
KNOWHOW_SERVER=http://customapi:8080/api/cache/clearCache/bitbucketKpiCacheStop the containers using docker stop debbie-django debbie-knowhow and docker rm debbie-django debbie-knowhow.
Start using docker-compose up -d debbie-django debbie-knowhow.
Encrypt the generated API KEY using the code snippet below:
import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; import java.security.spec.KeySpec; import java.util.Base64; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; public class Main { private static final String ALGO = "AES"; private static final String DEFAULT_MODE_AND_PADDING_SCHEME = "AES/CBC/PKCS5Padding"; private static final int ITERATION_COUNT = 65536; private static final int KEY_LENGTH = 256; private static final String KEY_INSTANCE = "PBKDF2WithHmacSHA1"; private static byte[] generateSalt() { byte[] salt = new byte[16]; new SecureRandom().nextBytes(salt); return salt; } private static IvParameterSpec generateIv() { byte[] iv = new byte[16]; new SecureRandom().nextBytes(iv); return new IvParameterSpec(iv); } public static String encrypt(String text, String key) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, IOException { byte[] salt = generateSalt(); SecretKeyFactory factory = SecretKeyFactory.getInstance(KEY_INSTANCE); KeySpec spec = new PBEKeySpec(key.toCharArray(), salt, ITERATION_COUNT, KEY_LENGTH); SecretKey tempKey = factory.generateSecret(spec); SecretKey secret = new SecretKeySpec(tempKey.getEncoded(), ALGO); Cipher cipher = Cipher.getInstance(DEFAULT_MODE_AND_PADDING_SCHEME);// NOSONAR IvParameterSpec iv = generateIv(); cipher.init(Cipher.ENCRYPT_MODE, secret, iv); byte[] encryptedText = cipher.doFinal(text.getBytes(StandardCharsets.UTF_8)); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); outputStream.write(salt); outputStream.write(iv.getIV()); outputStream.write(encryptedText); return Base64.getEncoder().encodeToString(outputStream.toByteArray()); } public static void main(String[] args) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, InvalidKeySpecException, BadPaddingException, IOException, InvalidKeyException { System.out.println(encrypt("<API-Key-here>", "<AES Encryption key>")); } }
And paste it in /app/apps/properties/customapi.properties file of server as
repoToolAPIKey=<encrypted-api-key-here>
Restart the server docker restart customapi.
General
Content
Integrations