-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Migrate url shortener service #50896
Merged
Merged
Changes from 38 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
4624fa9
started migrating share
flash1293 0043259
continued migrating share
flash1293 7d373fb
Merge remote-tracking branch 'upstream/master' into migrate-share-reg…
flash1293 3627fad
continued migrating share
flash1293 0a93622
clean up and test
flash1293 f2e14e2
Merge remote-tracking branch 'upstream/master' into migrate-share-reg…
flash1293 8eb4743
review fixes
flash1293 f48be82
fix i18ns
flash1293 7a5c509
fix missing i18n
flash1293 40c4d71
Merge remote-tracking branch 'upstream/master' into migrate-share-reg…
flash1293 e2e9015
rename things
flash1293 540c00b
add back stylings
flash1293 6f3f802
add karma mocks
flash1293 af106e0
Merge remote-tracking branch 'upstream/master' into migrate-share-reg…
flash1293 f8add37
Merge remote-tracking branch 'upstream/master' into migrate-share-reg…
flash1293 1a69978
fix css and add to migration doc
flash1293 5164a5d
started moving url shortener to the new platform
flash1293 bbad895
fix types for typescript 3.7
flash1293 f1b0ecf
continued working on shimming shorten url service
flash1293 76a55c6
Merge remote-tracking branch 'upstream/master' into migrate-share-reg…
flash1293 5f5358c
fix snapshots
flash1293 6a751b7
Merge remote-tracking branch 'upstream/master' into migrate/url-short…
flash1293 46a0610
move over most of the share plugin
flash1293 b622b64
remove core plugin share
flash1293 b7ff865
Merge branch 'migrate-share-registry' into migrate/url-shortener
flash1293 2b86160
Merge remote-tracking branch 'upstream/master' into migrate/url-short…
flash1293 f0fb280
Merge remote-tracking branch 'upstream/master' into migrate/url-short…
flash1293 242773c
Merge remote-tracking branch 'upstream/master' into migrate/url-short…
flash1293 968cad1
Merge branch 'master' into migrate/url-shortener
elasticmachine bbc441c
Merge remote-tracking branch 'upstream/master' into migrate/url-short…
flash1293 44c4c9c
fix error handling
flash1293 71ecee0
Merge branch 'migrate/url-shortener' of github.com:flash1293/kibana i…
flash1293 cd2afab
switch to boom wrapper
flash1293 8e045a9
remove debug statement and fix codeowners
flash1293 cf2b6a9
remove optional setting
flash1293 9df3cc4
Merge remote-tracking branch 'upstream/master' into migrate/url-short…
flash1293 7cd578b
fix functional test
flash1293 a01881f
Merge remote-tracking branch 'upstream/master' into migrate/url-short…
flash1293 b39a22b
Merge remote-tracking branch 'upstream/master' into migrate/url-short…
flash1293 0a12908
remove unnecessary goto
flash1293 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
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"id": "share", | ||
"version": "kibana", | ||
"server": false, | ||
"server": true, | ||
"ui": true | ||
} |
This file contains 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 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,37 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { CoreSetup, Plugin, PluginInitializerContext } from 'kibana/server'; | ||
import { createRoutes } from './routes/create_routes'; | ||
|
||
export class SharePlugin implements Plugin { | ||
constructor(private readonly initializerContext: PluginInitializerContext) {} | ||
|
||
public async setup(core: CoreSetup) { | ||
createRoutes(core, this.initializerContext.logger.get()); | ||
} | ||
|
||
public start() { | ||
this.initializerContext.logger.get().debug('Starting plugin'); | ||
} | ||
|
||
public stop() { | ||
this.initializerContext.logger.get().debug('Stopping plugin'); | ||
} | ||
} |
This file contains 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,32 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { CoreSetup, Logger } from 'kibana/server'; | ||
|
||
import { shortUrlLookupProvider } from './lib/short_url_lookup'; | ||
import { createGotoRoute } from './goto'; | ||
import { createShortenUrlRoute } from './shorten_url'; | ||
|
||
export function createRoutes({ http }: CoreSetup, logger: Logger) { | ||
const shortUrlLookup = shortUrlLookupProvider({ logger }); | ||
const router = http.createRouter(); | ||
|
||
createGotoRoute({ router, shortUrlLookup, http }); | ||
createShortenUrlRoute({ router, shortUrlLookup }); | ||
} |
This file contains 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,65 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { CoreSetup, IRouter } from 'kibana/server'; | ||
import { schema } from '@kbn/config-schema'; | ||
|
||
import { shortUrlAssertValid } from './lib/short_url_assert_valid'; | ||
import { ShortUrlLookupService } from './lib/short_url_lookup'; | ||
|
||
export const createGotoRoute = ({ | ||
router, | ||
shortUrlLookup, | ||
http, | ||
}: { | ||
router: IRouter; | ||
shortUrlLookup: ShortUrlLookupService; | ||
http: CoreSetup['http']; | ||
}) => { | ||
router.get( | ||
{ | ||
path: '/goto/{urlId}', | ||
validate: { | ||
params: schema.object({ urlId: schema.string() }), | ||
}, | ||
}, | ||
router.handleLegacyErrors(async function(context, request, response) { | ||
const url = await shortUrlLookup.getUrl(request.params.urlId, { | ||
savedObjects: context.core.savedObjects.client, | ||
}); | ||
shortUrlAssertValid(url); | ||
|
||
const uiSettings = context.core.uiSettings.client; | ||
const stateStoreInSessionStorage = await uiSettings.get('state:storeInSessionStorage'); | ||
if (!stateStoreInSessionStorage) { | ||
return response.redirected({ | ||
headers: { | ||
location: http.basePath.prepend(url), | ||
}, | ||
}); | ||
} else { | ||
flash1293 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return response.redirected({ | ||
headers: { | ||
location: http.basePath.prepend('/goto_LP/' + request.params.urlId), | ||
}, | ||
}); | ||
} | ||
}) | ||
); | ||
}; |
63 changes: 63 additions & 0 deletions
63
src/plugins/share/server/routes/lib/short_url_assert_valid.test.ts
This file contains 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,63 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { shortUrlAssertValid } from './short_url_assert_valid'; | ||
|
||
describe('shortUrlAssertValid()', () => { | ||
const invalid = [ | ||
['protocol', 'http://localhost:5601/app/kibana'], | ||
['protocol', 'https://localhost:5601/app/kibana'], | ||
['protocol', 'mailto:[email protected]'], | ||
['protocol', 'javascript:alert("hi")'], // eslint-disable-line no-script-url | ||
['hostname', 'localhost/app/kibana'], | ||
['hostname and port', 'local.host:5601/app/kibana'], | ||
['hostname and auth', 'user:[email protected]/app/kibana'], | ||
['path traversal', '/app/../../not-kibana'], | ||
['deep path', '/app/kibana/foo'], | ||
['deep path', '/app/kibana/foo/bar'], | ||
['base path', '/base/app/kibana'], | ||
]; | ||
|
||
invalid.forEach(([desc, url]) => { | ||
it(`fails when url has ${desc}`, () => { | ||
try { | ||
shortUrlAssertValid(url); | ||
throw new Error(`expected assertion to throw`); | ||
} catch (err) { | ||
if (!err || !err.isBoom) { | ||
throw err; | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
const valid = [ | ||
'/app/kibana', | ||
'/app/monitoring#angular/route', | ||
'/app/text#document-id', | ||
'/app/some?with=query', | ||
'/app/some?with=query#and-a-hash', | ||
]; | ||
|
||
valid.forEach(url => { | ||
it(`allows ${url}`, () => { | ||
shortUrlAssertValid(url); | ||
}); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the plugin contains server part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this means the platform should pick up the
server
directory for server side code. This PR moved the url shortener into theshare
plugin whereas before it was only a client side thing (handling the share registry)