Skip to content
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

fix(appname): encodeURIComponent for app name #8586

Merged
merged 16 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/scripts/modules/amazon/src/image/image.reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class AwsImageReader {
return $q.when([{ message: 'Please enter at least 3 characters...', disabled: true }]) as any;
}

return API.one('images/find')
return API.one('images', 'find')
.withParams(params)
.get()
.catch(() => [] as IAmazonImage[]);
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/modules/azure/src/image/image.reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const AZURE_IMAGE_IMAGE_READER = 'spinnaker.azure.image.reader';
export const name = AZURE_IMAGE_IMAGE_READER; // for backwards compatibility
module(AZURE_IMAGE_IMAGE_READER, []).factory('azureImageReader', function() {
function findImages(params) {
return API.one('images/find')
return API.one('images', 'find')
.get(params)
.then(
function(results) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ICloudFoundryCluster } from 'cloudfoundry/domain';

export class CloudFoundryImageReader {
public static findImages(account: string): IPromise<ICloudFoundryCluster[]> {
return API.one('images/find')
return API.one('images', 'find')
.withParams({
account,
provider: 'cloudfoundry',
Expand Down
6 changes: 6 additions & 0 deletions app/scripts/modules/core/src/api/ApiService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ describe('API Service', function() {
SETTINGS.gateUrl = 'http://localhost/////';
expect(API.baseUrl).toEqual('http://localhost');
});

it('encodes passed in URI components', function() {
const result = API.one('foo#bar');
expected.url = `${baseUrl}/foo%23bar`;
expect(result.config).toEqual(expected);
});
});

describe('validate response content-type header', function() {
Expand Down
9 changes: 5 additions & 4 deletions app/scripts/modules/core/src/api/ApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class API {
return (...urls: string[]) => {
urls.forEach((url: string) => {
if (url) {
config.url = `${config.url}/${url}`;
config.url = `${config.url}/${encodeURIComponent(url)}`;
}
});

Expand Down Expand Up @@ -170,9 +170,10 @@ export class API {
url: this.baseUrl,
};
urls
.filter(i => !isNil(i))
.forEach((url: string) => (config.url = `${config.url}/${url.toString().replace(/^\/+/, '')}`));

.filter((i) => !isNil(i))
.map((url: string) => url.toString().replace(/^\/+/, ''))
.map((url: string) => encodeURIComponent(url))
.forEach((url: string) => (config.url = `${config.url}/${url.toString()}`));
return this.baseReturn(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export interface IOnCall {

export class PagerDutyReader {
public static listServices(): Observable<IPagerDutyService[]> {
return Observable.fromPromise(API.one('pagerDuty/services').getList());
return Observable.fromPromise(API.one('pagerDuty', 'services').getList());
}

public static listOnCalls(): Observable<{ [id: string]: IOnCall[] }> {
return Observable.fromPromise(API.one('pagerDuty/oncalls').getList());
return Observable.fromPromise(API.one('pagerDuty', 'oncalls').getList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class PipelineConfigService {

public static deletePipeline(applicationName: string, pipeline: IPipeline, pipelineName: string): IPromise<void> {
return API.one(pipeline.strategy ? 'strategies' : 'pipelines')
.one(applicationName, encodeURIComponent(pipelineName.trim()))
.one(applicationName, pipelineName.trim())
.remove();
}

Expand Down Expand Up @@ -82,7 +82,7 @@ export class PipelineConfigService {
idsToIndices: { [key: string]: number },
isStrategy = false,
): IPromise<void> {
return API.one(`actions/${isStrategy ? 'strategies' : 'pipelines'}/reorder`)
return API.one('actions', `${isStrategy ? 'strategies' : 'pipelines'}`, 'reorder')
german-muzquiz marked this conversation as resolved.
Show resolved Hide resolved
.data({
application,
idsToIndices,
Expand All @@ -109,7 +109,7 @@ export class PipelineConfigService {
return API.one('pipelines')
.one('v2')
.one(applicationName)
.one(encodeURIComponent(pipelineName))
.one(pipelineName)
.data(body)
.post()
.then((result: ITriggerPipelineResponse) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class GremlinStageConfig extends React.Component<IStageConfigProps> {

private fetchCommands = (apiKey: string) => {
return Observable.fromPromise(
API.one('integrations/gremlin/templates/command')
API.one('integrations', 'gremlin', 'templates', 'command')
.post({
apiKey,
})
Expand All @@ -61,7 +61,7 @@ export class GremlinStageConfig extends React.Component<IStageConfigProps> {

private fetchTargets = (apiKey: string) => {
return Observable.fromPromise(
API.one('integrations/gremlin/templates/target')
API.one('integrations', 'gremlin', 'templates', 'target')
.post({
apiKey,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class ExecutionService {
execution.hydrated = true;
this.cleanExecutionForDiffing(execution);
if (application && name) {
return API.one('applications', application, 'pipelineConfigs', encodeURIComponent(name))
return API.one('applications', application, 'pipelineConfigs', name)
.get()
.then((pipelineConfig: IPipeline) => {
execution.pipelineConfig = pipelineConfig;
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/modules/core/src/plugins/plugin.registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class PluginRegistry {
public loadPluginManifestFromGate() {
const source = 'gate';
const uri = '/plugins/deck/plugin-manifest.json';
const loadPromise = API.one(uri)
const loadPromise = API.one(...uri.split('/').slice(1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API.one('plugins', 'deck', 'plugin-manifest.json');
?

.get()
.catch((error: any) => {
console.error(`Failed to load ${uri} from ${source}`);
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/modules/core/src/slack/SlackReader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('SlackReader', () => {
await SlackReader.getChannels().then((channels: ISlackChannel[]) => {
expect(SlackReader.getChannels).toHaveBeenCalled();
expect(channels.length).toEqual(2);
expect(API.one).toHaveBeenCalledWith('slack/channels');
expect(API.one).toHaveBeenCalledWith('slack', 'channels');
});
});
});
2 changes: 1 addition & 1 deletion app/scripts/modules/core/src/slack/SlackReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface ISlackChannel {

export class SlackReader {
public static getChannels(): IPromise<ISlackChannel[]> {
return API.one('slack/channels')
return API.one('slack', 'channels')
.getList()
.catch(() => [] as ISlackChannel[]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/modules/dcos/image/image.reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const DCOS_IMAGE_IMAGE_READER = 'spinnaker.dcos.image.reader';
export const name = DCOS_IMAGE_IMAGE_READER; // for backwards compatibility
module(DCOS_IMAGE_IMAGE_READER, []).factory('dcosImageReader', function() {
function findImages(params) {
return API.all('images/find')
return API.all('images', 'find')
.getList(params)
.then(
function(results) {
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/modules/docker/src/image/DockerImageReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DockerImageReader {

public static findImages(params: IFindImageParams): IPromise<IDockerImage[]> {
return RetryService.buildRetrySequence<IDockerImage[]>(
() => API.all('images/find').getList(params),
() => API.all('images', 'find').getList(params),
(results: IDockerImage[]) => results.length > 0,
10,
1000,
Expand All @@ -34,7 +34,7 @@ export class DockerImageReader {

public static findTags(params: IFindTagsParams): IPromise<string[]> {
return RetryService.buildRetrySequence<string[]>(
() => API.all('images/tags').getList(params),
() => API.all('images', 'tags').getList(params),
(results: string[]) => results.length > 0,
10,
1000,
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/modules/google/src/image/image.reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface IGceImage {

export class GceImageReader {
public static findImages(params: { account?: string; provider?: string; q?: string }): IPromise<IGceImage[]> {
return API.one('images/find')
return API.one('images', 'find')
.withParams(params)
.get()
.catch(() => [] as IGceImage[]);
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/modules/oracle/src/image/image.reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const ORACLE_IMAGE_IMAGE_READER = 'spinnaker.oracle.image.reader';
export const name = ORACLE_IMAGE_IMAGE_READER; // for backwards compatibility
module(ORACLE_IMAGE_IMAGE_READER, []).factory('oracleImageReader', function() {
function findImages(params) {
return API.one('images/find')
return API.one('images', 'find')
.withParams(params)
.get()
.catch(function() {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/modules/tencentcloud/src/image/image.reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TencentcloudImageReader {
return $q.when([{ message: 'Please enter at least 3 characters...', disabled: true }]) as any;
}

return API.one('images/find')
return API.one('images', 'find')
.withParams({ ...params, provider: 'tencentcloud' })
.get()
.catch(() => [] as ITencentcloudImage[]);
Expand Down