Skip to content
Permalink
Browse files

Initial commit

 Copied from the cash-exemplar repo
  • Loading branch information...
adrw committed May 21, 2019
0 parents commit 560edffe0774c52e4ec41839b317d269ff0df15a
Showing with 961 additions and 0 deletions.
  1. +9 βˆ’0 .gitignore
  2. +3 βˆ’0 OWNERS.yaml
  3. +46 βˆ’0 README.md
  4. +43 βˆ’0 build.gradle
  5. +48 βˆ’0 client/build.gradle
  6. +4 βˆ’0 client/gradle.properties
  7. +40 βˆ’0 client/src/main/kotlin/com/squareup/cash/barber/client/BarberApi.kt
  8. +6 βˆ’0 client/src/main/kotlin/com/squareup/cash/barber/client/BarberClient.kt
  9. +22 βˆ’0 client/src/main/kotlin/com/squareup/cash/barber/client/BarberClientModule.kt
  10. +27 βˆ’0 client/src/main/kotlin/com/squareup/cash/barber/client/RealBarberClient.kt
  11. +10 βˆ’0 client/src/main/kotlin/com/squareup/cash/barber/client/testing/FakeBarberClient.kt
  12. +11 βˆ’0 client/src/main/kotlin/com/squareup/cash/barber/client/testing/FakeBarberClientModule.kt
  13. +47 βˆ’0 dependencies.gradle
  14. +16 βˆ’0 gradle.properties
  15. BIN gradle/wrapper/gradle-wrapper.jar
  16. +5 βˆ’0 gradle/wrapper/gradle-wrapper.properties
  17. +172 βˆ’0 gradlew
  18. +84 βˆ’0 gradlew.bat
  19. +3 βˆ’0 kochiku.yml
  20. +6 βˆ’0 script/ci
  21. +100 βˆ’0 service/build.gradle
  22. +11 βˆ’0 service/src/main/kotlin/com/squareup/cash/barber/actions/BarberWebActionModule.kt
  23. +28 βˆ’0 service/src/main/kotlin/com/squareup/cash/barber/actions/PingAction.kt
  24. +19 βˆ’0 service/src/main/kotlin/com/squareup/cash/barber/service/BarberAccessModule.kt
  25. +11 βˆ’0 service/src/main/kotlin/com/squareup/cash/barber/service/BarberConfig.kt
  26. +42 βˆ’0 service/src/main/kotlin/com/squareup/cash/barber/service/BarberService.kt
  27. +12 βˆ’0 service/src/main/proto/squareup/cash/barber/service.proto
  28. +9 βˆ’0 service/src/main/resources/barber-common.yaml
  29. +14 βˆ’0 service/src/main/resources/barber-production.yaml
  30. +14 βˆ’0 service/src/main/resources/barber-staging.yaml
  31. +26 βˆ’0 service/src/test/kotlin/com/squareup/cash/barber/InjectorTest.kt
  32. +27 βˆ’0 service/src/test/kotlin/com/squareup/cash/barber/actions/BarberTestingModule.kt
  33. +27 βˆ’0 service/src/test/kotlin/com/squareup/cash/barber/actions/PingActionTest.kt
  34. +17 βˆ’0 service/src/test/resources/log4j.properties
  35. +2 βˆ’0 settings.gradle
@@ -0,0 +1,9 @@
.gradle
**/out/
.idea
build/
*.iml
*.swp
polyrepo-settings.gradle
dev/
docker-sources/
@@ -0,0 +1,3 @@
# Fill this out to get notifications of new PRs!
# r: [reviewer1, reviewer2]
# cc: [tagged1, tagged2]
@@ -0,0 +1,46 @@
# barber

This is a sample app that makes use of Misk. All commands below assume you're in the root directory
of this repository.

## Building
Build barber:

```
$ ./gradlew clean shadowJar
```

## Run the Service

### From the command line

```
$ ENVIRONMENT=DEVELOPMENT \
SERVICE_NAME=barber \
REGION= ACCOUNT_ID= \
java -jar service/build/libs/service.jar
```

### From IntelliJ
Right-click on `BarberService.kt` and select `Run`. It will fail without the correct environment
variables. Edit the run configuration and add:

```
SERVICE_NAME=barber
ENVIRONMENT=DEVELOPMENT
REGION=
ACCOUNT_ID=
```

The latter two are required in production and staging, and managed by the infrastructure.
They're not used in development mode, so any value is fine.


### Confirm barber works with curl

```
$ curl --data '{"message": "hello"}' -H 'Content-Type: application/json' http://localhost:8080/ping
```

## Additional docs
* Visit [go/cashdevguide](http://go/cashdevguide) for documentation about the Cash Cloud Platform
@@ -0,0 +1,43 @@
apply from: new File("./dependencies.gradle")

subprojects {
apply plugin: "java"
buildscript {
repositories {
maven {
url "https://maven.global.square/artifactory/square-public"
}
mavenCentral()
jcenter()
}

dependencies {
classpath dep.kotlinGradlePlugin
classpath dep.wireCompiler
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
classpath dep.shadowJarPlugin
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.2.0'
}
}

repositories {
maven {
url "https://maven.global.square/artifactory/square-public"
}
mavenCentral()
jcenter()
}
dependencies {
testImplementation dep.junitApi
testRuntimeOnly dep.junitEngine
}
test {
useJUnitPlatform()
testLogging {
events "started", "passed", "skipped", "failed"
exceptionFormat = 'full'
showExceptions = true
}
}
}

@@ -0,0 +1,48 @@
apply plugin: 'kotlin'
apply plugin: 'org.junit.platform.gradle.plugin'

apply from: "https://git.sqcorp.co/projects/CASH/repos/cash-upload/raw/common-upload.gradle?at=refs%2Fheads%2Fmaster"

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
allWarningsAsErrors = true
}
}

compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
allWarningsAsErrors = true
}
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
main.java.srcDirs += 'build/generated/source/protos/main/java/'
test.java.srcDirs += 'src/test/kotlin/'
}

dependencies {
implementation dep.guava
implementation dep.guice
implementation dep.kotlinStdLib
implementation dep.kotlinReflection
implementation dep.misk
implementation dep.moshi
implementation dep.okHttp
implementation dep.okio
implementation dep.retrofit
implementation dep.retrofitMoshi
implementation dep.retrofitWire
implementation dep.wireMoshiAdapter
implementation dep.wireRuntime

testImplementation dep.junitEngine
}

jar {
baseName = "client"
}

compileKotlin.dependsOn ':service:compileWire'
@@ -0,0 +1,4 @@
POM_ARTIFACT_ID=client
POM_NAME=client
POM_DESCRIPTION=A client for accessing barber
POM_PACKAGING=jar
@@ -0,0 +1,40 @@
package com.squareup.cash.barber.client

import com.squareup.moshi.Moshi
import com.squareup.protos.cash.barber.service.PingRequest
import com.squareup.protos.cash.barber.service.PingResponse
import com.squareup.wire.WireJsonAdapterFactory
import okhttp3.OkHttpClient
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.http.Body
import retrofit2.http.Headers
import retrofit2.http.POST

/** The api exposed by barber. */
interface BarberApi {
companion object {
fun create(hostname: String, okHttpClient: OkHttpClient): BarberApi {
val moshi = Moshi.Builder()
.add(WireJsonAdapterFactory())
.build()

val retrofit = Retrofit.Builder()
.baseUrl(hostname)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.client(okHttpClient)
.build()

return retrofit.create(BarberApi::class.java)
}
}

@POST("/ping")
@Headers(value = [
"accept: application/json"
])
fun ping(
@Body request: PingRequest
): Call<PingResponse>
}
@@ -0,0 +1,6 @@
package com.squareup.cash.barber.client

/** Responsible for building the request and parsing the response from the barber api. */
interface BarberClient {
fun ping(message: String): String
}
@@ -0,0 +1,22 @@
package com.squareup.cash.barber.client

import com.google.inject.name.Names
import misk.client.TypedHttpClientModule
import misk.inject.KAbstractModule

/**
* Module to install to bind a real client to your app.
* Your app's config must include the http client details
* to communicate to barber.
*
* Note that this is meant for other Misk apps to install.
* Square DC Java apps have their own style of binding up
* clients, and can use the RealBarberClient.buildClient API.
*/
class BarberClientModule : KAbstractModule() {
override fun configure() {
install(TypedHttpClientModule(
BarberApi::class, "barber", Names.named("barber")))
bind<BarberClient>().to<RealBarberClient>()
}
}
@@ -0,0 +1,27 @@
package com.squareup.cash.barber.client

import com.google.common.base.Preconditions.checkState
import com.squareup.protos.cash.barber.service.PingRequest
import okhttp3.OkHttpClient
import javax.inject.Inject
import javax.inject.Named
import javax.inject.Singleton


/** A real client that uses Retrofit to make HTTP calls and Moshi for JSON serialization/de-serialization. */
@Singleton class RealBarberClient @Inject constructor(
@Named("barber") private val api: BarberApi) : BarberClient {
companion object {
fun create(hostname: String, okHttpClient: OkHttpClient) : BarberClient {
return RealBarberClient(BarberApi.create(hostname, okHttpClient))
}
}

override fun ping(message: String): String {
val request = PingRequest.Builder().message(message).build()
val response = api.ping(request).execute()

checkState(response.isSuccessful)
return response.body()!!.message
}
}
@@ -0,0 +1,10 @@
package com.squareup.cash.barber.client.testing

import com.squareup.cash.barber.client.BarberClient
import javax.inject.Singleton

/** A fake client used by tests. The fake client is an open class to allow for use of spies and mocks. */
@Singleton
open class FakeBarberClient : BarberClient {
override fun ping(message: String): String = "pong $message"
}
@@ -0,0 +1,11 @@
package com.squareup.cash.barber.client.testing

import com.squareup.cash.barber.client.BarberClient
import misk.inject.KAbstractModule

/** Module to install to bind BarberClient to a fake instance */
class FakeBarberClientModule : KAbstractModule() {
override fun configure() {
bind<BarberClient>().to<FakeBarberClient>()
}
}
@@ -0,0 +1,47 @@
//Generated from polyrepo's master-dependencies.json
ext.dep = [
"assertj": "org.assertj:assertj-core:3.9.0",
"guava": "com.google.guava:guava:23.6-jre",
"guice": "com.google.inject:guice:4.2.2",
"guiceMultibindings": "com.google.inject.extensions:guice-multibindings:4.2.2",
"jacksonDatabind": "com.fasterxml.jackson.core:jackson-databind:2.9.3",
"jacksonDataformatYaml": "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.3",
"jacksonJsr310": "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.4",
"jacksonKotlin": "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.3",
"jettyServer": "org.eclipse.jetty:jetty-server:9.4.18.v20190429",
"jettyServlet": "org.eclipse.jetty:jetty-servlet:9.4.18.v20190429",
"jettyWebsocketServer": "org.eclipse.jetty.websocket:websocket-server:9.4.18.v20190429",
"jettyWebsocketServlet": "org.eclipse.jetty.websocket:websocket-servlet:9.4.18.v20190429",
"junitApi": "org.junit.jupiter:junit-jupiter-api:5.3.1",
"junitEngine": "org.junit.jupiter:junit-jupiter-engine:5.3.1",
"junitParams": "org.junit.jupiter:junit-jupiter-params:5.3.1",
"kotlinGradlePlugin": "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21",
"kotlinReflection": "org.jetbrains.kotlin:kotlin-reflect:1.3.21",
"kotlinScriptRuntime": "org.jetbrains.kotlin:kotlin-script-runtime:1.3.21",
"kotlinStdLib": "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.21",
"loggingApi": "io.github.microutils:kotlin-logging:1.4.9",
"metricsCore": "io.dropwizard.metrics:metrics-core:4.0.1",
"metricsParent": "io.dropwizard.metrics:metrics-parent:4.0.1",
"misk": "com.squareup.misk:misk:2019.05.20-c9c6723f",
"miskTesting": "com.squareup.misk:misk-testing:2019.05.20-c9c6723f",
"mockito": "org.mockito:mockito-core:2.23.4",
"mockitoKotlin": "com.nhaarman:mockito-kotlin:1.5.0",
"moshi": "com.squareup.moshi:moshi-kotlin:1.8.0",
"mysql": "mysql:mysql-connector-java:5.1.47",
"okHttp": "com.squareup.okhttp3:okhttp:3.12.1",
"okio": "com.squareup.okio:okio:2.2.2",
"openTracing": "io.opentracing:opentracing-api:0.31.0",
"openTracingMock": "io.opentracing:opentracing-mock:0.31.0",
"openTracingOkHttp": "io.opentracing.contrib:opentracing-okhttp3:0.1.0",
"retrofit": "com.squareup.retrofit2:retrofit:2.4.0",
"retrofitMoshi": "com.squareup.retrofit2:converter-moshi:2.4.0",
"retrofitWire": "com.squareup.retrofit2:converter-wire:2.4.0",
"shadowJarPlugin": "com.github.jengelman.gradle.plugins:shadow:4.0.4",
"skim": "com.squareup.skim:skim:2019.05.15-c7447aa",
"tracingJaeger": "com.uber.jaeger:jaeger-core:0.24.0",
"wireCompiler": "com.squareup.wire:wire-compiler:3.0.0-square09",
"wireMoshiAdapter": "com.squareup.wire:wire-moshi-adapter:3.0.0-alpha01",
"wireRuntime": "com.squareup.wire:wire-runtime:2.3.0-RC1",
"wireSchema": "com.squareup.wire:wire-schema:2.3.0-RC1",
]
//Generated from polyrepo's master-dependencies.json
@@ -0,0 +1,16 @@
GROUP=com.squareup.barber
VERSION_NAME=


POM_URL=https://stash.corp.squareup.com/projects/CASH/repos/barber
POM_SCM_URL=https://stash.corp.squareup.com/projects/CASH/repos/barber/browse
POM_SCM_CONNECTION=scm:git:ssh://git@git.corp.squareup.com/cash/barber.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@git.corp.squareup.com/cash/barber.git

POM_LICENCE_NAME=Private
POM_LICENCE_URL=Private
POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=square
POM_DEVELOPER_NAME=Square, Inc.

Binary file not shown.
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-5.1-bin.zip

0 comments on commit 560edff

Please sign in to comment.
You can’t perform that action at this time.