Skip to content

Commit

Permalink
Merge pull request #19 from unparallel-innovation/main
Browse files Browse the repository at this point in the history
External project importer integration
  • Loading branch information
schlotze authored Oct 26, 2022
2 parents 2f4c87e + 301a55d commit 7d9209b
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ide-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
# build image
docker build . --tag ${CONTAINER_IMAGE}
# push image
docker push ${CONTAINER_IMAGE}
# docker push ${CONTAINER_IMAGE}
2 changes: 1 addition & 1 deletion client/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const routes = [
component: NotImplemented
},
{
path: "/dashboard",
path: "/",
name: "Dashboard",
component: Dashboard
},
Expand Down
3 changes: 1 addition & 2 deletions client/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default new Vuex.Store({
{
category: "root",
options: [
{ title: 'Dashboard', link: '/dashboard' },
{ title: 'Workflows', link: '/workflows' },
{ title: 'Services', link: '/services' },
{ title: 'Deployments', link: '/deployments' }
Expand Down Expand Up @@ -84,7 +83,7 @@ export default new Vuex.Store({
category: "Project",
options: [
{ title: 'Edit Project Settings', link: '' },
{ title: 'Close Project', link: '/dashboard' }
{ title: 'Close Project', link: '/' }
]
}
]
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ services:
ROOT_URL: ${APP_ROOT_URL:-http://localhost}
MONGO_URL: mongodb://mongo:27017/meteor
PORT: 8080
KEYCLOAK_URL:
KEYCLOAK_REALM:
KEYCLOAK_CLIENT_ID:
CHE_URL:
SMARTCLIDE_BACKEND_URL:
deploy:
resources:
limits:
Expand Down
9 changes: 8 additions & 1 deletion imports/ui/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
};
},
created() {
// Meteor.call("getKeycloakConfiguration", (error, result) => {
// if(result) {
// this.$store.state.keycloak = result;
// this.$store.state.keycloak = new Keycloak(result);
// }
// });

this.$store.state.keycloak = new Keycloak("/keycloak.json");

this.$store.state.keycloak.init({
Expand All @@ -53,7 +60,7 @@
if(authenticated){
this.eclipseCheUser = this.$store.state.keycloak.tokenParsed;
this.addUserToDB();
router.push("/dashboard");
// router.push("/dashboard");
}
}).catch(error => {
console.log(error);
Expand Down
9 changes: 6 additions & 3 deletions imports/ui/components/CheTheia/CheTheia.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="name text-primary">{{projectName}}</div>

<div class="d-flex h-100">
<iframe id="iframe" :src="workspaceURL"/>
<iframe id="che-theia-iframe" :src="workspaceURL"/>

<div class="loading d-flex justify-content-center align-items-center flex-column bg-white">
<b-spinner class="spinner-border text-primary" style="width: 5rem; height: 5rem;" role="status"/>
Expand Down Expand Up @@ -97,7 +97,7 @@
}
},
sendMessageToIframe(messageType){
const iframe = document.getElementById("iframe");
const iframe = document.getElementById("che-theia-iframe");

try {
let message;
Expand Down Expand Up @@ -156,11 +156,13 @@
align-items: center;
padding-left: 15px;
}
#iframe{

#che-theia-iframe{
border: 0;
height: 100%;
width: 100%;
}

.loading {
z-index: 9;
width: 100%;
Expand All @@ -169,6 +171,7 @@
bottom: 0px;
left: 0px;
}

.spinner-border{
animation: 1.75s linear infinite spinner-border;
}
Expand Down
2 changes: 1 addition & 1 deletion imports/ui/components/Layout/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<!-- LOGO -->
<div class="logo-container">
<router-link to="/dashboard"> <b-img class="logo" src="/assets/SmartCLIDERGBColor.png" @click="optionClicked('home')"/></router-link>
<router-link to="/"> <b-img class="logo" src="/assets/SmartCLIDERGBColor.png" @click="optionClicked('home')"/></router-link>
</div>

<!-- TODO: avoid this -->
Expand Down
2 changes: 1 addition & 1 deletion imports/ui/components/MyAccount/Credentials.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
value: null
},
token: {
label: "Token",
label: "Personal Access Token (PAT)",
formType: "password",
value: null
}
Expand Down
64 changes: 53 additions & 11 deletions imports/ui/components/Services/ServiceCreation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,16 @@
gitCredentials: [],
currentStep: 1,
totalSteps: 2,
receivedService: {},
serviceCreated: false
}
},
mounted(){
this.hideOverlay();
this.fetchGitCredentials();

if(this.$route.query.serviceID)
this.fetchService();
},
methods: {
showOverlay(){
Expand All @@ -208,7 +212,10 @@
$(".creating").addClass("d-none");
},
cancelButtonClicked(){
router.back();
if(Object.keys(this.$route.query).length !== 0)
router.push("/services");
else
router.back();
},
previousButtonClicked(){
this.currentStep--;
Expand Down Expand Up @@ -264,19 +271,54 @@
resetCredentialsOptions(){
this.steps[0].fields.credentials.options.splice(1);
},
fetchService(){
Meteor.call("request", {
operationID: this.$store.state.apis.backend.endpoints.getServiceByID.operationID,
parameters: JSON.parse(`{
"${this.$store.state.apis.backend.endpoints.getServiceByID.parameters.serviceID}": "${this.$route.query.serviceID}"
}`),
token: this.$store.state.keycloak.idToken
}, (error, result) => {
if(result){
this.receivedService = result.body;
this.fillFormIn();
}
});
},
fillFormIn(){
this.steps[1].fields.name.value = this.receivedService.name;
this.steps[1].fields.description.value = this.receivedService.description;
},
setupProject(){
const parameters = {
'projectName': this.steps[1].fields.name.value,
'projVisibility': this.steps[1].fields.visibility.value,
'projDescription': this.steps[1].fields.description.value,
'gitLabServerURL': this.steps[0].fields.credentials.value.url,
'gitlabToken': this.steps[0].fields.credentials.value.token
};
let createRepositoryMethod;
let parameters = {};
let headers = {};

if(Object.keys(this.$route.query).length !== 0){
createRepositoryMethod = "importRepository";
parameters = {
'repoUrl': this.receivedService.url.replace(".git", "")
};
headers = {
'gitLabServerURL': this.steps[0].fields.credentials.value.url,
'gitlabToken': this.steps[0].fields.credentials.value.token
};
}
else{
createRepositoryMethod = "createRepository";
headers = {
'projectName': this.steps[1].fields.name.value,
'projVisibility': this.steps[1].fields.visibility.value,
'projDescription': this.steps[1].fields.description.value,
'gitLabServerURL': this.steps[0].fields.credentials.value.url,
'gitlabToken': this.steps[0].fields.credentials.value.token
};
}

Meteor.call("createRepository", this.$store.state.keycloak.idToken, parameters, (error, result) => {
Meteor.call(createRepositoryMethod, this.$store.state.keycloak.idToken, headers, parameters, (error, result) => {
if(result){
if(result.status === 0){
const repositoryURL = result.message;
if(result.status === 0 || (Object.keys(this.$route.query).length !== 0 && result === 201)){
const repositoryURL = Object.keys(this.$route.query).length !== 0 ? parameters.repoUrl : result.message;
const devfileURL = this.steps[1].fields.framework.value;

Meteor.call("getDevfile", this.$store.state.keycloak.idToken, devfileURL, (error, result) => {
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"@babel/runtime": "^7.18.6",
"@unparallel/smartclide-backend-connector": "^0.7.0",
"@unparallel/smartclide-che-rest-client": "^1.0.6",
"@unparallel/smartclide-che-rest-client": "^1.0.8",
"@unparallel/smartclide-frontend-comm": "^0.4.0",
"axios": "^0.27.2",
"bootstrap": "^4.6.1",
Expand Down
58 changes: 44 additions & 14 deletions server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,61 +30,63 @@ Meteor.startup(() => {
});

Meteor.methods({
// Che REST API
async getLatestWorkflows(){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

return await connector.getMostRecentWorkflows();
},
async getLatestServices(){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

return await connector.getMostRecentServices();
},
async getLatestDeployments(){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

return await connector.getMostRecentDeployments();
},
async createWorkspace(keycloakToken, devfile){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

return await connector.createWorkspace(keycloakToken, devfile);
},
async getWorkspaces(keycloakToken){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

return await connector.getWorkspaces(keycloakToken);
},
async getLatestWorkspaces(keycloakToken, length){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

return await connector.getLatestWorkspaces(keycloakToken, length);
},
async getWorkspace(keycloakToken, workspaceID){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

return connector.getWorkspace(keycloakToken, workspaceID);
},
async startWorkspace(keycloakToken, workspaceID){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

await connector.startWorkspace(keycloakToken, workspaceID);
},
async updateWorkspace(keycloakToken, workspaceID, data){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

return await connector.updateWorkspace(keycloakToken, workspaceID, data);
},
async stopWorkspace(keycloakToken, workspaceID){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

await connector.stopWorkspace(keycloakToken, workspaceID);
},
async deleteWorkspace(keycloakToken, workspaceID){
const connector = new Connector();
const connector = new Connector(process.env.CHE_URL);

await connector.deleteWorkspace(keycloakToken, workspaceID);
},
// SmartCLIDE Backend APIs
async request(configuration){
let connector = await new SmartCLIDEBackendConnector("https://raw.githubusercontent.com/goncalorolo/swagger-json/main/smartCLIDE_DB_API_swagger.json");

Expand All @@ -95,17 +97,17 @@ Meteor.methods({

return await connector.exists(entity, id, keycloakToken);
},
async createRepository(keycloakToken, input){
async createRepository(keycloakToken, inputHeaders, inputParameters){
const configuration = {
method: 'POST',
url: 'https://api.dev.smartclide.eu/service-creation/createStructure',
url: `${process.env.SMARTCLIDE_BACKEND_URL}/service-creation/createStructure`,
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${keycloakToken}`
}
}

Object.assign(configuration.headers, input);
Object.assign(configuration.headers, inputHeaders);

try{
const res = await axios(configuration);
Expand All @@ -114,6 +116,26 @@ Meteor.methods({
throw e;
}
},
async importRepository(keycloakToken, inputHeaders, inputParameters){
const configuration = {
method: 'POST',
url: `${process.env.SMARTCLIDE_BACKEND_URL}/external-project-importer/importProject`,
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${keycloakToken}`
},
params: inputParameters
}

Object.assign(configuration.headers, inputHeaders);

try{
const res = await axios(configuration);
return res.status;
} catch(e){
throw e;
}
},
async getDevfile(keycloakToken, devfileURL){
const configuration = {
method: 'GET',
Expand All @@ -129,5 +151,13 @@ Meteor.methods({
} catch(e){
throw e;
}
},
// Keycloak
getKeycloakConfiguration(){
return {
url: process.env.KEYCLOAK_URL,
realm: process.env.KEYCLOAK_REALM,
clientId: process.env.KEYCLOAK_CLIENT_ID
}
}
});

0 comments on commit 7d9209b

Please sign in to comment.