settings: show secrets

This commit is contained in:
Simone Gotti 2019-07-09 14:20:03 +02:00
parent 239f7ee516
commit 4baabd6365
6 changed files with 166 additions and 16 deletions

View File

@ -11,12 +11,12 @@
type="text" type="text"
placeholder="Project Group Name" placeholder="Project Group Name"
v-model="projectGroup.name" v-model="projectGroup.name"
> />
</div> </div>
</div> </div>
<div class="mb-4"> <div class="mb-4">
<label class="checkbox"> <label class="checkbox">
<input type="checkbox" v-model="projectGroupIsPrivate"> <input type="checkbox" v-model="projectGroupIsPrivate" />
Private Private
</label> </label>
</div> </div>
@ -32,10 +32,17 @@
</div> </div>
</div> </div>
<div class="panel">
<p class="panel-title">Secrets</p>
<div class="p-4">
<projectsecrets :secrets="secrets" :allsecrets="allsecrets" type="projectgroup" />
</div>
</div>
<div class="panel"> <div class="panel">
<p class="panel-title">Variables</p> <p class="panel-title">Variables</p>
<div class="p-4"> <div class="p-4">
<projectvars :variables="variables" :allvariables="allvariables"/> <projectvars :variables="variables" :allvariables="allvariables" type="projectgroup" />
</div> </div>
</div> </div>
@ -66,7 +73,7 @@
v-model="projectGroupNameToDelete" v-model="projectGroupNameToDelete"
type="email" type="email"
placeholder="Project Group name to delete" placeholder="Project Group name to delete"
> />
</div> </div>
<button <button
class="btn btn-red" class="btn btn-red"
@ -88,6 +95,7 @@
<script> <script>
import { import {
fetchProjectGroup, fetchProjectGroup,
fetchSecrets,
fetchVariables, fetchVariables,
updateProjectGroup, updateProjectGroup,
deleteProjectGroup deleteProjectGroup
@ -95,10 +103,11 @@ import {
import { projectGroupLink } from "@/util/link.js"; import { projectGroupLink } from "@/util/link.js";
import projectsecrets from "@/components/projectsecrets";
import projectvars from "@/components/projectvars"; import projectvars from "@/components/projectvars";
export default { export default {
components: { projectvars }, components: { projectsecrets, projectvars },
name: "projectgroupsettings", name: "projectgroupsettings",
props: { props: {
ownertype: String, ownertype: String,
@ -111,6 +120,8 @@ export default {
deleteProjectGroupError: null, deleteProjectGroupError: null,
projectGroup: null, projectGroup: null,
projectGroupIsPrivate: false, projectGroupIsPrivate: false,
secrets: [],
allsecrets: [],
variables: [], variables: [],
allvariables: [], allvariables: [],
projectGroupNameToDelete: "" projectGroupNameToDelete: ""
@ -198,6 +209,28 @@ export default {
this.projectGroup = data; this.projectGroup = data;
this.projectGroupIsPrivate = this.projectGroup.visibility == "private"; this.projectGroupIsPrivate = this.projectGroup.visibility == "private";
({ data, error } = await fetchSecrets(
"projectgroup",
projectgroupref,
false
));
if (error) {
this.$store.dispatch("setError", error);
return;
}
this.secrets = data;
({ data, error } = await fetchSecrets(
"projectgroup",
projectgroupref,
true
));
if (error) {
this.$store.dispatch("setError", error);
return;
}
this.allsecrets = data;
({ data, error } = await fetchVariables( ({ data, error } = await fetchVariables(
"projectgroup", "projectgroup",
projectgroupref, projectgroupref,

View File

@ -0,0 +1,39 @@
<template>
<div>
<h5 class="text-2xl">{{ typetitle }} Secrets</h5>
<secrets v-if="secrets.length" :secrets="secrets" />
<span v-else>No secrets</span>
<hr class="my-6 border-t" />
<h5 class="text-2xl">All secrets (local and inherited)</h5>
<secrets v-if="allsecrets.length" :secrets="allsecrets" :showparentpath="true" />
<span v-else>No secrets</span>
</div>
</template>
<script>
import secrets from "@/components/secrets";
export default {
components: { secrets },
name: "projectsecrets",
props: {
secrets: Array,
allsecrets: Array,
type: String
},
computed: {
typetitle() {
if (this.type == "project") return "Project";
if (this.type == "projectgroup") return "Project group";
return "";
}
}
};
</script>
<style scoped lang="scss">
</style>

View File

@ -10,11 +10,11 @@
type="text" type="text"
placeholder="Project Name" placeholder="Project Name"
v-model="project.name" v-model="project.name"
> />
</div> </div>
<div class="mb-4"> <div class="mb-4">
<label class="checkbox"> <label class="checkbox">
<input type="checkbox" v-model="projectIsPrivate"> <input type="checkbox" v-model="projectIsPrivate" />
Private Private
</label> </label>
</div> </div>
@ -29,10 +29,17 @@
</div> </div>
</div> </div>
<div class="panel">
<p class="panel-title">Secrets</p>
<div class="p-4">
<projectsecrets :secrets="secrets" :allsecrets="allsecrets" type="project" />
</div>
</div>
<div class="panel"> <div class="panel">
<p class="panel-title">Variables</p> <p class="panel-title">Variables</p>
<div class="p-4"> <div class="p-4">
<projectvars :variables="variables" :allvariables="allvariables"/> <projectvars :variables="variables" :allvariables="allvariables" type="project" />
</div> </div>
</div> </div>
@ -63,7 +70,7 @@
v-model="projectNameToDelete" v-model="projectNameToDelete"
type="email" type="email"
placeholder="Project name to delete" placeholder="Project name to delete"
> />
</div> </div>
<button <button
class="btn btn-red" class="btn btn-red"
@ -104,6 +111,7 @@
<script> <script>
import { import {
fetchProject, fetchProject,
fetchSecrets,
fetchVariables, fetchVariables,
updateProject, updateProject,
deleteProject, deleteProject,
@ -112,10 +120,11 @@ import {
import { projectGroupLink } from "@/util/link.js"; import { projectGroupLink } from "@/util/link.js";
import projectsecrets from "@/components/projectsecrets";
import projectvars from "@/components/projectvars"; import projectvars from "@/components/projectvars";
export default { export default {
components: { projectvars }, components: { projectsecrets, projectvars },
name: "projectsettings", name: "projectsettings",
props: { props: {
ownertype: String, ownertype: String,
@ -129,6 +138,8 @@ export default {
updateRepoLinkedAccountError: null, updateRepoLinkedAccountError: null,
project: null, project: null,
projectIsPrivate: false, projectIsPrivate: false,
secrets: [],
allsecrets: [],
variables: [], variables: [],
allvariables: [], allvariables: [],
projectNameToDelete: "" projectNameToDelete: ""
@ -227,6 +238,20 @@ export default {
this.project = data; this.project = data;
this.projectIsPrivate = this.project.visibility == "private"; this.projectIsPrivate = this.project.visibility == "private";
({ data, error } = await fetchSecrets("project", projectref, false));
if (error) {
this.$store.dispatch("setError", error);
return;
}
this.secrets = data;
({ data, error } = await fetchSecrets("project", projectref, true));
if (error) {
this.$store.dispatch("setError", error);
return;
}
this.allsecrets = data;
({ data, error } = await fetchVariables("project", projectref, false)); ({ data, error } = await fetchVariables("project", projectref, false));
if (error) { if (error) {
this.$store.dispatch("setError", error); this.$store.dispatch("setError", error);

View File

@ -1,13 +1,13 @@
<template> <template>
<div> <div>
<h5 class="text-2xl">Local variables</h5> <h5 class="text-2xl">{{ typetitle }} Variables</h5>
<vars v-if="allvariables.length" :variables="variables"/> <vars v-if="variables.length" :variables="variables" />
<span v-else>No variables</span> <span v-else>No variables</span>
<hr class="my-6 border-t"> <hr class="my-6 border-t" />
<h5 class="text-2xl">All variables</h5> <h5 class="text-2xl">All variables (local and inherited)</h5>
<vars v-if="allvariables.length" :variables="allvariables" :showparentpath="true"/> <vars v-if="allvariables.length" :variables="allvariables" :showparentpath="true" />
<span v-else>No variables</span> <span v-else>No variables</span>
</div> </div>
</template> </template>
@ -20,7 +20,15 @@ export default {
name: "projectvars", name: "projectvars",
props: { props: {
variables: Array, variables: Array,
allvariables: Array allvariables: Array,
type: String
},
computed: {
typetitle() {
if (this.type == "project") return "Project";
if (this.type == "projectgroup") return "Project group";
return "";
}
} }
}; };
</script> </script>

View File

@ -0,0 +1,30 @@
<template>
<div>
<div class="my-3 flex font-bold">
<div class="w-2/12">Name</div>
</div>
<div class="flex" v-for="secret in secrets" v-bind:key="secret.id">
<div class="w-2/12">
<span class="name">{{secret.name}}</span>
<div v-if="showparentpath" class="text-sm font-light">from {{secret.parent_path}}</div>
</div>
</div>
</div>
</template>
<script>
export default {
components: {},
name: "secrets",
props: {
secrets: Array,
showparentpath: Boolean
}
};
</script>
<style scoped lang="scss">
</style>

View File

@ -146,6 +146,21 @@ export async function fetchProject(ref) {
return await fetch(apiurl(path)); return await fetch(apiurl(path));
} }
export async function fetchSecrets(ownertype, ref, all) {
let path
if (ownertype == "project") {
path = "/projects/"
} else if (ownertype == "projectgroup") {
path = "/projectgroups/"
}
path += encodeURIComponent(ref);
path += "/secrets";
if (all) {
path += "?tree&removeoverridden";
}
return await fetch(apiurl(path));
}
export async function fetchVariables(ownertype, ref, all) { export async function fetchVariables(ownertype, ref, all) {
let path let path
if (ownertype == "project") { if (ownertype == "project") {