| @@ 88-110 (lines=23) @@ | ||
| 85 | // GET /config/common_names/:commonName get a particular CN |
|
| 86 | $service->get( |
|
| 87 | '/config/common_names/:commonName', |
|
| 88 | function (Request $request, TokenInfo $tokenInfo, $commonName) { |
|
| 89 | Utils::requireScope($tokenInfo, ['admin']); |
|
| 90 | InputValidation::commonName($commonName); |
|
| 91 | ||
| 92 | $fileName = sprintf('%s/%s', $this->configDir, $commonName); |
|
| 93 | if (!$this->io->isFile($fileName)) { |
|
| 94 | // if the file does not exist, use default values |
|
| 95 | $cnConfig = new CnConfig([]); |
|
| 96 | } else { |
|
| 97 | $cnConfig = new CnConfig( |
|
| 98 | Json::decode( |
|
| 99 | $this->io->readFile( |
|
| 100 | sprintf('%s/%s', $this->configDir, $commonName) |
|
| 101 | ) |
|
| 102 | ) |
|
| 103 | ); |
|
| 104 | } |
|
| 105 | ||
| 106 | $response = new JsonResponse(); |
|
| 107 | $response->setBody($cnConfig->toArray()); |
|
| 108 | ||
| 109 | return $response; |
|
| 110 | } |
|
| 111 | ); |
|
| 112 | ||
| 113 | // PUT /config/common_names/:commonName set new config for CN |
|
| @@ 78-102 (lines=25) @@ | ||
| 75 | ||
| 76 | $service->get( |
|
| 77 | '/config/users/:userId', |
|
| 78 | function (Request $request, TokenInfo $tokenInfo, $userId) { |
|
| 79 | Utils::requireScope($tokenInfo, ['admin', 'portal']); |
|
| 80 | InputValidation::userId($userId); |
|
| 81 | ||
| 82 | $fileName = sprintf('%s/%s', $this->configDir, $userId); |
|
| 83 | if (!$this->io->isFile($fileName)) { |
|
| 84 | // if the file does not exist, use default values |
|
| 85 | $userConfig = new UserConfig([]); |
|
| 86 | } else { |
|
| 87 | $userConfig = new UserConfig( |
|
| 88 | Json::decode( |
|
| 89 | $this->io->readFile( |
|
| 90 | sprintf('%s/%s', $this->configDir, $userId) |
|
| 91 | ) |
|
| 92 | ) |
|
| 93 | ); |
|
| 94 | // never expose the OTP secret |
|
| 95 | $userConfig->hideOtpSecret(); |
|
| 96 | } |
|
| 97 | ||
| 98 | $response = new JsonResponse(); |
|
| 99 | $response->setBody($userConfig->toArray()); |
|
| 100 | ||
| 101 | return $response; |
|
| 102 | } |
|
| 103 | ); |
|
| 104 | ||
| 105 | $service->put( |
|