I’m trying to connect my app inside codespace to digitalocean database, I know I need to add ip’s through the trusted source so from the codespace I can access my database.
I created a digitalocean function script that will constantly update the database trusted source with github ips from here api.github.com/meta. Below is the script
const axios = require('axios');
function main(args) {
const do_token = "PERSONAL_ACCESS_TOKEN";
const db_cluster = "DATABASE_CLUSTER";
const api_url = `https://api.digitalocean.com/v2/databases/${db_cluster}/firewall`;
const app = async function(){
let meta = await axios.get('https://api.github.com/meta')
.then( res =>{
return res.data;
})
.catch(err=>{
console.log(err);
return [];
});
let firewall_list = await axios.get(api_url,{
headers: {
'Content-Type' : 'text/plain',
'Authorization': `Bearer ${do_token}`
}
})
.then( res =>{
return res.data.rules;
})
.catch(err=>{
console.log(err);
return [];
});
let meta_web = meta.web.filter(i => !i.includes(':') ).map(i=>{
return {
"type": "ip_addr",
"value": i
}
});
let rules = [...firewall_list,...meta_web];
let new_rules = { "rules": [] };
rules.forEach(item=>{
if(!new_rules.rules.find(i=>i.value === item.value)){
new_rules.rules.push(item);
}
});
await axios({
url: api_url,
method: 'put',
data: new_rules,
headers: {
'Content-Type' : 'text/plain',
"Authorization": `Bearer ${do_token}`
}
})
.then( res =>{
return res.data;
})
.catch(err=>{
console.log(err);
return [];
});
return { "message": true, "new_rules": new_rules }
}
return app();
}
The above code works but unfortunately I’m still not able to connect to the digitalocean database. I tried the git, api, web ip’s on the trusted but seems none of them are correct. Any help?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
While GitHub publishes IP ranges for several products on its Meta API, IP addresses for codespaces are dynamically assigned, meaning your codespace is not guaranteed to have the same IP address day to day. For more information about the Meta API, see “Meta.”
Someone has raised this to the GitHub team as well here:
I could suggest adding a comment to that discussion mentioning that you are also interested in that feature.
Allowlisting an entire IP range would give overly broad access to your database anyway, so for the time being, you might have to disable the trusted sources for your database while the GitHub team works on that feature request.
Best,
Bobby