1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00

docs: Android SDK: reformat and add more details on client secrets

This commit is contained in:
Thomas Heartman 2021-12-06 12:58:58 +01:00
parent a03e7927bb
commit d936a0d4ed
2 changed files with 25 additions and 15 deletions

View File

@ -5,9 +5,14 @@ title: Android Proxy SDK
In this guide we'll explain how to use feature toggles in an Android application using Unleash's [Android Proxy SDK](https://github.com/Unleash/unleash-android-proxy-sdk) and the [Unleash Proxy](https://github.com/Unleash/unleash-proxy). In this guide we'll explain how to use feature toggles in an Android application using Unleash's [Android Proxy SDK](https://github.com/Unleash/unleash-android-proxy-sdk) and the [Unleash Proxy](https://github.com/Unleash/unleash-proxy).
> You will need your `PROXY_URL` and your `PROXY_SECRET`. Refer to the [Proxy documentation](/sdks/unleash-proxy)
# Step 1: Install the proxy SDK :::note
The Android proxy SDK requires Unleash Proxy to function. You'll need the proxy's URL and a configured proxy secret. Refer to the [proxy documentation](/sdks/unleash-proxy) for how to set it up and [how to configure the proxy secrets](/sdks/unleash-proxy#configuration-variables).
:::
## How to use the Android Proxy SDK
### Step 1: Install the proxy SDK
First we must add unleash-android-proxy-sdk as a dependency to our project. First we must add unleash-android-proxy-sdk as a dependency to our project.
@ -27,7 +32,7 @@ In maven
</dependency> </dependency>
``` ```
# Step 2: Enable internet ### Step 2: Enable internet
> NB - Your app will need internet permission in order to reach the proxy. So in your manifest add > NB - Your app will need internet permission in order to reach the proxy. So in your manifest add
@ -35,7 +40,7 @@ In maven
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
``` ```
# Step 3: Configure Context ### Step 3: Configure Context
Since the proxy works by evaluating all feature toggles server side and returning the evaluated toggles back to the client, we'll need to configure the context to send to the proxy for evaluation. Since the proxy works by evaluating all feature toggles server side and returning the evaluated toggles back to the client, we'll need to configure the context to send to the proxy for evaluation.
@ -49,11 +54,16 @@ val myAppContext = UnleashContext.newBuilder()
.build() .build()
``` ```
# Step 4: Configure the Client ### Step 4: Configure the Client
Configuring the client includes adding the URL for your proxy host, your proxy secret and deciding how you want to load the toggle status. As of v0.1 the SDK supports an automatic polling with an adjustable poll period or loading the state from disk. Most users will probably use the polling client, but it's nice to know that you can instantiate your client without actually needing Internet if you choose loading from File To create a client, use the `UnleashConfig.newBuilder` method. When building a configuration, you'll need to provide it with:
- `proxyUrl`: the URL your proxy is available at
- `clientSecret`: the [proxy secret](/sdks/unleash-proxy#configuration-variables) you wish to use
- `pollMode`: how you want to load the toggle status
# Step 4a: Configure client polling proxy As of v0.1 the SDK supports an automatic polling with an adjustable poll period or loading the state from disk. Most users will probably use the polling client, but it's nice to know that you can instantiate your client without actually needing Internet if you choose loading from File
#### Step 4a: Configure client polling proxy
Configuring a client with a 60 seconds poll interval Configuring a client with a 60 seconds poll interval
@ -63,7 +73,7 @@ import io.getunleash.polling.PollingModes
val unleashConfig = UnleashConfig.newBuilder() val unleashConfig = UnleashConfig.newBuilder()
.proxyUrl("URL to your proxy installation") .proxyUrl("URL to your proxy installation")
.clientSecret("yourProxyApiKey") .clientSecret("yourProxySecret")
.pollMode(PollingModes.autoPoll(Duration.ofSeconds(60)) { .pollMode(PollingModes.autoPoll(Duration.ofSeconds(60)) {
// This lambda will be called every time polling the server updates the toggle state // This lambda will be called every time polling the server updates the toggle state
featuresUpdated() featuresUpdated()
@ -71,7 +81,7 @@ val unleashConfig = UnleashConfig.newBuilder()
.build() .build()
``` ```
# Step 4b: Configure client loading toggles from a file #### Step 4b: Configure client loading toggles from a file
If you need to have a known state for your UnleashClient, you can perform a query against the proxy using your HTTP client of choice and save the output as a json file. Then you can tell Unleash to use this file to setup toggle states. If you need to have a known state for your UnleashClient, you can perform a query against the proxy using your HTTP client of choice and save the output as a json file. Then you can tell Unleash to use this file to setup toggle states.
@ -89,7 +99,7 @@ val unleashConfig = UnleashConfig.newBuilder()
.build() .build()
``` ```
# Step 5: Instantiate the client ### Step 5: Instantiate the client
Having created your `UnleashContext` and your `UnleashConfig` you can now instantiate your client. Make sure you only do this once, and pass the instantiated client to classes/functions that need it. Having created your `UnleashContext` and your `UnleashConfig` you can now instantiate your client. Make sure you only do this once, and pass the instantiated client to classes/functions that need it.
@ -99,7 +109,7 @@ import io.getunleash.UnleashClient
val unleashClient = UnleashClient(config = unleashConfig, context = myAppContext) val unleashClient = UnleashClient(config = unleashConfig, context = myAppContext)
``` ```
# Step 6: Use the feature toggle ### Step 6: Use the feature toggle
Now that we have initialized the proxy SDK we can start using feature toggles defined in Unleash in our application. To achieve this we have the “isEnabled” method available, which will allow us to check the value of a feature toggle. This method will return true or false based on whether the feature should be enabled or disabled for the current state. Now that we have initialized the proxy SDK we can start using feature toggles defined in Unleash in our application. To achieve this we have the “isEnabled” method available, which will allow us to check the value of a feature toggle. This method will return true or false based on whether the feature should be enabled or disabled for the current state.
@ -111,14 +121,14 @@ if (unleashClient.isEnabled("AwesomeFeature")) {
} }
``` ```
# Updates ## Updates
When using the AutoPoll mode you are able to pass in a listener which will get notified everytime our toggles changes, allowing you to recheck your toggles. For an example, see our [android-sample-app](https://github.com/Unleash/unleash-android-proxy-sdk/blob/main/samples/android/app/src/main/java/com/example/unleash/MainActivity.kt) When using the AutoPoll mode you are able to pass in a listener which will get notified everytime our toggles changes, allowing you to recheck your toggles. For an example, see our [android-sample-app](https://github.com/Unleash/unleash-android-proxy-sdk/blob/main/samples/android/app/src/main/java/com/example/unleash/MainActivity.kt)
# KDoc ## KDoc
KDoc for the api is available at [https://docs.getunleash.io/unleash-android-proxy-sdk](https://docs.getunleash.io/unleash-android-proxy-sdk) KDoc for the api is available at [https://docs.getunleash.io/unleash-android-proxy-sdk](https://docs.getunleash.io/unleash-android-proxy-sdk)
# Github ## Github
Readme for the client and source code is available at [https://github.com/Unleash/unleash-android-proxy-sdk](https://github.com/Unleash/unleash-android-proxy-sdk) Readme for the client and source code is available at [https://github.com/Unleash/unleash-android-proxy-sdk](https://github.com/Unleash/unleash-android-proxy-sdk)

View File

@ -37,7 +37,7 @@ Regardless of how you choose to run the it, the proxy will need access to these
- **`proxySecrets`** / **`UNLEASH_PROXY_SECRETS`** - **`proxySecrets`** / **`UNLEASH_PROXY_SECRETS`**
A list of client keys that the proxy will accept. For the proxy to accept an incoming request, the client must use one of these keys for authorization. In client SDKs, this is usually known as a `clientKey` . If you query the proxy directly via HTTP, this is the `authorization` header. A list of client keys that the proxy will accept. For the proxy to accept an incoming request, the client must use one of these keys for authorization. In client SDKs, this is usually known as a `clientKey` or a `clientSecret` . If you query the proxy directly via HTTP, this is the `authorization` header.
When using an environment variable to set the proxy secrets, the value should be a comma-separated list of strings, such as `secret-one,secret-two`. When using an environment variable to set the proxy secrets, the value should be a comma-separated list of strings, such as `secret-one,secret-two`.