feat(devstar home): upload new created public key
This commit is contained in:
@@ -356,15 +356,25 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
|
|||||||
.then(async userPublicKey => {
|
.then(async userPublicKey => {
|
||||||
if (userPublicKey == '') {
|
if (userPublicKey == '') {
|
||||||
await createUserPublicKeyByVSCode()
|
await createUserPublicKeyByVSCode()
|
||||||
await getUserPublicKeyFromVSCode()
|
.then(async () => {
|
||||||
.then(async userPublicKey => {
|
// only upload new created public key
|
||||||
// upload new created public key
|
await getUserPublicKeyFromVSCode()
|
||||||
|
.then(async userPublicKey => {
|
||||||
|
const dataFromResp = await communicateVSCodeByWebview('getMachineName', {});
|
||||||
|
const machineName = dataFromResp.machineName;
|
||||||
|
|
||||||
|
const keyTitle = `${USERNAME}-${machineName}`
|
||||||
|
await uploadNewCreatedPublicKey(userPublicKey, keyTitle);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Failed to get NEW CREATED user public key from vscode: ", error)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Failed to get user public key from vscode: ", error)
|
||||||
|
})
|
||||||
|
|
||||||
closeLoginModal()
|
closeLoginModal()
|
||||||
})
|
})
|
||||||
@@ -460,6 +470,36 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function uploadNewCreatedPublicKey(userPublicKey, keyTitle) {
|
||||||
|
const postData = {
|
||||||
|
"key": userPublicKey,
|
||||||
|
"title": keyTitle
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadUrl = DEVSTAR_HOME + `/api/v1/user/keys`;
|
||||||
|
|
||||||
|
fetch(uploadUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'token ' + USERTOKEN
|
||||||
|
},
|
||||||
|
body: JSON.stringify(postData)
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Error in logging ' + response.statusText);
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(async data => {
|
||||||
|
console.log(data)
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('There has been a problem with your fetch operation:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ===================================== Repo ===========================
|
// ===================================== Repo ===========================
|
||||||
function loadRepositories() {
|
function loadRepositories() {
|
||||||
// clear old data
|
// clear old data
|
||||||
@@ -685,16 +725,13 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
|
|||||||
// TODO: create container
|
// TODO: create container
|
||||||
async function createDevContainer(repoId) {
|
async function createDevContainer(repoId) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
// get public key
|
|
||||||
const publicKey = await getDefaultPublicKeyFromVSCode()
|
|
||||||
|
|
||||||
// request creating container
|
// request creating container
|
||||||
const url = DEVSTAR_HOME + "/api/devcontainer"
|
const url = DEVSTAR_HOME + "/api/devcontainer"
|
||||||
var token = USERTOKEN
|
var token = USERTOKEN
|
||||||
|
|
||||||
const postData = {
|
const postData = {
|
||||||
"repoId": repoId.toString(),
|
"repoId": repoId.toString(),
|
||||||
"sshPublicKeyList": [publicKey]
|
// "sshPublicKeyList": [publicKey]
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
|
Reference in New Issue
Block a user