Skip to content

Commit

Permalink
fix(appname): encodeURIComponent for app name (#8586)
Browse files Browse the repository at this point in the history
* fix(appname): encodeURIComponent for app name

* fix(appname): encodeURIComponent in API

* fix(appname): Code format

* fix(appname): Code format

* fix(appname): Code format

* Update app/scripts/modules/core/src/pipeline/config/services/PipelineConfigService.ts

Co-authored-by: Chris Thielen <christopherthielen@users.noreply.github.com>

* fix(appname): Plugins url request

Co-authored-by: Chris Thielen <christopherthielen@users.noreply.github.com>
Co-authored-by: Kevin Woo <kevinawoo@gmail.com>
  • Loading branch information
3 people committed Oct 2, 2020
1 parent 2e0458b commit f1bb04e
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/scripts/modules/amazon/src/image/image.reader.ts
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
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
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
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
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
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());
}
}
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')
.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
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
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
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('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
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
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
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
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
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
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
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

0 comments on commit f1bb04e

Please sign in to comment.