Skip to content

Commit

Permalink
include protocol in toString methods of both TCP and UDP implementati…
Browse files Browse the repository at this point in the history
…ons of IPortRange
  • Loading branch information
ChintanRaval committed Oct 3, 2018
1 parent a4918e7 commit d072dc4
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions packages/@aws-cdk/aws-ec2/lib/security-group-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,21 @@ export enum Protocol {
*/
export class TcpPort implements IPortRange {
public readonly canInlineRule = true;
private readonly protocol = Protocol.Tcp;

constructor(private readonly port: number) {
}

public toRuleJSON(): any {
return {
ipProtocol: Protocol.Tcp,
ipProtocol: this.protocol,
fromPort: this.port,
toPort: this.port
};
}

public toString() {
return `${this.port}`;
return `${this.protocol} ${this.port}`;
}
}

Expand All @@ -175,20 +176,21 @@ export class TcpPort implements IPortRange {
*/
export class TcpPortFromAttribute implements IPortRange {
public readonly canInlineRule = false;
private readonly protocol = Protocol.Tcp;

constructor(private readonly port: string) {
}

public toRuleJSON(): any {
return {
ipProtocol: Protocol.Tcp,
ipProtocol: this.protocol,
fromPort: this.port,
toPort: this.port
};
}

public toString() {
return '{IndirectPort}';
return `${this.protocol} {IndirectPort}`;
}
}

Expand All @@ -197,20 +199,21 @@ export class TcpPortFromAttribute implements IPortRange {
*/
export class TcpPortRange implements IPortRange {
public readonly canInlineRule = true;
private readonly protocol = Protocol.Tcp;

constructor(private readonly startPort: number, private readonly endPort: number) {
}

public toRuleJSON(): any {
return {
ipProtocol: Protocol.Tcp,
ipProtocol: this.protocol,
fromPort: this.startPort,
toPort: this.endPort
};
}

public toString() {
return `${this.startPort}-${this.endPort}`;
return `${this.protocol} ${this.startPort}-${this.endPort}`;
}
}

Expand All @@ -219,17 +222,18 @@ export class TcpPortRange implements IPortRange {
*/
export class TcpAllPorts implements IPortRange {
public readonly canInlineRule = true;
private readonly protocol = Protocol.Tcp;

public toRuleJSON(): any {
return {
ipProtocol: Protocol.Tcp,
ipProtocol: this.protocol,
fromPort: 0,
toPort: 65535
};
}

public toString() {
return 'ALL PORTS';
return `${this.protocol} ALL PORTS`;
}
}

Expand All @@ -238,20 +242,21 @@ export class TcpAllPorts implements IPortRange {
*/
export class UdpPort implements IPortRange {
public readonly canInlineRule = true;
private readonly protocol = Protocol.Udp;

constructor(private readonly port: number) {
}

public toRuleJSON(): any {
return {
ipProtocol: Protocol.Udp,
ipProtocol: this.protocol,
fromPort: this.port,
toPort: this.port
};
}

public toString() {
return `UDP ${this.port}`;
return `${this.protocol} ${this.port}`;
}
}

Expand All @@ -260,20 +265,21 @@ export class UdpPort implements IPortRange {
*/
export class UdpPortFromAttribute implements IPortRange {
public readonly canInlineRule = false;
private readonly protocol = Protocol.Udp;

constructor(private readonly port: string) {
}

public toRuleJSON(): any {
return {
ipProtocol: Protocol.Udp,
ipProtocol: this.protocol,
fromPort: this.port,
toPort: this.port
};
}

public toString() {
return '{IndirectPort}';
return `${this.protocol} {IndirectPort}`;
}
}

Expand All @@ -282,20 +288,21 @@ export class UdpPortFromAttribute implements IPortRange {
*/
export class UdpPortRange implements IPortRange {
public readonly canInlineRule = true;
private readonly protocol = Protocol.Udp;

constructor(private readonly startPort: number, private readonly endPort: number) {
}

public toRuleJSON(): any {
return {
ipProtocol: Protocol.Udp,
ipProtocol: this.protocol,
fromPort: this.startPort,
toPort: this.endPort
};
}

public toString() {
return `UDP ${this.startPort}-${this.endPort}`;
return `${this.protocol} ${this.startPort}-${this.endPort}`;
}
}

Expand All @@ -304,17 +311,18 @@ export class UdpPortRange implements IPortRange {
*/
export class UdpAllPorts implements IPortRange {
public readonly canInlineRule = true;
private readonly protocol = Protocol.Udp;

public toRuleJSON(): any {
return {
ipProtocol: Protocol.Udp,
ipProtocol: this.protocol,
fromPort: 0,
toPort: 65535
};
}

public toString() {
return 'UDP ALL PORTS';
return `${this.protocol} ALL PORTS`;
}
}

Expand All @@ -323,10 +331,11 @@ export class UdpAllPorts implements IPortRange {
*/
export class AllConnections implements IPortRange {
public readonly canInlineRule = true;
private readonly protocol = Protocol.All;

public toRuleJSON(): any {
return {
ipProtocol: '-1',
ipProtocol: this.protocol,
fromPort: -1,
toPort: -1,
};
Expand Down

0 comments on commit d072dc4

Please sign in to comment.