From e3662c82ae6613d251c60ac34f37d5091bd62e3b Mon Sep 17 00:00:00 2001
From: Oz Okun <112382001+Oz-Okun@users.noreply.github.com>
Date: Thu, 8 Jun 2023 10:48:26 +0200
Subject: [PATCH] Add public option to documentation
---
action.yml | 4 +-
.../Models/CustomTransformer.cs | 61 +++++++++----------
docs/deploying-site/README.md | 19 +++++-
docs/deploying-site/action.md | 7 +++
4 files changed, 54 insertions(+), 37 deletions(-)
diff --git a/action.yml b/action.yml
index ae521f3..82160ed 100644
--- a/action.yml
+++ b/action.yml
@@ -97,6 +97,4 @@ runs:
- name: Upload files to azure storage
shell: bash
run: |
- curl --request POST --header "Authorization: Bearer ${{steps.token.outputs.token}}" --header 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36' --form Docs=@vuepress/docs/.vuepress/dist/Docs.zip "https://developer.bcc.no/UploadDoc?isPublic=${{inputs.public}}"
-
-
+ curl --request POST --header "Authorization: Bearer ${{steps.token.outputs.token}}" --header 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36' --form Docs=@vuepress/docs/.vuepress/dist/Docs.zip "https://developer.bcc.no/UploadDoc?isPublic=${{inputs.public}}"
\ No newline at end of file
diff --git a/auth-proxy/backend/documentation-site/Models/CustomTransformer.cs b/auth-proxy/backend/documentation-site/Models/CustomTransformer.cs
index 60a2263..871f225 100644
--- a/auth-proxy/backend/documentation-site/Models/CustomTransformer.cs
+++ b/auth-proxy/backend/documentation-site/Models/CustomTransformer.cs
@@ -85,54 +85,51 @@ public override async ValueTask TransformRequestAsync(HttpContext httpContext,Ht
}
#endregion
- if (containerName != "bcc-core-api")
- {
- #region authenticate user access
- var usersInRepo = await getmembers.GetUsersInRepo("", containerName); //Gets the cached list of users who have access to the repository
+ #region authenticate user access
+ var usersInRepo = await getmembers.GetUsersInRepo("", containerName); //Gets the cached list of users who have access to the repository
- //Checks if repository members exsists in the cache
- if (usersInRepo.IsNullOrEmpty())
- {
+ //Checks if repository members exsists in the cache
+ if (usersInRepo.IsNullOrEmpty())
+ {
- string gitToken = await getmembers.GetTokenFromAzurePem(); //Calling this method to get github token using the azure vault pem file
+ string gitToken = await getmembers.GetTokenFromAzurePem(); //Calling this method to get github token using the azure vault pem file
- var users = await getmembers.GetUsersInRepo(gitToken, containerName); //Calling method to retrive users who have access to the repo
+ var users = await getmembers.GetUsersInRepo(gitToken, containerName); //Calling method to retrive users who have access to the repo
- //Checks if repo is not public (if list contains the element "404", repo is public) or Public file within container exists
- if (!(users.Contains(404)) && !(await token.IsPublic(containerName)))
+ //Checks if repo is not public (if list contains the element "404", repo is public) or Public file within container exists
+ if (!(users.Contains(404)) && !(await token.IsPublic(containerName)))
+ {
+ //If the list is an empty list the repository doesnt exsists
+ if (users.IsNullOrEmpty())
{
- //If the list is an empty list the repository doesnt exsists
- if (users.IsNullOrEmpty())
+ httpContext.Response.StatusCode = 403;
+ return;
+ }
+ //Returns if the current logged user exsists whitin the list of allowed people
+ else
+ {
+ if (!users.Contains(int.Parse(httpContext.Request.Headers["X-MS-CLIENT-PRINCIPAL-ID"])))
{
httpContext.Response.StatusCode = 403;
return;
}
- //Returns if the current logged user exsists whitin the list of allowed people
- else
- {
- if (!users.Contains(int.Parse(httpContext.Request.Headers["X-MS-CLIENT-PRINCIPAL-ID"])))
- {
- httpContext.Response.StatusCode = 403;
- return;
- }
- }
}
}
- else
+ }
+ else
+ {
+ //Checks if cached repo is public or not
+ if (!usersInRepo.Contains(404) && !(await token.IsPublic(containerName)))
{
- //Checks if cached repo is public or not
- if (!usersInRepo.Contains(404) && !(await token.IsPublic(containerName)))
+ //Checks if user exsists in the cached repo
+ if (!usersInRepo.Contains(int.Parse(httpContext.Request.Headers["X-MS-CLIENT-PRINCIPAL-ID"])))
{
- //Checks if user exsists in the cached repo
- if (!usersInRepo.Contains(int.Parse(httpContext.Request.Headers["X-MS-CLIENT-PRINCIPAL-ID"])))
- {
- httpContext.Response.StatusCode = 403;
- return;
- }
+ httpContext.Response.StatusCode = 403;
+ return;
}
}
- #endregion
}
+ #endregion
}
#region SubPath check
diff --git a/docs/deploying-site/README.md b/docs/deploying-site/README.md
index 6ad2ad9..150ffcc 100644
--- a/docs/deploying-site/README.md
+++ b/docs/deploying-site/README.md
@@ -43,7 +43,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Build documentation site
- uses: bcc-code/bcc-documentation-base@v2
+ uses: bcc-code/bcc-documentation-base@v3
with:
title: FILL IN
description: FILL IN
@@ -59,7 +59,7 @@ It is possible to use a different folder than `docs` for documentation. This can
```yml
steps:
- name: Build documentation site
- uses: bcc-code/bcc-documentation-base@v1
+ uses: bcc-code/bcc-documentation-base@v3
with:
...
docs-dir: documentation
@@ -73,3 +73,18 @@ on:
paths:
- documentation/**
```
+
+#### Make documentation publicly available
+For private repositories by default, the documentation is only visible to github members who are apart of the bcc-code organization or the collaborators of the repository.
+But if you want your documentation to be accessiable to **anyone** with a github account, than it can be configured using the `public` option in the action:
+```yml
+steps:
+ - name: Build documentation site
+ uses: bcc-code/bcc-documentation-base@v3
+ with:
+ ...
+ public: true
+```
+::: warning
+Be sure you are using **v3** or later of the action.
+:::
\ No newline at end of file
diff --git a/docs/deploying-site/action.md b/docs/deploying-site/action.md
index 0ca3397..81b70a6 100644
--- a/docs/deploying-site/action.md
+++ b/docs/deploying-site/action.md
@@ -66,3 +66,10 @@ The directory from where Vue components should automatically be registered
Type: `string`
Default: `src/components`
+
+### public
+Wheter or not the documentation will be publicly available or not (works only for private repositories)
+
+Type: `bool`
+
+Default: `false`
\ No newline at end of file