Skip to content

Commit

Permalink
Merge pull request #569 from Ilhasoft/hotfix/grpc
Browse files Browse the repository at this point in the history
Hotfix/grpc
  • Loading branch information
dyohan9 committed Apr 26, 2021
2 parents c1a4a18 + 7b0883c commit c348ff3
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ before_script:
- python -m grpc_tools.protoc --experimental_allow_proto3_optional --proto_path=./ --python_out=./ --grpc_python_out=./ ./bothub/protos/authentication.proto
- python -m grpc_tools.protoc --experimental_allow_proto3_optional --proto_path=./ --python_out=./ --grpc_python_out=./ ./bothub/protos/organization.proto
- python -m grpc_tools.protoc --experimental_allow_proto3_optional --proto_path=./ --python_out=./ --grpc_python_out=./ ./bothub/protos/repository.proto
- python -m grpc_tools.protoc --experimental_allow_proto3_optional --proto_path=./ --python_out=./ --grpc_python_out=./ ./bothub/protos/project.proto

install:
- pip install pipenv
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ You can set environment variables in your OS, write on ```.env``` file or pass v
| OIDC_OP_JWKS_ENDPOINT | ```string``` | ```None``` | URL of your OpenID Connect provider JWKS endpoint.
| OIDC_RP_SIGN_ALGO | ```string``` | ```RS256``` | Sets the algorithm the IdP uses to sign ID tokens.
| OIDC_DRF_AUTH_BACKEND | ```string``` | ```bothub.authentication.authorization.WeniOIDCAuthenticationBackend``` | Define the authentication middleware for the django rest framework.
| CONNECT_GRPC_SERVER_URL | ```string``` | ```localhost:8002``` | Define grpc connect server url


## Roadmap
Expand Down
32 changes: 30 additions & 2 deletions bothub/api/grpc/organization/services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import grpc
from django.db import models
from django_grpc_framework import generics, mixins
from google.protobuf import empty_pb2

Expand All @@ -9,10 +10,18 @@
OrgUpdateProtoSerializer,
)
from bothub.authentication.models import User
from bothub.common.models import Organization, OrganizationAuthorization
from bothub.common.models import (
Organization,
OrganizationAuthorization,
RepositoryAuthorization,
Repository,
)
from bothub.protos.organization_pb2 import OrgStatistic


class OrgService(mixins.ListModelMixin, generics.GenericService):
class OrgService(
mixins.ListModelMixin, mixins.RetrieveModelMixin, generics.GenericService
):
def List(self, request, context):

user = utils.get_user(self, request.user_email)
Expand Down Expand Up @@ -65,3 +74,22 @@ def Update(self, request, context):
serializer.save()

return serializer.message

def Retrieve(self, request, context):
org = utils.get_organization(self, request.org_id)

auths = (
RepositoryAuthorization.objects.exclude(repository__owner=org)
.exclude(role=RepositoryAuthorization.ROLE_NOT_SETTED)
.filter(user=org)
)

response = {
"repositories_count": int(
Repository.objects.filter(
models.Q(uuid__in=auths) | models.Q(owner=org)
).count()
)
}

return OrgStatistic(**response)
2 changes: 1 addition & 1 deletion bothub/api/grpc/repository/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RepositoryService(mixins.ListModelMixin, generics.GenericService):
def filter_queryset(self, queryset):
org_id = self.request.org_id

queryset = queryset.filter(name=self.request.name)
queryset = queryset.filter(name__icontains=self.request.name)

if org_id:
queryset = queryset.filter(authorizations__user__pk=org_id)
Expand Down
10 changes: 9 additions & 1 deletion bothub/api/v2/account/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,19 @@ def validate_email(self, value):
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = RepositoryOwner
fields = ["nickname", "name", "locale", "is_organization", "biography"]
fields = [
"nickname",
"name",
"locale",
"is_organization",
"biography",
"language",
]
ref_name = None

is_organization = serializers.BooleanField(style={"show": False}, read_only=True)
biography = TextField(min_length=0, max_length=350, required=False)
language = serializers.CharField(read_only=True)


class ResetPasswordSerializer(serializers.ModelSerializer):
Expand Down
9 changes: 9 additions & 0 deletions bothub/protos/organization.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "google/protobuf/empty.proto";

service OrgController {
rpc List(OrgListRequest) returns (stream Org) {}
rpc Retrieve(OrgStatisticRetrieveRequest) returns (OrgStatistic) {}
rpc Create(OrgCreateRequest) returns (Org) {}
rpc Update(OrgUpdateRequest) returns (OrgUpdateRequest) {}
rpc Destroy(OrgDestroyRequest) returns (google.protobuf.Empty) {}
Expand Down Expand Up @@ -43,3 +44,11 @@ message OrgUpdateRequest {
int32 id = 1;
optional string name = 2;
}

message OrgStatisticRetrieveRequest {
int32 org_id = 1;
}

message OrgStatistic {
int32 repositories_count = 1;
}
5 changes: 5 additions & 0 deletions bothub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
DJANGO_REDIS_URL=(str, "redis://localhost:6379/1"),
OIDC_ENABLED=(bool, False),
SECRET_KEY_CHECK_LEGACY_USER=(str, None),
CONNECT_GRPC_SERVER_URL=(str, "localhost:8002"),
)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -477,3 +478,7 @@
"OIDC_DRF_AUTH_BACKEND",
default="bothub.authentication.authorization.WeniOIDCAuthenticationBackend",
)


# gRPC Connect Server
CONNECT_GRPC_SERVER_URL = env.str("CONNECT_GRPC_SERVER_URL")

0 comments on commit c348ff3

Please sign in to comment.