Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ extend-exclude = [

[tool.ruff.lint]
# This section is managed by the plugin template. Do not edit manually.
select = ["E4", "E7", "E9", "F"]
extend-select = [
"I",
"INT",
Expand Down
10 changes: 5 additions & 5 deletions staging_docs/admin/guides/authentication/01-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ passwords against. By default it is set to:

```python
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend', # Django's users, groups, and permissions
'pulpcore.backends.ObjectRolePermissionBackend' # Pulp's RBAC object and model permissions
"django.contrib.auth.backends.ModelBackend", # Django's users, groups, and permissions
"pulpcore.backends.ObjectRolePermissionBackend", # Pulp's RBAC object and model permissions
]
```

Expand All @@ -31,9 +31,9 @@ Django Rest Framework defines the source usernames and passwords come from with

```python
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication', # Session Auth
'rest_framework.authentication.BasicAuthentication' # Basic Auth
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.SessionAuthentication", # Session Auth
"rest_framework.authentication.BasicAuthentication", # Basic Auth
]
}
```
Expand Down
6 changes: 3 additions & 3 deletions staging_docs/admin/guides/authentication/03-webserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Specify how to receive the username from the webserver. Do this by specifying to
`DEFAULT_AUTHENTICATION_CLASSES`. For example, consider this example:

```python
REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'] = (
'rest_framework.authentication.SessionAuthentication',
'pulpcore.app.authentication.PulpRemoteUserAuthentication'
REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"] = (
"rest_framework.authentication.SessionAuthentication",
"pulpcore.app.authentication.PulpRemoteUserAuthentication",
)
```

Expand Down
18 changes: 9 additions & 9 deletions staging_docs/admin/guides/authentication/04-keycloak.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ Define the authentication pipeline for data that will be associated with users:

```python title="settings.py"
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
"social_core.pipeline.social_auth.social_details",
"social_core.pipeline.social_auth.social_uid",
"social_core.pipeline.social_auth.social_user",
"social_core.pipeline.user.get_username",
"social_core.pipeline.social_auth.associate_by_email",
"social_core.pipeline.user.create_user",
"social_core.pipeline.social_auth.associate_user",
"social_core.pipeline.social_auth.load_extra_data",
"social_core.pipeline.user.user_details",
)
```

Expand Down
4 changes: 2 additions & 2 deletions staging_docs/admin/learn/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ The following code snippet can be used to generate a random SECRET_KEY.
```python linenums="1"
import random

chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
print(''.join(random.choice(chars) for i in range(50)))
chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
print("".join(random.choice(chars) for i in range(50)))
```

### DB_ENCRYPTION_KEY
Expand Down
17 changes: 9 additions & 8 deletions staging_docs/dev/learn/architecture/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ This is what the ViewSet should look like:
class RepositoryViewSet(viewsets.ModelViewSet):
queryset = models.Repository.objects.all()
serializer_class = serializers.RepositorySerializer
filterset_fields = ('name',)
filterset_fields = ("name",)
```

#### FilterSet
Expand All @@ -303,7 +303,8 @@ class RepositoryFilter(filters.FilterSet):

class Meta:
model = models.Repository
fields = ['name']
fields = ["name"]


class RepositoryViewSet(viewsets.ModelViewSet):
queryset = models.Repository.objects.all()
Expand All @@ -328,11 +329,11 @@ Simply define any filters in the `FilterSet` and then include them in `fields` i

```python
class RepositoryFilter(filters.FilterSet):
name_contains = django_filters.filters.CharFilter(field_name='name', lookup_expr='contains')
name_contains = django_filters.filters.CharFilter(field_name="name", lookup_expr="contains")

class Meta:
model = models.Repository
fields = ['name_contains']
fields = ["name_contains"]
```

#### Custom Filters
Expand All @@ -348,16 +349,16 @@ http 'http://192.168.121.134:24817/pulp/api/v3/repositories/?name_in_list=singin
```

```python
class CharInFilter(django_filters.filters.BaseInFilter,
django_filters.filters.CharFilter):
class CharInFilter(django_filters.filters.BaseInFilter, django_filters.filters.CharFilter):
pass


class RepositoryFilter(filters.FilterSet):
name_in_list = CharInFilter(name='name', lookup_expr='in')
name_in_list = CharInFilter(name="name", lookup_expr="in")

class Meta:
model = models.Repository
fields = ['name_in_list']
fields = ["name_in_list"]
```

!!! note
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ See the code below for an example:
```python
from pulpcore.plugin.util import get_domain_pk


class FileContent(Content):
...
_pulp_domain = models.ForeignKey("core.Domain", default=get_domain_pk, on_delete=models.PROTECT)
Expand Down Expand Up @@ -59,6 +60,7 @@ from pulpcore.plugin.models import Task
from pulpcore.plugin.util import get_domain
from .models import CustomModel


def custom_task(custom_property):
# How to get the current domain for this task
domain = Task.current().pulp_domain
Expand Down
20 changes: 7 additions & 13 deletions staging_docs/dev/learn/triage-needed!/concepts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ temp_file.save()

# Example 2 - Validating the digest and saving a temporary file:
temp_file = PulpTemporaryFile.init_and_validate(
my_file, expected_digests={'md5': '912ec803b2ce49e4a541068d495ab570'}
my_file, expected_digests={"md5": "912ec803b2ce49e4a541068d495ab570"}
)
temp_file.save()

Expand Down Expand Up @@ -259,18 +259,15 @@ GroupProgressReport needs to be updated.
task_group = TaskGroup(description="Migration Sub-tasks")
task_group.save()
group_pr = GroupProgressReport(
message="Repo migration",
code="create.repo_version",
total=1,
done=0,
task_group=task_group)
message="Repo migration", code="create.repo_version", total=1, done=0, task_group=task_group
)
group_pr.save()
# When a task that will be executing certain work, which is part of a TaskGroup, it will look
# for the TaskGroup it belongs to and find appropriate progress report by its code and will
# update it accordingly.
task_group = TaskGroup.current()
progress_repo = task_group.group_progress_reports.filter(code='create.repo_version')
progress_repo.update(done=F('done') + 1)
progress_repo = task_group.group_progress_reports.filter(code="create.repo_version")
progress_repo.update(done=F("done") + 1)
# To avoid race conditions/cache invalidation issues, this pattern needs to be used so that
# operations are performed directly inside the database:

Expand Down Expand Up @@ -369,13 +366,10 @@ below so `dynaconf` can run your plugin's validators. See [dynaconf validator do
```python
from dynaconf import Validator


def post(settings):
"""This hook is called by dynaconf after the settings are completely loaded"""
settings.validators.register(
Validator(...),
Validator(...),
...
)
settings.validators.register(Validator(...), Validator(...), ...)
settings.validators.validate()
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ To enable automatic permission creation for an object managed by an AccessPolicy
use the `pulpcore.plugin.models.AutoAddObjPermsMixin`. See the example below as an example:

```python
class MyModel(BaseModel, AutoAddObjPermsMixin):
...
class MyModel(BaseModel, AutoAddObjPermsMixin): ...
```

See the docstring below for more information on this mixin.
Expand Down Expand Up @@ -124,13 +123,13 @@ the `function` are method names on the Model that need to be registered with

```python
class MyModel(BaseModel, AutoAddObjPermsMixin):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.REGISTERED_CREATION_HOOKS["my_custom_callable"] = self.my_custom_callable

def my_custom_callable(self, role, users, groups):
from pulpcore.app.util import assign_role

for user in users:
assign_role(role, user, self) # self is the object being assigned
for group in groups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,11 @@ Here's an example of adding a permission like this for `FileRepository`:

```python
class FileRepository(Repository):

...

class Meta:
...
permissions = (
('modify_repo_content', 'Modify Repository Content'),
)
permissions = (("modify_repo_content", "Modify Repository Content"),)
```

!!! note
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ parameters can also be accepted by supplying them in a `parameters` section of t
from pulpcore.plugin.viewsets import NamedModelViewSet
from pulpcore.plugin.util import get_objects_for_user

class MyViewSet(NamedModelViewSet):

class MyViewSet(NamedModelViewSet):
DEFAULT_ACCESS_POLICY = {
# Statements omitted
"queryset_scoping" : {
"queryset_scoping": {
# This entire field is editable by the user
"function": "different_permission_scope",
"parameters": {"permission": "my.example_permission"}
"parameters": {"permission": "my.example_permission"},
}
}

Expand All @@ -100,8 +100,8 @@ provided by pulpcore. Here's an example:
```python
from pulpcore.plugin.util import get_objects_for_user

class MyViewSet(rest_framework.viewsets.GenericViewSet):

class MyViewSet(rest_framework.viewsets.GenericViewSet):
def get_queryset(self):
qs = super().get_queryset()
permission_name = "my.example_permission"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class FileContent(Content):
Fields:
digest (str): The SHA256 HEX digest.
"""
TYPE = 'file'

TYPE = "file"
digest = models.TextField(null=False)

class Meta:
Expand Down Expand Up @@ -75,13 +76,13 @@ class FileContent(Content):
digest (str): The SHA256 HEX digest.
"""

TYPE = 'file'
TYPE = "file"

digest = models.TextField(null=False)

class Meta:
# Note the comma, this must be a tuple.
unique_together = ('digest',)
unique_together = ("digest",)
default_related_name = "%(app_label)s_%(model_name)s"
```

Expand All @@ -99,16 +100,16 @@ class FileContent(Content):
digest (str): The SHA256 HEX digest.
"""

TYPE = 'file'
TYPE = "file"

relative_path = models.TextField(null=False)
digest = models.TextField(null=False)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = (
'relative_path',
'digest',
"relative_path",
"digest",
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ class FileContentSerializer(SingleArtifactContentSerializer):
help_text="Relative location of the file within the repository"
)


class Meta:
fields = SingleArtifactContentSerializer.Meta.fields + ('relative_path',)
model = FileContent
fields = SingleArtifactContentSerializer.Meta.fields + ("relative_path",)
model = FileContent
```

### Help Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ For example, a ContentViewSet for `app_label` "foobar" like this:

```python
class PackageViewSet(ContentViewSet):
endpoint_name = 'packages'
endpoint_name = "packages"
```

The above example will create set of CRUD endpoints for Packages at
Expand All @@ -37,9 +37,9 @@ In addition to the CRUD endpoints, a Viewset can also add a custom endpoint. For

```python
class PackageViewSet(ContentViewSet):
endpoint_name = 'packages'
endpoint_name = "packages"

@decorators.detail_route(methods=('get',))
@decorators.detail_route(methods=("get",))
def hello(self, request):
return Response("Hey!")
```
Expand Down Expand Up @@ -68,30 +68,26 @@ a task.

```python
# We recommend using POST for any endpoints that kick off task.
@detail_route(methods=('post',), serializer_class=RepositorySyncURLSerializer)
@detail_route(methods=("post",), serializer_class=RepositorySyncURLSerializer)
# `pk` is a part of the URL
def sync(self, request, pk):
"""
Synchronizes a repository.
The ``repository`` field has to be provided.
"""
remote = self.get_object()
serializer = RepositorySyncURLSerializer(data=request.data, context={'request': request})
serializer = RepositorySyncURLSerializer(data=request.data, context={"request": request})
# This is how non-crud validation is accomplished
serializer.is_valid(raise_exception=True)
repository = serializer.validated_data.get('repository')
mirror = serializer.validated_data.get('mirror', False)
repository = serializer.validated_data.get("repository")
mirror = serializer.validated_data.get("mirror", False)

# This is how tasks are kicked off.
result = dispatch(
tasks.synchronize,
exclusive_resources=[repository],
shared_resources=[remote],
kwargs={
'remote_pk': remote.pk,
'repository_pk': repository.pk,
'mirror': mirror
}
kwargs={"remote_pk": remote.pk, "repository_pk": repository.pk, "mirror": mirror},
)
# Since tasks are asynchronous, we return a 202
return OperationPostponedResponse(result, request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ working directory setup, and database cleanup after encountering failures.

```python
with repository.new_version() as new_version:

# add content manually
new_version.add_content(content)
new_version.remove_content(content)
# add content manually
new_version.add_content(content)
new_version.remove_content(content)
```

!!! warning
Expand Down
Loading
Loading