Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ gitlab-template {

// Pagination value for Gitlab. See https://docs.gitlab.com/ee/api/README.html#pagination for details.
per-page: 100

// throttle interval (milliseconds)
throttle-duration: 100
}

technical-users-keys {
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/de/frosner/gitlabtemplate/GitlabSource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class GitlabSource(wsClient: StandaloneWSClient,
url: String,
privateToken: String,
onlyActiveUsers: Boolean,
perPage: Int)(implicit ec: ExecutionContext, materializer: Materializer)
perPage: Int,
throttleDuration: Long)(implicit ec: ExecutionContext, materializer: Materializer)
extends StrictLogging {

def getUsers: EitherT[Future, Error, Set[GitlabUser]] = {
Expand Down Expand Up @@ -67,6 +68,7 @@ class GitlabSource(wsClient: StandaloneWSClient,
.url(s"$url/api/v4/users/${user.id}/keys")
.withHttpHeaders(("PRIVATE-TOKEN", privateToken))
logger.debug(s"Requesting public keys for ${user.username}: ${request.url}")
Thread.sleep(throttleDuration)
request.get().map { response =>
Json
.fromJson[Set[PublicKey]](response.body[JsValue])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ case class PrivateTokenAuthConfig(enabled: Boolean, token: String)

case class SinkConfig(filesystem: FilesystemConfig)

case class GitlabConfig(onlyActiveUsers: Boolean, privateToken: String, url: String, perPage: Int)
case class GitlabConfig(onlyActiveUsers: Boolean, privateToken: String, url: String, perPage: Int, throttleDuration: Long)

case class FilesystemConfig(path: Path, publicKeysFile: String, createEmptyKeyFile: Boolean)
3 changes: 2 additions & 1 deletion src/main/scala/de/frosner/gitlabtemplate/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ object Main extends StrictLogging {
gitlabConf.url,
gitlabConf.privateToken,
gitlabConf.onlyActiveUsers,
gitlabConf.perPage)
gitlabConf.perPage,
gitlabConf.throttleDuration)

val technicalUsersKeysSource =
new TechnicalUsersKeysSource(wsClient,
Expand Down
14 changes: 7 additions & 7 deletions src/test/scala/de/frosner/gitlabtemplate/GitlabSourceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class GitlabSourceSpec extends FlatSpec with Matchers with HttpTests {
GitlabUser(1, "usr1"),
GitlabUser(2, "usr2")
)
new GitlabSource(wsClient, address, "token", false, 100).getUsers.value
new GitlabSource(wsClient, address, "token", false, 100, 1).getUsers.value
.map(_ shouldBe Right(expected))
}
}
Expand Down Expand Up @@ -76,7 +76,7 @@ class GitlabSourceSpec extends FlatSpec with Matchers with HttpTests {
GitlabUser(6, "usr6"),
GitlabUser(7, "usr7")
)
new GitlabSource(wsClient, address, "token", false, 2).getUsers.value
new GitlabSource(wsClient, address, "token", false, 2, 1).getUsers.value
.map(_ shouldBe Right(expected))
}
}
Expand All @@ -97,7 +97,7 @@ class GitlabSourceSpec extends FlatSpec with Matchers with HttpTests {
} { implicit ec => implicit materializer =>
{
case (wsClient, address) =>
new GitlabSource(wsClient, address, "token", false, 100).getUsers.value
new GitlabSource(wsClient, address, "token", false, 100, 1).getUsers.value
.map(_ shouldBe a[Left[_, _]])
}
}
Expand All @@ -107,7 +107,7 @@ class GitlabSourceSpec extends FlatSpec with Matchers with HttpTests {
withServerAndClient { RouteDirectives.reject } { implicit ec => implicit materializer =>
{
case (wsClient, address) =>
new GitlabSource(wsClient, "http://dsafdsgdfsfdsfdsf", "token", false, 100).getUsers.value.failed
new GitlabSource(wsClient, "http://dsafdsgdfsfdsfdsf", "token", false, 100, 1).getUsers.value.failed
.map(_ shouldBe a[UnknownHostException])
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ class GitlabSourceSpec extends FlatSpec with Matchers with HttpTests {
"usr1" -> Set("key1", "key2"),
"usr2" -> Set("key3")
)
new GitlabSource(wsClient, address, "token", false, 100)
new GitlabSource(wsClient, address, "token", false, 100, 1)
.getSshKeys(users)
.value
.map(_ shouldBe Right(expected))
Expand All @@ -153,7 +153,7 @@ class GitlabSourceSpec extends FlatSpec with Matchers with HttpTests {
} { implicit ec => implicit materializer =>
{
case (wsClient, address) =>
new GitlabSource(wsClient, address, "token", false, 100)
new GitlabSource(wsClient, address, "token", false, 100, 1)
.getSshKeys(Set(GitlabUser(1, "usr1")))
.value
.map(_ shouldBe a[Left[_, _]])
Expand All @@ -165,7 +165,7 @@ class GitlabSourceSpec extends FlatSpec with Matchers with HttpTests {
withServerAndClient { RouteDirectives.reject } { implicit ec => implicit materializer =>
{
case (wsClient, address) =>
new GitlabSource(wsClient, address, "token", false, 100)
new GitlabSource(wsClient, address, "token", false, 100, 1)
.getSshKeys(Set(GitlabUser(1, "usr1")))
.value
.failed
Expand Down