Skip to content

Commit

Permalink
Lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Feb 20, 2024
1 parent b6be403 commit cd57527
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 39 deletions.
8 changes: 7 additions & 1 deletion dnas/trusted/zomes/coordinator/trusted/src/gpg_key_dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ pub fn distribute_gpg_key(request: DistributeGpgKeyRequest) -> ExternResult<Reco
// Just a point in time check, somebody could distribute this key using other code or we might just not have seen it yet.
// While this isn't an integrity guarantee, it might help out a somebody who is trying to distribute a key and hasn't realised they're using a different agent key than
// they originally distributed the key with.
let other_has_key = get_links(GetLinksInputBuilder::try_new(make_base_hash(summary.fingerprint.clone())?, LinkTypes::FingerprintToGpgKeyDist)?.build())?;
let other_has_key = get_links(
GetLinksInputBuilder::try_new(
make_base_hash(summary.fingerprint.clone())?,
LinkTypes::FingerprintToGpgKeyDist,
)?
.build(),
)?;
if !other_has_key.is_empty() {
return Err(wasm_error!(WasmErrorInner::Guest(
"This key has already been distributed by somebody else".to_string()
Expand Down
26 changes: 12 additions & 14 deletions ui/src/component/GpgFingerprint.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
<script setup lang="ts">
import { computed } from 'vue';
import { computed } from "vue";
const props = defineProps<{
fingerprint: string
fingerprint: string;
}>();
// There's nothing particularly special about this format but it's the same as the GPG CLI prints and
// it's what people are used to looking at for GPG keys. Hopefully that means its a little easier to
// 40 characters grouped together.
const fingerprintDisplay = computed(() => {
// It's a 160 bit hash, so 20 bytes, in hex is 40 characters
if (!props.fingerprint || props.fingerprint.length != 40) return '';
// It's a 160 bit hash, so 20 bytes, in hex is 40 characters
if (!props.fingerprint || props.fingerprint.length != 40) return "";
let repr = '';
for (let i = 0; i < 40; i += 4) {
repr += props.fingerprint.slice(i, i + 4) + ' ';
let repr = "";
for (let i = 0; i < 40; i += 4) {
repr += props.fingerprint.slice(i, i + 4) + " ";
if (i === 20) repr += ' ';
}
if (i === 20) repr += " ";
}
return repr.trim();
return repr.trim();
});
</script>

<template>
<span>{{ fingerprintDisplay }}</span>
</template>
<span>{{ fingerprintDisplay }}</span>
</template>
22 changes: 17 additions & 5 deletions ui/src/component/KeyList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,28 @@ const copyFingerprint = (keyDist: GpgKeyDist) => {
</tr>
</thead>
<tbody>
<tr v-for="k in keys" v-bind:key="k.fingerprint">
<tr v-for="k in keys" v-bind:key="k.fingerprint" v-memo="[k.fingerprint]">
<td>{{ k.name }}</td>
<td>{{ k.email ?? "-" }}</td>
<td>{{ k.expires_at ? formatDistanceToNow(k.expires_at) : "-" }}</td>

<td class="cursor-pointer font-mono" @click="copyFingerprint(k)">
<GpgFingerprint :fingerprint="k.fingerprint" v-memo="[k.fingerprint]" />
<span :class="{ 'ms-2': true, 'text-success': copied === k.fingerprint }">
<font-awesome-icon v-if="copied === k.fingerprint" icon="fa-regular fa-check-circle" size="lg" fixed-width />
<font-awesome-icon v-else icon="fa-regular fa-clipboard" size="lg" fixed-width />
<GpgFingerprint :fingerprint="k.fingerprint" />
<span
:class="{ 'ms-2': true, 'text-success': copied === k.fingerprint }"
>
<font-awesome-icon
v-if="copied === k.fingerprint"
icon="fa-regular fa-check-circle"
size="lg"
fixed-width
/>
<font-awesome-icon
v-else
icon="fa-regular fa-clipboard"
size="lg"
fixed-width
/>
</span>
</td>
<td v-if="!readonly">
Expand Down
13 changes: 8 additions & 5 deletions ui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import "./style.css";
import App from "./App.vue";
import { createPinia } from "pinia";

import { library } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faClipboard, faCheckCircle } from '@fortawesome/free-regular-svg-icons'
library.add(faClipboard, faCheckCircle)
import { library } from "@fortawesome/fontawesome-svg-core";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import {
faClipboard,
faCheckCircle,
} from "@fortawesome/free-regular-svg-icons";
library.add(faClipboard, faCheckCircle);

const pinia = createPinia();
const app = createApp(App);

app.component('font-awesome-icon', FontAwesomeIcon)
app.component("font-awesome-icon", FontAwesomeIcon);
app.use(pinia);
app.mount("#app");
56 changes: 44 additions & 12 deletions ui/src/trusted/trusted/DistributeGpgKey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const notifications = useNotificationsStore();
const selected = ref<Partial<GpgKeyDist>>({});
const creating = ref(false);
const inputType = ref<'file' | 'paste'>('file');
const inputType = ref<"file" | "paste">("file");
const fileInputField = ref<HTMLElement | null>(null);
const textAreaInputField = ref<HTMLElement | null>(null);
Expand Down Expand Up @@ -83,10 +83,12 @@ const onPublicKeySelect = async (event: Event) => {
};
const onPublicKeyPaste = async (event: Event) => {
if (event.type === 'paste') {
const value = (event as ClipboardEvent).clipboardData?.getData('text/plain');
if (event.type === "paste") {
const value = (event as ClipboardEvent).clipboardData?.getData(
"text/plain",
);
if (!value) return;
handleNewKeyProvided(value);
} else {
if (!event.target) return;
Expand Down Expand Up @@ -148,16 +150,38 @@ const distributeGpgKey = async () => {

<div class="flex justify-center">
<div role="tablist" class="tabs tabs-boxed w-1/2">
<a role="tab" :class="{ tab: true, 'tab-active': inputType === 'file' }" @click="inputType = 'file'">Select file</a>
<a role="tab" :class="{ tab: true, 'tab-active': inputType === 'paste' }" @click="inputType = 'paste'">Paste</a>
<a
role="tab"
:class="{ tab: true, 'tab-active': inputType === 'file' }"
@click="inputType = 'file'"
>Select file</a
>
<a
role="tab"
:class="{ tab: true, 'tab-active': inputType === 'paste' }"
@click="inputType = 'paste'"
>Paste</a
>
</div>
</div>

<div class="flex justify-center my-3">
<input v-if="inputType === 'file'" type="file" accept="text/*,.asc" @change="onPublicKeySelect" ref="fileInputField"
class="file-input file-input-bordered file-input-primary" />
<textarea v-else class="textarea textarea-ghost w-1/2" placeholder="Paste your GPG public key here"
@change="onPublicKeyPaste" @paste="onPublicKeyPaste" ref="textAreaInputField"></textarea>
<input
v-if="inputType === 'file'"
type="file"
accept="text/*,.asc"
@change="onPublicKeySelect"
ref="fileInputField"
class="file-input file-input-bordered file-input-primary"
/>
<textarea
v-else
class="textarea textarea-ghost w-1/2"
placeholder="Paste your GPG public key here"
@change="onPublicKeyPaste"
@paste="onPublicKeyPaste"
ref="textAreaInputField"
></textarea>
</div>

<div v-if="selected.fingerprint" class="mt-5">
Expand All @@ -168,13 +192,21 @@ const distributeGpgKey = async () => {

<div class="flex justify-end my-3">
<div class="join">
<button class="btn btn-primary join-item" :disabled="!isGpgKeyValid || creating" @click="distributeGpgKey">
<button
class="btn btn-primary join-item"
:disabled="!isGpgKeyValid || creating"
@click="distributeGpgKey"
>
<span v-if="creating" class="loading loading-spinner"></span>
<span v-else>{{
creating ? "Creating..." : "Distribute Gpg Key"
}}</span>
</button>
<button class="btn btn-secondary join-item" :disabled="!selected.fingerprint" @click="resetForm">
<button
class="btn btn-secondary join-item"
:disabled="!selected.fingerprint"
@click="resetForm"
>
Cancel
</button>
</div>
Expand Down
7 changes: 5 additions & 2 deletions ui/src/trusted/trusted/KeyCollections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ const keyCollectionsStore = useKeyCollectionsStore();

<template>
<p class="text-lg">My Key Collections</p>

<div v-if="keyCollectionsStore.keyCollections.length === 0" class="ms-5 italic">

<div
v-if="keyCollectionsStore.keyCollections.length === 0"
class="ms-5 italic"
>
<p>You don't have any key collections yet.</p>
<!-- TODO I want to link to the search screen here but I need the router for that -->
<p>When you add a key you will be able to create a collection for it!</p>
Expand Down

0 comments on commit cd57527

Please sign in to comment.