move protocol selection to environment variable

This commit is contained in:
Bryan Gerlach
2025-02-01 13:42:03 -06:00
parent a322fae5f0
commit dfa0845c53
4 changed files with 24 additions and 17 deletions

View File

@@ -7,6 +7,8 @@ services:
GHUSER: "github_username" GHUSER: "github_username"
GHBEARER: "github_access_token" GHBEARER: "github_access_token"
GENURL: "accessible_url_of_server" GENURL: "accessible_url_of_server"
PROTOCOL: "https"
REPONAME: "rdgen"
ports: ports:
- "8000:8000" - "8000:8000"
dns: dns:

View File

@@ -24,6 +24,8 @@ SECRET_KEY = os.environ.get('SECRET_KEY','django-insecure-!(t-!f#6g#sr%yfded9(xh
GHUSER = os.environ.get("GHUSER", '') GHUSER = os.environ.get("GHUSER", '')
GHBEARER = os.environ.get("GHBEARER", '') GHBEARER = os.environ.get("GHBEARER", '')
GENURL = os.environ.get("GENURL", '') GENURL = os.environ.get("GENURL", '')
PROTOCOL = os.environ.get("PROTOCOL", 'https')
REPONAME = os.environ.get("REPONAME", 'rdgen')
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

View File

@@ -72,7 +72,7 @@ def generator_view(request):
filename = re.sub(r'[^\w\s-]', '_', filename).strip() filename = re.sub(r'[^\w\s-]', '_', filename).strip()
myuuid = str(uuid.uuid4()) myuuid = str(uuid.uuid4())
protocol = 'https' protocol = _settings.PROTOCOL
host = request.get_host() host = request.get_host()
full_url = f"{protocol}://{host}" full_url = f"{protocol}://{host}"
try: try:
@@ -170,37 +170,37 @@ def generator_view(request):
####from here run the github action, we need user, repo, access token. ####from here run the github action, we need user, repo, access token.
if platform == 'windows': if platform == 'windows':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/generator-windows.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/generator-windows.yml/dispatches'
elif platform == 'linux': elif platform == 'linux':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/generator-linux.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/generator-linux.yml/dispatches'
elif platform == 'android': elif platform == 'android':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/generator-android.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/generator-android.yml/dispatches'
elif platform == 'macos': elif platform == 'macos':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/generator-macos.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/generator-macos.yml/dispatches'
else: else:
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/generator-windows.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/generator-windows.yml/dispatches'
####changes were made to use hbb_common as a submodule in version 1.3.7, so if 1.3.3 through 1.3.6, use: ####changes were made to use hbb_common as a submodule in version 1.3.7, so if 1.3.3 through 1.3.6, use:
if version == '1.3.3' or version == '1.3.4' or version == '1.3.5' or version == '1.3.6': if version == '1.3.3' or version == '1.3.4' or version == '1.3.5' or version == '1.3.6':
if platform == 'windows': if platform == 'windows':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/pre137-generator-windows.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/pre137-generator-windows.yml/dispatches'
elif platform == 'linux': elif platform == 'linux':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/pre137-generator-linux.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/pre137-generator-linux.yml/dispatches'
elif platform == 'android': elif platform == 'android':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/pre137-generator-android.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/pre137-generator-android.yml/dispatches'
elif platform == 'macos': elif platform == 'macos':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/pre137-generator-macos.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/pre137-generator-macos.yml/dispatches'
else: else:
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/pre137-generator-windows.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/pre137-generator-windows.yml/dispatches'
####breaking changes were made in 1.3.3 version, so if 1.3.2 or lower, use: ####breaking changes were made in 1.3.3 version, so if 1.3.2 or lower, use:
if version == '1.3.2' or version == '1.3.1' or version == '1.3.0': if version == '1.3.2' or version == '1.3.1' or version == '1.3.0':
if platform == 'windows': if platform == 'windows':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/pre133-generator-windows.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/pre133-generator-windows.yml/dispatches'
elif platform == 'linux': elif platform == 'linux':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/pre133-generator-linux.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/pre133-generator-linux.yml/dispatches'
elif platform == 'android': elif platform == 'android':
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/pre133-generator-android.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/pre133-generator-android.yml/dispatches'
else: else:
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/pre133-generator-windows.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/pre133-generator-windows.yml/dispatches'
#url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rustdesk/actions/workflows/test.yml/dispatches' #url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rustdesk/actions/workflows/test.yml/dispatches'
data = { data = {
@@ -336,7 +336,7 @@ def startgh(request):
#print(request) #print(request)
data_ = json.loads(request.body) data_ = json.loads(request.body)
####from here run the github action, we need user, repo, access token. ####from here run the github action, we need user, repo, access token.
url = 'https://api.github.com/repos/'+_settings.GHUSER+'/rdgen/actions/workflows/generator-'+data_.get('platform')+'.yml/dispatches' url = 'https://api.github.com/repos/'+_settings.GHUSER+'/'+_settings.REPONAME+'/actions/workflows/generator-'+data_.get('platform')+'.yml/dispatches'
data = { data = {
"ref":"master", "ref":"master",
"inputs":{ "inputs":{

View File

@@ -13,10 +13,13 @@
* under Repository access, select Only select repositories, then pick your * under Repository access, select Only select repositories, then pick your
rdgen repo rdgen repo
* give Read and Write access to actions and workflows * give Read and Write access to actions and workflows
* You might have to go to: https://github.com/USERNAME/rdgen/actions and hit green Enable Actions button so it works.
3. Setup environment variables/secrets: 3. Setup environment variables/secrets:
* environment variables on the server running rdgen: * environment variables on the server running rdgen:
* GHUSER="your github username" * GHUSER="your github username"
* GHBEARER="your fine-grained access token" * GHBEARER="your fine-grained access token"
* PROTOCOL="https" *optional - defaults to "https", change to "http" if you need to
* REPONAME="rdgen" *optional - defaults to "rdgen", change this if you renamed the repo when you forked it
* github secrets (setup on your github account for your rdgen repo): * github secrets (setup on your github account for your rdgen repo):
* GENURL="example.com:8000" *this is the domain and port that you are * GENURL="example.com:8000" *this is the domain and port that you are
running rdgen on, needs to be accessible on the internet, depending running rdgen on, needs to be accessible on the internet, depending
@@ -25,7 +28,7 @@
* WINDOWS_PFX_BASE64 * WINDOWS_PFX_BASE64
* WINDOWS_PFX_PASSWORD * WINDOWS_PFX_PASSWORD
* WINDOWS_PFX_SHA1_THUMBPRINT * WINDOWS_PFX_SHA1_THUMBPRINT
* You might have to go to: https://github.com/USERNAME/rdgen/actions and hit green Enable Actions button so it works.
## A few notes: ## A few notes: