搜尋套件、儲存庫與 APP 分類

套件詳情v1.2.0

azure_app_config

一個用於與 Microsoft Azure 應用程式組態通訊的 Dart 套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
4940
喜歡數
19
Pub 分數
160

安裝套件

flutter pub add azure_app_config

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Dart 套件,可實現與 Microsoft Azure 應用程式設定的無縫整合,讓應用程式能夠動態地從 Azure 檢索和管理設定。它支援跨多個環境的安全即時存取金鑰-值對,非常適合在雲端原生環境中管理應用程式設定。此套件相容於所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,適用於需要中央化設定管理的跨平台應用。

適用情境

  • 動態設定管理
  • 環境特定的設定
  • 雲原生應用部署
  • 即時設定更新
  • 集中式應用設定儲存

主要特色

  • 與 Azure 應用程式設定的受保護連接
  • 支援多個平台
  • 即時設定同步
  • 環境感知的設定取得
  • 輕鬆整合至Flutter應用

適合對象

  • 使用 Azure 的 Flutter 應用
  • 需要設定管理的後端服務
  • 跨平台應用程式
  • 使用 Azure 進行基礎設施的團隊
  • 需要動態設定更新的開發者

使用建議

  • 需要 Azure 應用程式設定實例
  • 需要進行驗證設定(例如,SAS 權杖或託管身分識別)
  • 僅限 Azure 主機配置
  • 需要網路連接
  • 可能需要快取以供離線使用

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

style: very good analysis

Azure App Configuration

This package makes it easier to communicate with Microsoft Azure App Configuration KeyValue and FeatureFlag resources.

Installation

To use this plugin, add azure_app_config to your pubspec.yaml file.

Authentication

There are two methods of authenticating Azure App Configuration:

  1. (simple) Use the connection string which can be obtained from the App Configuration Dashboard under 'Access keys'. If the connection string is invalid or not specified, an ArgumentError will occur.

  2. (complex) Use the factory constructor AzureAppConfig.customAuthentication() which enables you to provide a custom way of signing requests.

Example

Example 1: Creating an instance of AzureAppConfig

import 'package:azure_app_config/azure_app_config.dart';

void main() {
  // Creating an instance needs a connection String. This can be
  // obtained through the Azure Portal, under "Access Keys".
  final service = AzureAppConfig(connectionString: '<CONNECTION_STRING>');

  // Use the service instance to interact with Azure App Configuration.
  // ...
}

Example 2: Retrieving a key value from Azure App Configuration

import 'package:azure_app_config/azure_app_config.dart';

void main() async {
  const exampleKey = 'example_key';
  const exampleLabel = 'example_label';

  final service = AzureAppConfig(connectionString: '<CONNECTION_STRING>');

  // Getting a key value.
  try {
    final keyValue = await service.getKeyValue(key: exampleKey, label: exampleLabel);
    // Use the keyValue instance to retrieve any property of the key value.
    // ...
  } catch (err) {
    // Handle any exceptions that might occur when interacting with the Azure
    // service.
  }
}

Example 3: Retrieving a feature flag from Azure App Configuration

import 'dart:developer' as developer;

import 'package:azure_app_config/azure_app_config.dart';

void main() async {
  const exampleKey = 'example_key';
  const exampleLabel = 'example_label';

  final service = AzureAppConfig(connectionString: '<CONNECTION_STRING>');
  
  final keyValue = await service.getKeyValue(key: exampleKey, label: exampleLabel);

  // If the KeyValue is a FeatureFlag, you can use .asFeatureFlag()
  // to get the properties of the FeatureFlag
  final featureFlag = keyValue.asFeatureFlag();

  // .asFeatureFlag() will return null if it's unable to parse.
  if (featureFlag != null) {
    // To check if the featureflag is enabled, use
    developer.log('${featureFlag.enabled}');
  }
} 

Example 4: Retrieving a feature flag with feature filters from Azure App Configuration

import 'dart:developer' as developer;

import 'package:azure_app_config/azure_app_config.dart';

void main() async {
  const exampleKey = 'example_key';
  const exampleLabel = 'example_label';

  final service = AzureAppConfig(connectionString: '<CONNECTION_STRING>');

  // Register a FeatureFilter before using it.
  service.registerFeatureFilter(
    FeatureFilter.targeting(
      user: 'test.user@company.com',
    ),
  );
  
  try {
    // getFeatureEnabled() will take the feature filters into account when evaluating. 
    final isFeatureEnabled = await service.getFeatureEnabled(key: exampleKey, label: exampleLabel);

    developer.log('$isFeatureEnabled');
  } catch (err) {
    // Handle any exceptions that might occur when interacting with the Azure
    // service.
  }
}

Example 5: Finding key values based on a key and label filter

import 'dart:developer' as developer;

import 'package:azure_app_config/azure_app_config.dart';

void main() async {
  final service = AzureAppConfig(connectionString: '<CONNECTION_STRING>');

  try {
    // Find key values based on a key and label filter.
    // This example searches for the keyValues that start with '.appconfig.'
    // without a label.
    final keyValues = await service.findKeyValuesBy(
      key: '.appconfig.*',
      label: AzureFilters.noLabel,
    );

    // Loop through the values.
    for (final keyValue in keyValues) {
      developer.log(keyValue.value);
      // Use the keyValue instance to retrieve any property of the key value.
      // ...
    }
  } on AzureFilterValidationException catch (e) {
    // When an invalid filter has been provided, for example, '.appconfig.**',
    // an [AzureFilterValidationException] is thrown.
    developer.log(e.errorResponse.detail ?? 'Error occurred!');
  } catch (err) {
    // Handle any exceptions that might occur when interacting with the Azure
    // service.
  }
}

Complex Types

You are able to register types with their associated encode and decode functions. After registering the types, the library will automatically use those functions to retrieve/set values in the database.

class TimeRange {
    String start;
    String end;
    TimeRange(this.start, this.end);
    factory TimeRange.fromJson(Map<String, dynamic>)
    Map<String, dynamic> toMap() => {'start': start, 'end': end}
}

...

// Register a type, so that the library knows how to encode and decode the model
service.registerType<TimeRange>(
  decode: (jsonData) => TimeRange.fromJson(jsonData),
  encode: (timeRange) => timeRange.toMap(),
);

// Uses the passed-in [encode] method to know the json structure to use.
await service.setTyped(
    TimeRange('Monday', 'Friday'),
    key: 'time_range',
    label: 'some_label',
);

// Uses the passed-in [decode] method to know how to serialize [TimeRange]
final timeRange = await service.getTyped<TimeRange>(
    key: 'time_range',
    label: 'some_label',
); 

FeatureFilters

This package currently has 2 built-in FeatureFilters based on the defaults which can be found in the App Configuration dashboard:

Microsoft.Targeting -> Enable a flag based on some Targeting parameters which can be found in the Azure dashboard.

Microsoft.TimeWindow -> Enable a feature flag during a specified window of time.

Make sure to register the FeatureFilter before retrieving a feature's value.
service.registerFeatureFilter(FeatureFilter.timeWindow()) or
service.registerFeatureFilter(FeatureFilter.targeting()).

Implement your own FeatureFilter

This package enables you to create custom FeatureFilters by extending the FeatureFilter class. An example of this can be found by looking at how the built-in FeatureFilters are implemented here.

More Information

For more information about Azure App Configuration, take a look at the following resources.

Feel free to submit any pull requests!

所屬分類

依賴

依賴清單 6 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。