2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-31 14:25:30 +00:00

Add ownerGroupId to RecordSet (#387)

* Add ownerGroupId to RecordSet and RecordSetInfo models.
This commit is contained in:
Michael Ly
2018-12-07 15:24:43 -05:00
committed by GitHub
parent a1c0c179f4
commit e220c1ed93
6 changed files with 34 additions and 8 deletions

View File

@@ -111,7 +111,8 @@ case class RecordSetInfo(
records: List[RecordData],
id: String,
account: String,
accessLevel: AccessLevel)
accessLevel: AccessLevel,
ownerGroupId: Option[String])
object RecordSetInfo {
def apply(recordSet: RecordSet, accessLevel: AccessLevel): RecordSetInfo = RecordSetInfo(
zoneId = recordSet.zoneId,
@@ -124,7 +125,8 @@ object RecordSetInfo {
records = recordSet.records,
id = recordSet.id,
account = recordSet.account,
accessLevel = accessLevel
accessLevel = accessLevel,
ownerGroupId = recordSet.ownerGroupId
)
}

View File

@@ -178,7 +178,8 @@ trait DnsJsonProtocol extends JsonValidation {
recordType
.andThen(extractRecords(_, js \ "records")),
(js \ "id").default[String](UUID.randomUUID().toString),
(js \ "account").default[String]("system")
(js \ "account").default[String]("system"),
(js \ "ownerGroupId").optional[String]
).mapN(RecordSet.apply)
// Put additional record set level checks below
@@ -200,7 +201,8 @@ trait DnsJsonProtocol extends JsonValidation {
("updated" -> Extraction.decompose(rs.updated)) ~
("records" -> Extraction.decompose(rs.records)) ~
("id" -> rs.id) ~
("account" -> rs.account)
("account" -> rs.account) ~
("ownerGroupId" -> rs.ownerGroupId)
}
case object RecordSetInfoSerializer extends ValidationSerializer[RecordSetInfo] {
@@ -221,7 +223,8 @@ trait DnsJsonProtocol extends JsonValidation {
("records" -> Extraction.decompose(rs.records)) ~
("id" -> rs.id) ~
("account" -> rs.account) ~
("accessLevel" -> rs.accessLevel.toString)
("accessLevel" -> rs.accessLevel.toString) ~
("ownerGroupId" -> rs.ownerGroupId)
}
def extractRecords(typ: RecordType, js: JValue): ValidatedNel[String, List[RecordData]] =

View File

@@ -470,6 +470,7 @@ class ProtobufConversionsSpec
pb.getTtl shouldBe aRs.ttl
pb.getTyp shouldBe aRs.typ.toString
pb.getZoneId shouldBe aRs.zoneId
pb.hasOwnerGroupId shouldBe false
pb.getRecordCount shouldBe 2
}
@@ -481,6 +482,21 @@ class ProtobufConversionsSpec
rs shouldBe aRs
}
"convert to protobuf for a recordset with ownerGroupId defined" in {
val rs = aRs.copy(ownerGroupId = Some("ownerGroupId"))
val pb = toPB(rs)
pb.hasOwnerGroupId shouldBe true
Some(pb.getOwnerGroupId) shouldBe rs.ownerGroupId
}
"convert from protobuf for a recordset with ownerGroupId defined" in {
val rs = aRs.copy(ownerGroupId = Some("ownerGroupId"))
val pb = toPB(rs)
fromPB(pb) shouldBe rs
}
"convert from protobuf for AAAA recordset" in {
fromPB(toPB(aaaa)) shouldBe aaaa
}

View File

@@ -110,6 +110,7 @@ message RecordSet {
optional int64 updated = 8;
repeated RecordData record = 9;
required string account = 10;
optional string ownerGroupId = 11;
}
message RecordSetChange {

View File

@@ -43,7 +43,8 @@ case class RecordSet(
updated: Option[DateTime] = None,
records: List[RecordData] = List.empty,
id: String = UUID.randomUUID().toString,
account: String = "system") {
account: String = "system",
ownerGroupId: Option[String] = None) {
def isPending: Boolean =
(status == RecordSetStatus.Pending
@@ -60,7 +61,8 @@ case class RecordSet(
sb.append("ttl=\"").append(ttl.toString).append("\"; ")
sb.append("account=\"").append(account).append("\"; ")
sb.append("status=\"").append(status.toString).append("\"; ")
sb.append("records=\"").append(records.toString).append("\"")
sb.append("records=\"").append(records.toString).append("\"; ")
sb.append("ownerGroupId=\"").append(ownerGroupId).append("\"")
sb.append("]")
sb.toString

View File

@@ -72,7 +72,8 @@ trait ProtobufConversions {
id = rs.getId,
records =
rs.getRecordList.asScala.map(rd => fromPB(rd, RecordType.withName(rs.getTyp))).toList,
account = rs.getAccount
account = rs.getAccount,
ownerGroupId = if (rs.hasOwnerGroupId) Some(rs.getOwnerGroupId) else None
)
def fromPB(zn: VinylDNSProto.Zone): Zone =
@@ -286,6 +287,7 @@ trait ProtobufConversions {
.setAccount(rs.account)
rs.updated.foreach(dt => builder.setUpdated(dt.getMillis))
rs.ownerGroupId.foreach(id => builder.setOwnerGroupId(id))
// Map the records, first map to bytes, and then map the bytes to a record data instance
rs.records.map(toRecordData).foreach(rd => builder.addRecord(rd))