Skip to content

Commit

Permalink
Fixed up code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaddalena committed Jan 14, 2025
1 parent 69e1fa9 commit eb60bca
Show file tree
Hide file tree
Showing 27 changed files with 286 additions and 287 deletions.
6 changes: 3 additions & 3 deletions DOCS/coding-style-guide/form-layouts-and-design.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ If created correctly, the form can be added to a template with two lines:


```json
{% load crispy_forms_tags %}
{% crispy form form.helper %}
{% load crispy_forms_tags %}
{% crispy form form.helper %}
```
Read about Crispy's `FormHelper()` and `Layout()` objects:

<CardGroup cols={2}>
<Card title="GitHub - django-crispy-forms/django-crispy-forms:" icon="github" iconType="solid" href="https://github.com/django-crispy-forms/django-crispy-forms" />
<Card title="GitHub - django-crispy-forms/django-crispy-forms:" icon="github" iconType="solid" href="https://github.com/django-crispy-forms/django-crispy-forms" />
<Card title="Layouts — django-crispy-forms 1.11.1 documentation" icon="book" iconType="solid" href="https://django-crispy-forms.readthedocs.io/en/latest/layouts.html" />
</CardGroup>
## Creating a Form
Expand Down
109 changes: 54 additions & 55 deletions DOCS/coding-style-guide/style-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ Black is "opinionated" and automatically changes things to keep code consistent


```json

"editor.formatOnSave": true,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"90"
],
"editor.formatOnSave": true,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"90"
],
```
VSCode will now use Black to format all Python files on save actions.

Expand All @@ -44,8 +43,7 @@ VSCode will now use Black to format all Python files on save actions.
Black will not automatically delete trailing whitespace or whitespace on otherwise empty lines. Trailing whitespace will be identified by the linter (below). Add this line to VSCode's _settings.json_ file to automatically delete trailing whitespace on save:

```json

"files.trimTrailingWhitespace": true
"files.trimTrailingWhitespace": true
```
## Managing Imports

Expand All @@ -56,18 +54,18 @@ The Ghostwriter project also uses `Isort` which is part of the Python extensions
This tool sorts imports by library types (FUTURE, STDLIB, THIRDPARTY, FIRSTPARTY, LOCALFOLDER) and then alphabetically. It is customizable to generate comments and sort by line length. Ghostwriter code repository includes an _.isort.cfg_ file. Ghostwriter's current configuration contains:

```json

[settings]
profile=ghostwriter
src_paths=isort,test
atomic=True
line_length=90
use_parentheses=True
ensure_newline_before_comments=True
import_heading_stdlib=Standard Libraries
import_heading_firstparty=Ghostwriter Libraries
import_heading_thirdparty=Django & Other 3rd Party Libraries
[settings]
profile=ghostwriter
src_paths=isort,test
atomic=True
line_length=90
use_parentheses=True
ensure_newline_before_comments=True
import_heading_stdlib=Standard Libraries
import_heading_firstparty=Ghostwriter Libraries
import_heading_thirdparty=Django & Other 3rd Party Libraries
```

This configuration enforces the use of parentheses, adds newlines between sections, and keeps the line length /\<= 90 characters. It also adds custom comments before standard libraries, third-party libraries, and Ghostwriter's local first-party libraries.

Here is an example:
Expand Down Expand Up @@ -101,6 +99,7 @@ Here is an example:
ProjectObjective
)
```

Once the Python extension is installed, run `isort` by pressing SHIFT+CMD+P and selecting `Python Refactor: Sort Imports`.

## Line Length
Expand Down Expand Up @@ -150,6 +149,7 @@ A good view docstring looks like this:
:template:`rolodex/client_detail.html`
"""
```

Note the newline after the opening `"""` which deviates from standard practice (per PEP-8). Further, the use of grave accents, asterisks ( * ), and colons ( : ). are all purposeful and important. Django and `docutils` convert these symbols into formatting for the auto-generated documentation in the admin panel.

The above example is rendered like this:
Expand All @@ -168,22 +168,22 @@ Finally, docstrings should have newlines between sections and section headers. T
Setup VSCode snippets to create templates for repeated code snippets, like docstrings.

```json

"UpdateView Docstring": {
"prefix": "update",
"body": [
"\"\"\"",
"Update an individual :model:`${1:model}`.",
"",
"**Template**",
"",
":template:`${2:template}`",
"\"\"\"",
],
"description": "A docstring template for an UpdateView"
},
"UpdateView Docstring": {
"prefix": "update",
"body": [
"\"\"\"",
"Update an individual :model:`${1:model}`.",
"",
"**Template**",
"",
":template:`${2:template}`",
"\"\"\"",
],
"description": "A docstring template for an UpdateView"
},
```
</Check>

## Linting


Expand Down Expand Up @@ -219,25 +219,24 @@ Once the file is in place, run `pre-commit install` to hook future git commits.


```json
exclude: 'docs|node_modules|migrations|.git|.tox'
default_stages: [commit]
fail_fast: true
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: master
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
args: ['--config=setup.cfg']
additional_dependencies: [flake8-isort]

exclude: 'docs|node_modules|migrations|.git|.tox'
default_stages: [commit]
fail_fast: true
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: master
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
args: ['--config=setup.cfg']
additional_dependencies: [flake8-isort]
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Fill-in the configuration values in accordance with your API configuration. All

<CardGroup cols={1}> <Card title="Intro to API for Developers" icon="chevron-right" iconType="solid" href="https://www.namecheap.com/support/api/intro/" horizontal > <img src="/images/configuring-global-settings/configuring-apis/cdn/1138/assets/img/nc-icon/namecheap-icon-152x152.png" className="w-5 h-5 mr-2" alt="Logo" /> <span className="text-xs text-dark/7 dark:text-light/6">Namecheap.com</span> </Card> </CardGroup>


<Frame>
<img src="/images/configuring-global-settings/image-9.png" alt=""/>
</Frame>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Ghostwriter can use VirusTotal's API to look up domain names in your Domain Libr

The blocklist is maintained inside of the *review\.py* module:

```bash
```python Domain Blocklist
class DomainReview(object

« snip »
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,3 @@ The following sections walk you through what to do to prepare for a new release
5. Wait some time (usually \~25 minutes) and review the results of the GitHub Actions

6. If required Actions succeeded, the code may be merged and Ghostwriter team members will review the code prior to a release

[PreviousContributing to the Project](/development/contributing-to-the-project)[NextDatabase Models](/development/database-models)
2 changes: 1 addition & 1 deletion DOCS/development/expected-services-and-processes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If you would like to monitor or check the various processes and services running

Manually list processes with `docker-compose` and these commands:

```
```log
docker-compose -f local.yml top django
docker-compose -f local.yml top postgres
docker-compose -f local.yml top queue
Expand Down
5 changes: 3 additions & 2 deletions DOCS/development/modifying-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Most errors will be displayed in your web browser thanks to the verbose error ou

Of course, there will be no visible output in your browser if an error prevents Django from starting the server. To view logging output from Redis, PostgreSQL, and Django, use the Docker `logs` command:

```
```log
docker-compose -f local.yml logs
docker-compose -f local.yml logs django
docker-compose -f local.yml logs queue
Expand All @@ -41,6 +41,7 @@ docker-compose -f local.yml logs postgres
<Check>
Logs are handy for performing dry runs of scheduled tasks. Anything you \`print\` will be output to the logs.
</Check>

Add the name of the container after \`logs\` to get logs just from that service.

### Cleaning Up Containers
Expand All @@ -51,7 +52,7 @@ If you break something or want to start from scratch, stop all of your container
The following assumes only Ghostwriter container and volumes are present on your system. Proceed with caution if you use Docker for other things on your development system.
</Warning>

```
```log
docker system prune -a
docker volume rm -f $(docker volume ls)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Some of the variables influence the Docker builds. The majority of the variables

For example, the `DJANGO_SUPERUSER_PASSWORD` variable has the `DJANGO_` prefix to signify it is tied to the Django service and container. It is declared in the YAML files like this:

```
```yaml
- DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD}
```
Expand All @@ -35,14 +35,16 @@ You may need to do one additional thing if adding a new variable to the Django c

Add your new variable in the same manner as the other variables already in these files. Looking at `DJANGO_DATE_FORMAT` again, add the variable like this with `env()`:

```
```python
DATE_FORMAT = env(
"DJANGO_DATE_FORMAT",
default="d M Y"
)
```

<Check>
It's a good idea to provide a default value if your custom variable is missing from your DotEnv file.
</Check>

Finally, you can also modify Ghostwriter CLI to include your new variable. After building a new binary, you can set the value via Ghostwriter CLI's commands.

2 changes: 0 additions & 2 deletions DOCS/development/stack-overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,3 @@ Trying to move code updates to a production server can be messy when migrations
### Background Tasking — AQMP

Finally, Django Q and Redis handle automated queue management processing (AQMP). Ghostwriter automates a number of things like updating domain categorization data and DNS records. These tasks are handed off to Redis for background processing.

[PreviousCustom Layout Objects](/coding-style-guide/form-layouts-and-design/custom-layout-objects)[NextBehind the Scenes](/development/stack-overview/behind-the-scenes)
12 changes: 6 additions & 6 deletions DOCS/development/testing-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Tests are run through Django's _manage.py_ and the `test` command. You can run a
```
A successful run of all unit tests may still display errors. Many of the unit tests intentionally trigger errors by passing invalid data to the server. The logger output can be disabled but this is generally unnecessary. A successful run will output something like this at the end:

```json

----------------------------------------------------------------------
Ran 488 tests in 45.331s
```log
----------------------------------------------------------------------
Ran 488 tests in 45.331s
OK
Destroying test database for alias 'default'...
OK
Destroying test database for alias 'default'...
```

A test run with failures or errors will report the number of each at the end. Review the test output to see which test(s) failed to determine what needs to be fixed.

### Test Coverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ For example, you might make _1-sso-provider.py_ to hold your SSO configuration a
Your new config file must contain these settings at a minimum. We'll use Microsoft as an example for these steps.


```json
# Provider(s) configuration
SOCIALACCOUNT_PROVIDERS = {
"microsoft": {
"APP": {
"client_id": "CLIENT ID",
"secret": "SECRET",
}
},
}
# Extend the installed apps with the SSO app for your provider(s)
SSO_PROVIDERS = ["allauth.socialaccount.providers.microsoft"]
INSTALLED_APPS = INSTALLED_APPS + SSO_PROVIDERS
```python SSO Provider Config
# Provider(s) configuration
SOCIALACCOUNT_PROVIDERS = {
"microsoft": {
"APP": {
"client_id": "CLIENT ID",
"secret": "SECRET",
}
},
}
# Extend the installed apps with the SSO app for your provider(s)
SSO_PROVIDERS = ["allauth.socialaccount.providers.microsoft"]
INSTALLED_APPS = INSTALLED_APPS + SSO_PROVIDERS
```

The above lines add our provider (Microsoft for this example) to Ghostwriter's installed apps and provide the information necessary for the SSO handshake. You can find the values you need for your provider(s) at the above link.
Expand Down Expand Up @@ -63,34 +63,36 @@ Set `DJANGO_SOCIAL_ACCOUNT_DOMAIN_ALLOWLIST` with Ghostwriter CLI or `SOCIAL_ACC

Here is what this might look like in your config file:

```json
# Enable or disable registration
SOCIAL_ACCOUNT_ALLOW_REGISTRATION = True
# Allow only these email domains
SOCIAL_ACCOUNT_DOMAIN_ALLOWLIST = ["specterops.io"]
```python SSO Domain Allowlist
# Enable or disable registration
SOCIAL_ACCOUNT_ALLOW_REGISTRATION = True
# Allow only these email domains
SOCIAL_ACCOUNT_DOMAIN_ALLOWLIST = ["specterops.io"]
```

These settings allow registration via an SSO provider, but only if the account's email address has the _specterops.io_ domain.

If a local account with a matching email address already exists, the user will be prompted to enter a different address for their new account. This will most likely arise when transitioning from local accounts to a new SSO provider. You will probably want to link the accounts in these cases.

<Note>
An error is raised if multiple existing accounts share the same email address. Rather than trying to connect one of them, the user will see a message encouraging them to contact an administrator.
</Note>
You can link accounts by enabling your provider to authenticate via the account's email address. By default, email authentication is disabled, and the provider must have pre-verified the email address. Use the following settings if you trust the provider and want to consider email addresses as verified.

You can link accounts by enabling your provider to authenticate via the account's email address. By default, email authentication is disabled, and the provider must have pre-verified the email address. Use the following settings if you trust the provider and want to consider email addresses as verified.

```json
SOCIALACCOUNT_PROVIDERS = {
"microsoft": {
"APP": {
"client_id": "",
"secret": "",
},
"EMAIL_AUTHENTICATION": True,
"VERIFIED_EMAIL": True,
```python SSO Email Authentication
SOCIALACCOUNT_PROVIDERS = {
"microsoft": {
"APP": {
"client_id": "",
"secret": "",
},
}
"EMAIL_AUTHENTICATION": True,
"VERIFIED_EMAIL": True,
},
}
```

These settings enable Microsoft email authentication and consider all email addresses verified for automatic connection.

If someone were to authenticate with a Microsoft account, they would only be allowed to create or link an account if registration is enabled and the domain allowlist checks passed. If either check fails, the user will be redirected to a page like this.
Expand All @@ -105,4 +107,4 @@ Depending on your SSO provider, you may need to consider other configuration opt

If you wish to have users log in immediately when they click the provider button, set `DJANGO_SOCIAL_ACCOUNT_LOGIN_ON_GET` to `true` with Ghostwriter CLI. For information is available here:

[Configuration - django-allauth](https://docs.allauth.org/en/latest/socialaccount/configuration.html)
<CardGroup cols={1}> <Card title="Provider Configuration" icon="chevron-right" iconType="solid" href="https://docs.allauth.org/en/latest/socialaccount/configuration.html" horizontal > <span className="text-xs text-dark/7 dark:text-light/6">docs.allauth.org</span> </Card> </CardGroup>
Loading

0 comments on commit eb60bca

Please sign in to comment.