From dd4b937061c7f7cff22f6f3446eed108370eaa1d Mon Sep 17 00:00:00 2001 From: Brian Yencho Date: Thu, 14 Sep 2023 16:27:34 -0500 Subject: [PATCH] BIT-282: Include Bitwarden SDK dependency (#44) --- .github/workflows/run-check.yml | 1 + README.md | 6 ++++- app/build.gradle.kts | 1 + .../datasource/di/EncryptionModule.kt | 22 ++++++++++++++++++ gradle/libs.versions.toml | 4 ++++ settings.gradle.kts | 23 +++++++++++++++++++ 6 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/di/EncryptionModule.kt diff --git a/.github/workflows/run-check.yml b/.github/workflows/run-check.yml index 5e573dfb3..bffa7140d 100644 --- a/.github/workflows/run-check.yml +++ b/.github/workflows/run-check.yml @@ -5,6 +5,7 @@ on: pull_request: env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} JAVA_VERSION: 17 jobs: diff --git a/README.md b/README.md index 8cff39f30..a77ffdeac 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,11 @@ $ git clone https://github.com/bitwarden/android ``` -2. Setup the code style formatter: +2. Create a `user.properties` file in the root directory of the project and add the following properties: + + - `gitHubToken`: A "classic" Github Personal Access Token (PAT) with the `read:packages` scope (ex: `gitHubToken=gph_xx...xx`). These can be generated by going to the [Github tokens page](https://github.com/settings/tokens). See [the Github Packages user documentation concerning authentication](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#authenticating-to-github-packages) for more details. + +3. Setup the code style formatter: All code must follow the guidelines described in the [Code Style Guidelines document](docs/STYLE_AND_BEST_PRACTICES.md). To aid in adhering to these rules, all contributors should apply `docs/bitwarden-style.xml` as their code style scheme. In IntelliJ / Android Studio: diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4659ac038..b209ad50b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -82,6 +82,7 @@ dependencies { implementation(libs.androidx.room.ktx) implementation(libs.androidx.room.runtime) implementation(platform(libs.google.firebase.bom)) + implementation(libs.bitwarden.sdk) implementation(libs.bumptech.glide) implementation(libs.google.firebase.cloud.messaging) implementation(libs.google.firebase.crashlytics) diff --git a/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/di/EncryptionModule.kt b/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/di/EncryptionModule.kt new file mode 100644 index 000000000..4a6d57cba --- /dev/null +++ b/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/di/EncryptionModule.kt @@ -0,0 +1,22 @@ +package com.x8bit.bitwarden.data.platform.datasource.di + +import com.bitwarden.sdk.Client +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +/** + * Provides dependencies related to encryption / decryption / secure generation. + */ +@Module +@InstallIn(SingletonComponent::class) +object EncryptionModule { + + @Provides + @Singleton + fun provideBitwardenClient(): Client { + return Client(null) + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0d0489379..b24d85cc7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -20,6 +20,9 @@ androidxLifecycle = "2.6.1" # child navigation destinations (BIT-201). androidxNavigation = "2.5.3" androidxRoom = "2.5.2" +# Once the app and SDK reach a critical point of completeness we should begin fixing the version +# here (BIT-311). +bitwardenSdk = "ps-maven-SNAPSHOT" detekt = "1.23.1" firebaseBom = "32.2.2" glide = "4.15.1" @@ -61,6 +64,7 @@ androidx-navigation-compose = { module = "androidx.navigation:navigation-compose androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "androidxRoom" } androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "androidxRoom" } androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "androidxRoom" } +bitwarden-sdk = { module = "com.bitwarden:sdk-android", version.ref = "bitwardenSdk" } bumptech-glide = { module = "com.github.bumptech.glide:glide", version.ref = "glide" } detekt-detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } detekt-detekt-rules = { module = "io.gitlab.arturbosch.detekt:detekt-rules-libraries", version.ref = "detekt" } diff --git a/settings.gradle.kts b/settings.gradle.kts index b79d916cf..40e634f4f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,6 @@ +import java.io.FileInputStream +import java.util.Properties + pluginManagement { repositories { google() @@ -5,11 +8,31 @@ pluginManagement { gradlePluginPortal() } } + +/** + * Loads local user-specific build properties that are not checked into source control. + */ +val userProperties = Properties().apply { + val buildPropertiesFile = File(rootDir, "user.properties") + if (buildPropertiesFile.exists()) { + FileInputStream(buildPropertiesFile).use { load(it) } + } +} + + dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() + maven { + name = "GitHubPackages (Bitwarden)" + url = uri("https://maven.pkg.github.com/bitwarden/sdk") + credentials { + username = "" + password = userProperties["gitHubToken"] as String? ?: System.getenv("GITHUB_TOKEN") + } + } } }