-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate protocol version on connector update (#18639)
* Add helper class to check protocol version range * Check ProtocolVersion when modifying a destination definition * Check ProtocolVersion when modifying a source definition * Format * Add UnsupportedProtocolVersion exception * Rewrite AirbyteProtocolVersionRange as a record * Format * Rename exception
- Loading branch information
Showing
7 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
airbyte-commons/src/main/java/io/airbyte/commons/version/AirbyteProtocolVersionRange.java
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,18 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.commons.version; | ||
|
||
public record AirbyteProtocolVersionRange(Version min, Version max) { | ||
|
||
public boolean isSupported(final Version v) { | ||
final Integer major = getMajor(v); | ||
return getMajor(min) <= major && major <= getMajor(max); | ||
} | ||
|
||
private Integer getMajor(final Version v) { | ||
return Integer.valueOf(v.getMajorVersion()); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...yte-commons/src/test/java/io/airbyte/commons/version/AirbyteProtocolVersionRangeTest.java
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,40 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.commons.version; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class AirbyteProtocolVersionRangeTest { | ||
|
||
@Test | ||
void checkRanges() { | ||
final AirbyteProtocolVersionRange range = new AirbyteProtocolVersionRange(new Version("1.2.3"), new Version("4.3.2")); | ||
assertTrue(range.isSupported(new Version("2.0.0"))); | ||
assertTrue(range.isSupported(new Version("1.2.3"))); | ||
assertTrue(range.isSupported(new Version("4.3.2"))); | ||
|
||
// We should only be requiring major to be within range | ||
assertTrue(range.isSupported(new Version("1.0.0"))); | ||
assertTrue(range.isSupported(new Version("4.4.0"))); | ||
|
||
assertFalse(range.isSupported(new Version("0.2.3"))); | ||
assertFalse(range.isSupported(new Version("5.0.0"))); | ||
} | ||
|
||
@Test | ||
void checkRangeWithOnlyOneMajor() { | ||
final AirbyteProtocolVersionRange range = new AirbyteProtocolVersionRange(new Version("2.0.0"), new Version("2.1.2")); | ||
|
||
assertTrue(range.isSupported(new Version("2.0.0"))); | ||
assertTrue(range.isSupported(new Version("2.5.0"))); | ||
|
||
assertFalse(range.isSupported(new Version("1.0.0"))); | ||
assertFalse(range.isSupported(new Version("3.0.0"))); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...te-server/src/main/java/io/airbyte/server/errors/UnsupportedProtocolVersionException.java
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,25 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
import io.airbyte.commons.version.Version; | ||
|
||
public class UnsupportedProtocolVersionException extends KnownException { | ||
|
||
public UnsupportedProtocolVersionException(final Version current, final Version minSupported, final Version maxSupported) { | ||
this(current.serialize(), minSupported, maxSupported); | ||
} | ||
|
||
public UnsupportedProtocolVersionException(final String current, final Version minSupported, final Version maxSupported) { | ||
super(String.format("Airbyte Protocol Version %s is not supported. (Must be within [%s:%s])", | ||
current, minSupported.serialize(), maxSupported.serialize())); | ||
} | ||
|
||
@Override | ||
public int getHttpCode() { | ||
return 400; | ||
} | ||
|
||
} |
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
Oops, something went wrong.