Skip to content

Commit

Permalink
Revert "NB-12 remove cyphertext field from graphql and reformat the c…
Browse files Browse the repository at this point in the history
…ode"

This reverts commit 35d69de.
  • Loading branch information
mjoshionemind committed Jul 10, 2024
1 parent 35d69de commit f97685a
Show file tree
Hide file tree
Showing 19 changed files with 440 additions and 773 deletions.
1 change: 1 addition & 0 deletions netbox_secrets/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CENSOR_MASTER_KEY = '********'
CENSOR_MASTER_KEY_CHANGED = '***CHANGED***'


#
# Session Keys
#
Expand Down
2 changes: 1 addition & 1 deletion netbox_secrets/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class UserKeyForm(forms.ModelForm):
),
label='Public Key (PEM format)',
help_text='Enter your public RSA key. Keep the private one with you; you will need it for decryption. Please '
'note that passphrase-protected keys are not supported.',
'note that passphrase-protected keys are not supported.',
)

class Meta:
Expand Down
4 changes: 2 additions & 2 deletions netbox_secrets/graphql/filters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import strawberry_django

from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin
from ..filtersets import *

from ..models import *
from ..filtersets import *

__all__ = [
'SecretFilter',
Expand Down
2 changes: 1 addition & 1 deletion netbox_secrets/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import strawberry
import strawberry_django

from .types import *
from ..models import *
from .types import *


@strawberry.type
Expand Down
5 changes: 3 additions & 2 deletions netbox_secrets/graphql/types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Annotated
from typing import Annotated, List

import strawberry
import strawberry_django

from netbox.graphql.types import NetBoxObjectType
from .filters import *
from ..models import *
from .filters import *

__all__ = [
'SecretRoleType',
Expand All @@ -24,4 +24,5 @@ class SecretRoleType(NetBoxObjectType):
class SecretType(NetBoxObjectType):
role: Annotated['SecretRoleType', strawberry.lazy('netbox_secrets.graphql.types')]
name: str
ciphertext: bool
description: str
2 changes: 1 addition & 1 deletion netbox_secrets/models/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def _unpad(self, s):
plaintext_length = (ord(s[0]) << 8) + ord(s[1])
else:
plaintext_length = (s[0] << 8) + s[1]
return s[2: plaintext_length + 2].decode('utf8')
return s[2 : plaintext_length + 2].decode('utf8')

def encrypt(self, secret_key):
"""
Expand Down
15 changes: 3 additions & 12 deletions netbox_secrets/project-static/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@
"arrowFunctions": true
}
},
"plugins": [
"@typescript-eslint",
"prettier"
],
"plugins": ["@typescript-eslint", "prettier"],
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [
".ts",
".tsx"
]
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {}
Expand All @@ -40,10 +34,7 @@
"@typescript-eslint/no-unused-vars": "off",
"no-unused-vars": "off",
"no-inner-declarations": "off",
"comma-dangle": [
"error",
"always-multiline"
],
"comma-dangle": ["error", "always-multiline"],
"global-require": "off",
"import/no-dynamic-require": "off",
"import/prefer-default-export": "off",
Expand Down
46 changes: 23 additions & 23 deletions netbox_secrets/project-static/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ const esbuild = require('esbuild');

// Bundler options common to all bundle jobs.
const options = {
outdir: './dist',
bundle: true,
minify: true,
sourcemap: true,
logLevel: 'error',
publicPath: '/static/netbox_secrets',
outdir: './dist',
bundle: true,
minify: true,
sourcemap: true,
logLevel: 'error',
publicPath: '/static/netbox_secrets',
};

/**
* Run script bundle jobs.
*/
async function bundleScripts() {
const entryPoints = {
secrets: 'src/index.ts',
};
try {
let result = await esbuild.build({
...options,
entryPoints,
target: 'es2016',
});
if (result.errors.length === 0) {
for (const [targetName, sourceName] of Object.entries(entryPoints)) {
const source = sourceName.split('/')[1];
console.log(`✅ Bundled source file '${source}' to '${targetName}.js'`);
}
}
} catch (err) {
console.error(err);
const entryPoints = {
secrets: 'src/index.ts',
};
try {
let result = await esbuild.build({
...options,
entryPoints,
target: 'es2016',
});
if (result.errors.length === 0) {
for (const [targetName, sourceName] of Object.entries(entryPoints)) {
const source = sourceName.split('/')[1];
console.log(`✅ Bundled source file '${source}' to '${targetName}.js'`);
}
}
} catch (err) {
console.error(err);
}
}

bundleScripts();
110 changes: 55 additions & 55 deletions netbox_secrets/project-static/src/bs.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
type ToastLevel = 'danger' | 'warning' | 'success' | 'info';

export function createToast(
level: ToastLevel,
title: string,
message: string,
extra?: string,
level: ToastLevel,
title: string,
message: string,
extra?: string,
): InstanceType<typeof window.Toast> {
let iconName = 'mdi-alert';
switch (level) {
case 'warning':
iconName = 'mdi-alert';
break;
case 'success':
iconName = 'mdi-check-circle';
break;
case 'info':
iconName = 'mdi-information';
break;
case 'danger':
iconName = 'mdi-alert';
break;
}
let iconName = 'mdi-alert';
switch (level) {
case 'warning':
iconName = 'mdi-alert';
break;
case 'success':
iconName = 'mdi-check-circle';
break;
case 'info':
iconName = 'mdi-information';
break;
case 'danger':
iconName = 'mdi-alert';
break;
}

const container = document.createElement('div');
container.setAttribute('class', 'toast-container position-fixed bottom-0 end-0 m-3');
const container = document.createElement('div');
container.setAttribute('class', 'toast-container position-fixed bottom-0 end-0 m-3');

const main = document.createElement('div');
main.setAttribute('class', `toast bg-${level}`);
main.setAttribute('role', 'alert');
main.setAttribute('aria-live', 'assertive');
main.setAttribute('aria-atomic', 'true');
const main = document.createElement('div');
main.setAttribute('class', `toast bg-${level}`);
main.setAttribute('role', 'alert');
main.setAttribute('aria-live', 'assertive');
main.setAttribute('aria-atomic', 'true');

const header = document.createElement('div');
header.setAttribute('class', `toast-header bg-${level} text-body`);
const header = document.createElement('div');
header.setAttribute('class', `toast-header bg-${level} text-body`);

const icon = document.createElement('i');
icon.setAttribute('class', `mdi ${iconName}`);
const icon = document.createElement('i');
icon.setAttribute('class', `mdi ${iconName}`);

const titleElement = document.createElement('strong');
titleElement.setAttribute('class', 'me-auto ms-1');
titleElement.innerText = title;
const titleElement = document.createElement('strong');
titleElement.setAttribute('class', 'me-auto ms-1');
titleElement.innerText = title;

const button = document.createElement('button');
button.setAttribute('type', 'button');
button.setAttribute('class', 'btn-close');
button.setAttribute('data-bs-dismiss', 'toast');
button.setAttribute('aria-label', 'Close');
const button = document.createElement('button');
button.setAttribute('type', 'button');
button.setAttribute('class', 'btn-close');
button.setAttribute('data-bs-dismiss', 'toast');
button.setAttribute('aria-label', 'Close');

const body = document.createElement('div');
body.setAttribute('class', 'toast-body');
const body = document.createElement('div');
body.setAttribute('class', 'toast-body');

header.appendChild(icon);
header.appendChild(titleElement);
header.appendChild(icon);
header.appendChild(titleElement);

if (typeof extra !== 'undefined') {
const extraElement = document.createElement('small');
extraElement.setAttribute('class', 'text-muted');
header.appendChild(extraElement);
}
if (typeof extra !== 'undefined') {
const extraElement = document.createElement('small');
extraElement.setAttribute('class', 'text-muted');
header.appendChild(extraElement);
}

header.appendChild(button);
header.appendChild(button);

body.innerText = message.trim();
body.innerText = message.trim();

main.appendChild(header);
main.appendChild(body);
container.appendChild(main);
document.body.appendChild(container);
main.appendChild(header);
main.appendChild(body);
container.appendChild(main);
document.body.appendChild(container);

const toast = new window.Toast(main);
return toast;
const toast = new window.Toast(main);
return toast;
}
22 changes: 11 additions & 11 deletions netbox_secrets/project-static/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ type JSONAble = Primitives | Primitives[] | { [k: string]: JSONAble } | JSONAble
* Base NetBox API Error.
*/
type ErrorBase = {
error: string;
error: string;
};

/**
* NetBox API error with details.
*/
type APIError = {
exception: string;
netbox_version: string;
python_version: string;
exception: string;
netbox_version: string;
python_version: string;
} & ErrorBase;

/**
* NetBox API Object.
*/
type APIObjectBase = {
id: number;
display: string;
name?: string | null;
url: string;
[k: string]: JSONAble;
id: number;
display: string;
name?: string | null;
url: string;
[k: string]: JSONAble;
};

interface Window {
Modal: typeof import('bootstrap').Modal;
Toast: typeof import('bootstrap').Toast;
Modal: typeof import('bootstrap').Modal;
Toast: typeof import('bootstrap').Toast;
}
6 changes: 3 additions & 3 deletions netbox_secrets/project-static/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {initSecrets} from './secrets';
import { initSecrets } from './secrets';

if (document.readyState !== 'loading') {
initSecrets();
initSecrets();
} else {
document.addEventListener('DOMContentLoaded', initSecrets);
document.addEventListener('DOMContentLoaded', initSecrets);
}
Loading

0 comments on commit f97685a

Please sign in to comment.