-
Notifications
You must be signed in to change notification settings - Fork 3
Add getWikiHostsForDomain endpoint #1001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5f13a86
Add endpoint for wiki host map
rosalieper 316b73e
Add the map config to the controller
rosalieper b4af51d
add test
rosalieper 46cea56
move the configuration to /config
rosalieper 4b4eb9c
Use MediaWikiHOstResolver for mapping
rosalieper 8ec6721
fix linting errors
rosalieper 5f58b90
fix linting errors
rosalieper 0e57f16
Change the endpoint path
rosalieper e2a5403
remove space
rosalieper b94d2d6
Add alpha host
rosalieper 6a3ce63
rename path to getWikiHostsForDomain and did some refactoring
rosalieper 527282e
fix linting
rosalieper 7a90ab3
Fix MediaWikiHostsControllerTest name and namespace
outdooracorn 6c7d2f5
Fix and refactor MediaWikiHostsControllerTest
outdooracorn d0eda48
Reorder methods in MediaWikiHostsControllerTest
outdooracorn 864792e
Rename method in MediaWikiHostsControllerTest
outdooracorn 87b3475
Update TODO comments in MediaWikiHostResolver
outdooracorn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers\Backend; | ||
|
|
||
| use App\Http\Controllers\Controller; | ||
| use App\Services\MediaWikiHostResolver; | ||
| use App\Services\UnknownDBVersionException; | ||
| use App\Services\UnknownWikiDomainException; | ||
| use Illuminate\Http\Request; | ||
|
|
||
| class MediaWikiHostController extends Controller { | ||
| public function getWikiHostForDomain(Request $request): \Illuminate\Http\JsonResponse { | ||
| $mediawikiHostResolver = new MediaWikiHostResolver; | ||
| $domain = $request->query('domain'); | ||
| try { | ||
| $backendHost = $mediawikiHostResolver->getBackendHostForDomain($domain); | ||
| $webHost = $mediawikiHostResolver->getWebHostForDomain($domain); | ||
| $apiHost = $mediawikiHostResolver->getApiHostForDomain($domain); | ||
| $alphaHost = $mediawikiHostResolver->getAlphaHostForDomain($domain); | ||
| } catch (UnknownWikiDomainException $e) { | ||
|
outdooracorn marked this conversation as resolved.
Outdated
|
||
| return response()->json(['error' => 'Domain not found.'], 404); | ||
| } catch (UnknownDBVersionException $e) { | ||
| return response()->json(['error' => 'Unknown database version.'], 500); | ||
| } | ||
|
|
||
| return response() | ||
| ->json([ | ||
| 'domain' => $domain, | ||
| 'backend-host' => $backendHost, | ||
| 'web-host' => $webHost, | ||
| 'api-host' => $apiHost, | ||
| 'alpha-host' => $alphaHost, | ||
| ]) | ||
| ->header('x-backend-host', $backendHost) | ||
| ->header('x-web-host', $webHost) | ||
| ->header('x-api-host', $apiHost) | ||
| ->header('x-alpha-host', $alphaHost); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| <?php | ||
|
|
||
| namespace Routes\Backend; | ||
|
|
||
| use App\Wiki; | ||
| use App\WikiDb; | ||
| use Illuminate\Foundation\Testing\RefreshDatabase; | ||
| use Tests\TestCase; | ||
|
|
||
| class MediaWikiHostControllerTest extends TestCase { | ||
| use RefreshDatabase; | ||
|
|
||
| private function createWiki(string $domain, string $version) { | ||
| $wiki = Wiki::factory()->create(['domain' => $domain]); | ||
| WikiDb::create([ | ||
| 'name' => $domain, | ||
| 'user' => 'someUser', | ||
| 'password' => 'somePassword', | ||
| 'version' => $version, | ||
| 'prefix' => 'somePrefix', | ||
| 'wiki_id' => $wiki->id, | ||
| ]); | ||
| } | ||
|
|
||
| public function testDomainNotfound() { | ||
| $this->getJson('/backend/getWikiHostForDomain?domain=notfound.wikibase.cloud') | ||
| ->assertStatus(404); | ||
| } | ||
|
|
||
| public function testDbVersionNotfound() { | ||
| $this->createWiki('noversion.wikibase.cloud', 'unknownVersion'); | ||
| $this->getJson('/backend/getWikiHostForDomain?domain=noversion.wikibase.cloud') | ||
| ->assertStatus(500); | ||
| } | ||
|
|
||
| public function testFoundHost() { | ||
| $expectedHosts = [ | ||
| 'backend' => 'mediawiki-143-app-backend.default.svc.cluster.local', | ||
| 'web' => 'mediawiki-143-app-web.default.svc.cluster.local', | ||
| 'api' => 'mediawiki-143-app-api.default.svc.cluster.local', | ||
| 'alpha' => 'mediawiki-143-app-alpha.default.svc.cluster.local', | ||
| ]; | ||
| $this->createWiki('found.wikibase.cloud', 'mw1.43-wbs1'); | ||
| $this->createWiki('other.wikibase.cloud', 'otherVersion'); | ||
| $this->getJson('/backend/getWikiHostForDomain?domain=found.wikibase.cloud') | ||
| ->assertStatus(200) | ||
| ->assertHeader('x-backend-host', $expectedHosts['backend']) | ||
| ->assertHeader('x-web-host', $expectedHosts['web']) | ||
| ->assertHeader('x-api-host', $expectedHosts['api']) | ||
| ->assertHeader('x-alpha-host', $expectedHosts['alpha']) | ||
| ->assertJson([ | ||
| 'backend-host' => $expectedHosts['backend'], | ||
| 'web-host' => $expectedHosts['web'], | ||
| 'api-host' => $expectedHosts['api'], | ||
| 'alpha-host' => $expectedHosts['alpha'], | ||
| 'domain' => 'found.wikibase.cloud', | ||
| ]); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.