Skip to content

Commit

Permalink
feat(all): Configure plugins with AmplifyOutputs (#3567)
Browse files Browse the repository at this point in the history
* feat: read and decode AmplifyConfigurationV2

* analytics

* api

* auth

* geo

* logging

* notifications

* storage

* authenticator support

* predictions and coreML

* fixes - String to AWSAuthorizationType, AWSRegion, AmazonCognitoStandardAttributes

* reconcile to latest changes

* Add AWSAPIPluginGen2FunctionalTests

* Revert "logging"

This reverts commit 0df5c34.

* consolidate README

* Auth Integration tests

* fix apiplugin

* storage integ tests

* rename and refactor AmplifyOutputs

* analytics integration tests

* enable more storage tests

* geo integration tests

* logging integration test set up

* AuthHostedUIApp testing with Gen2 set up

* PushNotifications tests with Gen2 set up

* Add Prediction integration test README

* refactor analytics options under the plugin type

* auth flow type mapping

* fix storage behavior - revert to previous behavior

* rename oauth domain to cognito domain and add custom domain override

* unit test around AmplifyOutputsData

* remove authFlowType, add internal init helpers, auth unit tests

* analytics unit tests

* api unit tests

* geo unit tests

* datastore unit tests

* Amplify configure tests

* no changes to InternalAWSPinpoint, removing added init

* fix push notifications unit tests

* predictions plugin does not configure with amplify outputs

* coreMLpredictions unit tests

* storage unit tests

* fix concurrent config unit tests

* update Auth usernameAttributes and userVerificationTypes to enum

* rename analytics options file

* update debug description

* remove unneeded mapping from amplifyconfiguration.json

* add unit test for translating back to json for auth config

* Update Analytics Options properties to use TimeInterval

* fix naming and method signatures

* auth integ test - user username as username

* fix analytics tests

* fix api functional test target

* fix auth integ test target

* fix geo integ test target

* fix logging integ test target

* fix notifications integ test target

* fix storage integ test target

* update README

* update analytics options to remove autoSessionTrackingInterval

* fix commented out username checking

* configure if-else refactor

* update recovery message

* swiftlint disable nesting AmplifyOutputsData

* adding reasoning and link for swiftlint message

* reanble at end of file swiftlint

* feat(api): Expose a constant for the API name used by Gen2 data category (#3631)

* feat(api): Expose a constant for the API name used by Gen2 data category

* update casing on API

* add public

* finalize API
  • Loading branch information
lawmicha authored Apr 25, 2024
1 parent adf5a2e commit f8b9885
Show file tree
Hide file tree
Showing 128 changed files with 5,943 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ extension APICategory: CategoryConfigurable {
try configure(using: categoryConfiguration(from: amplifyConfiguration))
}

func configure(using amplifyOutputs: AmplifyOutputsData) throws {
for plugin in Array(plugins.values) {
try plugin.configure(using: amplifyOutputs)
}
isConfigured = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ extension AnalyticsCategory: CategoryConfigurable {
try configure(using: categoryConfiguration(from: amplifyConfiguration))
}

func configure(using amplifyOutputs: AmplifyOutputsData) throws {
for plugin in Array(plugins.values) {
try plugin.configure(using: amplifyOutputs)
}
isConfigured = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ extension AuthCategory: CategoryConfigurable {
func configure(using amplifyConfiguration: AmplifyConfiguration) throws {
try configure(using: categoryConfiguration(from: amplifyConfiguration))
}

func configure(using amplifyOutputs: AmplifyOutputsData) throws {
for plugin in Array(plugins.values) {
try plugin.configure(using: amplifyOutputs)
}
isConfigured = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ extension DataStoreCategory: CategoryConfigurable {
}
}

func configure(using amplifyConfiguration: AmplifyOutputsData) throws {
try configureFirstWithEmptyConfiguration()
}

func configure(using configuration: CategoryConfiguration?) throws {
guard !isConfigured else {
let error = ConfigurationError.amplifyAlreadyConfigured(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ extension GeoCategory: CategoryConfigurable {
try configure(using: categoryConfiguration(from: amplifyConfiguration))
}

func configure(using amplifyOutputs: AmplifyOutputsData) throws {
for plugin in Array(plugins.values) {
try plugin.configure(using: amplifyOutputs)
}
isConfigured = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@ extension HubCategory: CategoryConfigurable {
try configure(using: categoryConfiguration(from: amplifyConfiguration))
}

func configure(using amplifyOutputs: AmplifyOutputsData) throws {
guard configurationState.get() != .configured else {
let error = ConfigurationError.amplifyAlreadyConfigured(
"\(categoryType.displayName) has already been configured.",
"Remove the duplicate call to `Amplify.configure()`"
)
throw error
}

for plugin in Array(plugins.values) {
try plugin.configure(using: amplifyOutputs)
}
configurationState.set(.configured)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,30 @@ extension LoggingCategory: CategoryConfigurable {
try configure(using: categoryConfiguration(from: amplifyConfiguration))
}

func configure(using amplifyOutputs: AmplifyOutputsData) throws {
let plugin: LoggingCategoryPlugin
switch configurationState {
case .default:
// Default plugin is already assigned, and no configuration is applicable, exit early
configurationState = .configured
return
case .pendingConfiguration(let pendingPlugin):
plugin = pendingPlugin
case .configured:
let error = ConfigurationError.amplifyAlreadyConfigured(
"\(categoryType.displayName) has already been configured.",
"Remove the duplicate call to `Amplify.configure()`"
)
throw error
}

try plugin.configure(using: amplifyOutputs)
self.plugins[plugin.key] = plugin

if plugin.key != AWSUnifiedLoggingPlugin.key, let consolePlugin = try? self.getPlugin(for: AWSUnifiedLoggingPlugin.key) {
try consolePlugin.configure(using: amplifyOutputs)
}

configurationState = .configured
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ extension PushNotificationsCategory: CategoryConfigurable {
func configure(using amplifyConfiguration: AmplifyConfiguration) throws {
try configure(using: categoryConfiguration(from: amplifyConfiguration))
}

func configure(using amplifyOutputs: AmplifyOutputsData) throws {
for plugin in Array(plugins.values) {
try plugin.configure(using: amplifyOutputs)
}
isConfigured = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ extension PredictionsCategory: CategoryConfigurable {
try configure(using: categoryConfiguration(from: amplifyConfiguration))
}

func configure(using amplifyOutputs: AmplifyOutputsData) throws {
for plugin in Array(plugins.values) {
try plugin.configure(using: amplifyOutputs)
}
isConfigured = true
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ extension StorageCategory: CategoryConfigurable {
try configure(using: categoryConfiguration(from: amplifyConfiguration))
}

func configure(using amplifyOutputs: AmplifyOutputsData) throws {
for plugin in Array(plugins.values) {
try plugin.configure(using: amplifyOutputs)
}
isConfigured = true
}
}
4 changes: 2 additions & 2 deletions Amplify/Core/Configuration/AmplifyConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ extension Amplify {

/// Notifies all hub channels that Amplify is configured, in case any plugins need to be notified of the end of the
/// configuration phase (e.g., to set up cross-channel dependencies)
private static func notifyAllHubChannels() {
static func notifyAllHubChannels() {
let payload = HubPayload(eventName: HubPayload.EventName.Amplify.configured)
for channel in HubChannel.amplifyChannels {
Hub.plugins.values.forEach { $0.dispatch(to: channel, payload: payload) }
Expand Down Expand Up @@ -210,7 +210,7 @@ extension Amplify {
}

//// Indicates is the runtime is for SwiftUI Previews
private static var isRunningForSwiftUIPreviews: Bool {
static var isRunningForSwiftUIPreviews: Bool {
ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] != nil
}

Expand Down
Loading

0 comments on commit f8b9885

Please sign in to comment.