Skip to content

Commit

Permalink
Merge pull request #345 from AmpersandTarski/bug/344-fix-link-to-stud…
Browse files Browse the repository at this point in the history
…ent-prototype

Moved username cleaning out of k8s.
  • Loading branch information
KlaasDijkstraOrdina committed Jan 4, 2024
2 parents 2f83ea4 + e7744d1 commit a596a34
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions RAP4/customizations/bootstrap/files/ExecEngineFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@
$scriptContent = $scriptContentPairs[0]->tgt()->getId();
$scriptContentForCommandline = base64_encode($scriptContent);

$pattern = '/[\W+]/';

$userName=strtolower($userName);
$userName = preg_replace($pattern, '-', $userName);

$deployment = getenv('RAP_DEPLOYMENT');
if ($deployment == 'Kubernetes') {
/** Deployed on Kubernetes Cluster
Expand All @@ -320,24 +325,19 @@
* - run kubectl apply -f "student-manifest-{{student}}.yaml"
*/

$pattern = '/[\W+]/';

$studentName=strtolower($userName);
$studentName = preg_replace($pattern, '-', $studentName);

$namespace=getenv('RAP_KUBERNETES_NAMESPACE');
$containerImage=getenv('RAP_STUDENT_PROTO_IMAGE');

$hostname=getenv('RAP_HOST_NAME');
$hostname="{$studentName}.{$hostname}";
$hostname="{$userName}.{$hostname}";

$suffix=substr($namespace, 3);

$dbName="rap-db{$suffix}";

$dbSecret="db-secrets{$suffix}";

$tlsSecret="{$studentName}-tls{$suffix}";
$tlsSecret="{$userName}-tls{$suffix}";

// Location to save files
$relDir = pathinfo($path, PATHINFO_DIRNAME);
Expand All @@ -350,7 +350,7 @@
throw new Exception("Student manifest template not found for '{$scriptVersionAtom}', workDir: {$workDir}, manifestFile: {$manifestFile}", 500);
}
// replace {{student}}, {{namespace}} and {{scriptContent}}
$manifest=str_replace("{{student}}", $studentName, $manifest);
$manifest=str_replace("{{student}}", $userName, $manifest);
$manifest=str_replace("{{namespace}}", $namespace, $manifest);
$manifest=str_replace("{{containerImage}}", $containerImage, $manifest);
$manifest=str_replace("{{scriptContent}}", $scriptContentForCommandline, $manifest);
Expand All @@ -360,7 +360,7 @@
$manifest=str_replace("{{tlsSecret}}", $tlsSecret, $manifest);

// Save manifest file
$studentManifestFile="{$workDir}/student-manifest-{$studentName}.yaml";
$studentManifestFile="{$workDir}/student-manifest-{$userName}.yaml";
file_put_contents($studentManifestFile, $manifest);

// Call Kubernetes API to add script
Expand Down

0 comments on commit a596a34

Please sign in to comment.