ServerCacheOfsProvider
public class ServerCacheOfsProvider : BaseProvider
Data provider that combines the ServerProvider and the OfsProvider. The ServerProvider is treated and the main source for all data. The OfsProvider is treated as a cache. So, all create and update operations will be performed on the Absio Broker™ application and then cached in the OFS. All delete operations will be done against both the Absio Broker™ application and the OFS. All read operations will attempt to pull from the OFS (cache) and then from the Absio Broker™ application if not found. Use the ForceLoadFromServer property if you want read operations to skip the cache. NOTE: the read will still cache the value in the OFS. It will simply ensure the data is refreshed from the Absio Broker™ application.
-
A flag that determines the usage of the OfsProvider as a source on read operations. When true, this will skip the OfsProvider and load data from the ServerProvider. However, newly read data will still be cached in the OFS.
Declaration
Swift
public var forceLoadFromServer: Bool
-
Throws
AbsioErrorDeclaration
Swift
public init(apiKey: UUID, serverUrl: URL, applicationName: String, ofsRootDirectory: URL = OfsProvider.defaultOfsURL, partitionDataByUser: Bool = false) throws
Parameters
apiKey
The API Key needed for accessing the Absio Broker application
serverUrl
The URL of the Absio Broker application.
applicationName
A unique name for the application. This is optional, but is helpful if debugging requests on the Absio Broker application.
ofsRootDirectory
The root of OFS
partitionDataByUser
A flag that determines the usage of the OfsProvider as a source on read operations. When true, this will skip the OfsProvider and load data from the ServerProvider. However, newly read data will still be cached in the OFS.
-
Authenticates the user by calling login on both the OfsProvider and the ServerProvider. If the User does not have their KeyFile in the OFS yet, it will be pulled from the server. The KeyRing will be used to authenticate with the Absio Broker application. This will create an authenticated session on the ServerProvider and the OfsProvider. If the KeyFile has not been stored in the OFS yet, you must supply the passphrase. This will throw an exception on failure. When successful the session will be authenticated.
Throws
AbsioError
Declaration
Swift
public func logIn(userId: UUID, password: String?, passphrase: String? = nil) throws -> Promise<Data>
Parameters
userId
The user’s ID.
password
Optional. The user’s password.
passphrase
Optional. The user’s backup credential passphrase. This is used if logging into a device for the first time or if the password is unavailable.
Return Value
The encrypted KeyFile data
-
Uses the provided KeyRing to authenticate with the Absio Broker application.
Throws
AbsioError
Declaration
Swift
public func logIn(keyRing: KeyRing) throws -> Promise<Void>
Parameters
keyRing
The user’s private key ring.
-
Registers a user on the Absio Broker application and then in the OFS. This will throw an exception on failure. When successful the session will be authenticated.
Throws
AbsioError
Declaration
Swift
public func register(password: String, passphrase: String, reminder: String? = nil) throws -> Promise<Data>
Parameters
password
The password used to encrypt the KeyRing portion of the KeyFile.
passphrase
The passphrase used to encrypt the password portion of the KeyFile.
reminder
Optional. The reminder. This can be used to help remember the users passphrase.
Return Value
The encrypted KeyFile data
-
This will change the credentials using the ServerProvider. The resultant KeyFile bytes will be used to update the KeyFile in the Ofs using the OfsProviders OfsKeyFileMapper.
Throws
AbsioError
Declaration
Swift
public func changeCredentials(password: String, passphrase: String, passphraseReminder: String? = nil) throws -> Promise<Data>
Parameters
password
The new password
passphrase
The new passphrase
passphraseReminder
Optional. The reminder to help a user recall their passphrase. Defaults to null.
Return Value
The encrypted KeyFile data
-
Deletes all associated data for the authenticated user. Calls DeleteUser on the ServerProvider and the OfsProvider. NOTE: This cannot be undone. Ensure you really want to perform this operation before doing so. All data related to the user will be removed from the Absio Broker application.
Throws
AbsioErrorDeclaration
Swift
public override func deleteUser() throws -> Promise<Void>
-
This will call GetEvents on the ServerProvider. Gets all ContainerEvents that match the action type, starting id, ending id, container id and type. No parameters are required. If none are supplied this will return all ContainerEvents for all time for the authenticated user. This can be used to synchronize accounts or keep a store up-to-date with the latest container activity related to the user. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Parameters
eventType
The event types you are interested in. Default is all actions
containerId
The container ID to get events for.
containerType
The type field value to get events for. Only will return events with an exact match on the type. Default is null, meaning all events.
startId
The starting event id to process. Defaults to the very first event.
endId
The last event id to process. Defaults to null, meaning get all events since the starting id.
Return Value
A array of events that match the given criteria.
-
This will call GetReminder on the ServerProvider. Gets the reminder for a user. The reminder can be used to help a user recall their passphrase. If the session is authenticated the user ID is not required. If not supplied the authenticated user’s ID will be used.
Throws
AbsioError
Declaration
Swift
public func getReminder(userId: UUID? = nil) throws -> Promise<String>
Parameters
userId
Optional. The user ID. If not supplied the authenticated user’s ID will be used.
Return Value
The user’s reminder.
-
This will check to see if the KeyFile stored in the OFS differs from the KeyFile stored on the Absio Broker application.
Throws
AbsioError
Declaration
Swift
public func needToSyncAccount(userId: UUID) throws -> Promise<Bool>
Parameters
userId
The user ID of the account to check.
Return Value
True if the KeyFile stored in the OFS differs from the KeyFile stored on the Absio Broker application.
-
This pulls the KeyFile from the Absio Broker application, stores it into the OFS and then updates the KeyRing in use on the ServerProvider and the OfsProvider.
Throws
AbsioError
Declaration
Swift
public func synchronizeAccount(passphrase: String, password: String?) throws -> Promise<Void>
Parameters
passphrase
The passphrase used to store the KeyFile on the Absio Broker application.
password
The password used to encrypt the KeyFile on the Absio Broker application.
-
This will end the authenticated session by calling Logout on the ServerProvider and the OfsProvider
Throws
AbsioErrorDeclaration
Swift
public override func logout() throws -> Promise<Void>
-
Creates and persists a new SecuredContainer on the Absio Broker application, caches it in the OFS and returns it. Use the returned value to learn the assigned ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func createContainer(content: Data?, accessLevels: [AccessLevel] = [], type: String? = nil) throws -> Promise<SecuredContainer>
Parameters
content
The container payload.
accessLevels
Optional. This is the defined access for all users. If null, the user creating the container will get full access (ContainerAccessLevel.DefaultOwnerPermissions). If any access is defined then the user creating the container will get the defined access or no access if none is defined. By default this list is null.
type
Optional string used to categorize the Container. Default: nil.
Return Value
The created SecuredContainer.
-
Creates and persists a new SecuredContainer on the Absio Broker application, caches it in the OFS and returns it. Use the returned value to learn the assigned ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func createContainer<T>(content: Data?, customHeaderObject: T?, accessLevels: [AccessLevel] = [], type: String? = nil) throws -> Promise<SecuredContainer> where T : Decodable, T : Encodable
Parameters
content
The container payload.
customHeaderObject
The optional header portion of the container. This Codable object will be serialized. Default: nil.
accessLevels
Optional. This is the defined access for all users. If null, the user creating the container will get full access (ContainerAccessLevel.DefaultOwnerPermissions). If any access is defined then the user creating the container will get the defined access or no access if none is defined. By default this list is null.
type
Optional string used to categorize the Container. Default: nil.
Return Value
The created SecuredContainer.
-
Deletes the container with the given ID from the Absio Broker application and the OFS by calling Delete on the ServerProvider and the OfsProvider. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func deleteContainer(containerId: UUID) throws -> Promise<Void>
Parameters
containerId
The ID of the container.
-
Update the header of the secured container with the given ID on the Absio Broker application and then cache the resulting container in the OFS. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func updateContainerHeader<T>(containerId: UUID, customHeaderObject: T?) throws -> Promise<SecuredContainer> where T : Decodable, T : Encodable
Parameters
containerId
The ID of the container.
customHeaderObject
Optional. The header Codable to be encrypted in the secured container. If not supplied the header will be nil.
Return Value
The updated SecuredContainer.
-
Update the content of the secured container with the given ID on the Absio Broker application and then cache the resulting container in the OFS. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func updateContainerContent(containerId: UUID, content: Data?) throws -> Promise<SecuredContainer>
Parameters
containerId
The ID of the secured container.
content
Optional. The content to be encrypted in the secured container. If not supplied the content will be null.
Return Value
The updated SecuredContainer.
-
Update the content, header, access and type of the secured container with the given ID on the Absio Broker application and then cache the resulting container in the OFS. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func updateContainer<T>(containerId: UUID, content: Data?, customHeaderObject: T?, accessLevels: [AccessLevel] = [], type: String? = nil) throws -> Promise<SecuredContainer> where T : Decodable, T : Encodable
Parameters
containerId
The ID of the secured container.
content
The container payload.
customHeaderObject
The optional header portion of the container. This object will be serialized as JSON. Default: null.
accessLevels
Optional. This is the defined access for all users. If null, the user creating the container will get full access (ContainerAccessLevel.DefaultOwnerPermissions). If any access is defined then the user creating the container will get the defined access or no access if none is defined. By default this list has one access level for creator with default permissions.
type
Optional string used to categorize the Container. Default: nil.
Return Value
The updated SecuredContainer.
-
Update the access of the secured container with the given ID on the Absio Broker application and then cache the resulting container in the OFS. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func updateContainerAccessLevels(containerId: UUID, accessLevels: [AccessLevel] = []) throws -> Promise<Void>
Parameters
containerId
The ID of the secured container.
accessLevels
Optional. This is the defined access for all users. If null, the user updating the container will get full access (ContainerAccessLevel.DefaultOwnerPermissions). If any access is defined then the user creating the container will get the defined access or no access if none is defined. By default this list is null.
Return Value
The updated SecuredContainer.
-
If the ForceLoadFromServer property is false this gets the Container from the OFS. If the ForceLoadFromServer is true or the OFS does not have the container, it is pulled from the server, cached in the OFS and returned to the user. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func getContainer(containerId: UUID) throws -> Promise<Container>
Parameters
containerId
The ID of the secured container.
Return Value
Container with content, header, and container metadata.
-
If the ForceLoadFromServer property is false this gets the Container header from the OFS. If the ForceLoadFromServer is true or the OFS does not have the container, it is pulled from the server, cached in the OFS and returned to the user. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func getContainerHeader(containerId: UUID) throws -> Promise<Header?>
Parameters
containerId
The ID of the secured container.
Return Value
The decrypted header from the container.
-
If the ForceLoadFromServer property is false this gets the Container content from the OFS. If the ForceLoadFromServer is true or the OFS does not have the container, it is pulled from the server, cached in the OFS and returned to the user. Calling this method requires an authenticated session. See logIn for authenticating.
Throws
AbsioError
Declaration
Swift
public override func getContainerContent(containerId: UUID) throws -> Promise<Data?>
Parameters
containerId
The ID of the secured container.
Return Value
The decrypted content from the container.
-
If the ForceLoadFromServer property is false this gets the Container content from the OFS. If the ForceLoadFromServer is true or the OFS does not have the container, it is pulled from the server, cached in the OFS and returned to the user. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func getContainerMetadata(containerId: UUID) throws -> Promise<Container>
Parameters
containerId
The ID of the secured container.
Return Value
The metadata for the requested container.
-
Update the type of the secured container with the given ID on the Absio Broker application and then cache the resulting container in the OFS. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func updateContainerType(containerId: UUID, type: String?) throws -> Promise<Void>
Parameters
containerId
The ID of the secured container.
type
Optional. This is used to categorize the Container. Default: nil.
Return Value
The updated SecuredContainer.
-
Authenticates the user by calling login on both the OfsProvider and the ServerProvider. If the User does not have their KeyFile in the OFS yet, it will be pulled from the server. The KeyRing will be used to authenticate with the Absio Broker application. This will create an authenticated session on the ServerProvider and the OfsProvider. If the KeyFile has not been stored in the OFS yet, you must supply the passphrase. This will throw an exception on failure. When successful the session will be authenticated.
Throws
AbsioError
Declaration
Swift
public func logIn(userId: UUID, password: String?, passphrase: String? = nil, completionHandler: @escaping (Data) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> Self
Parameters
userId
The user’s ID.
password
Optional. The user’s password.
passphrase
Optional. The user’s backup credential passphrase. This is used if logging into a device for the first time or if the password is unavailable.
completionHandler
Completion Handler
errorHandler
Error Handler
queue
Optional. Custom queue to run callback on. If not specified DispatchQueue.main queue will be used
Return Value
The encrypted KeyFile data
-
Uses the provided KeyRing to authenticate with the Absio Broker application.
Throws
AbsioError
Declaration
Swift
public func logIn(keyRing: KeyRing, completionHandler: @escaping () -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> Self
Parameters
keyRing
The user’s private key ring.
completionHandler
Completion Handler
errorHandler
Error Handler
queue
Optional. Custom queue to run callback on. If not specified DispatchQueue.main queue will be used
-
Registers a user on the Absio Broker application and then in the OFS. This will throw an exception on failure. When successful the session will be authenticated.
Throws
AbsioError
Declaration
Swift
public func register(password: String, passphrase: String, reminder: String? = nil, completionHandler: @escaping (Data) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> Self
Parameters
password
The password used to encrypt the KeyRing portion of the KeyFile.
passphrase
The passphrase used to encrypt the password portion of the KeyFile.
reminder
Optional. The reminder. This can be used to help remember the users passphrase.
Return Value
The encrypted KeyFile data
-
This will change the credentials using the ServerProvider. The resultant KeyFile bytes will be used to update the KeyFile in the Ofs using the OfsProviders OfsKeyFileMapper.
Throws
AbsioError
Declaration
Swift
public func changeCredentials(password: String, passphrase: String, passphraseReminder: String? = nil, completionHandler: @escaping (Data) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> Self
Parameters
password
The new password
passphrase
The new passphrase
passphraseReminder
Optional. The reminder to help a user recall their passphrase. Defaults to null.
completionHandler
Completion Handler
errorHandler
Error Handler
queue
Optional. Custom queue to run callback on. If not specified DispatchQueue.main queue will be used
Return Value
The encrypted KeyFile data
-
This will call GetEvents on the ServerProvider. Gets all ContainerEvents that match the action type, starting id, ending id, container id and type. No parameters are required. If none are supplied this will return all ContainerEvents for all time for the authenticated user. This can be used to synchronize accounts or keep a store up-to-date with the latest container activity related to the user. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Parameters
eventType
The event types you are interested in. Default is all actions
containerId
The container ID to get events for.
containerType
The type field value to get events for. Only will return events with an exact match on the type. Default is null, meaning all events.
startId
The starting event id to process. Defaults to the very first event.
endId
The last event id to process. Defaults to null, meaning get all events since the starting id.
completionHandler
Completion Handler
errorHandler
Error Handler
queue
Optional. Custom queue to run callback on. If not specified DispatchQueue.main queue will be used
Return Value
A array of events that match the given criteria.
-
This will call GetReminder on the ServerProvider. Gets the reminder for a user. The reminder can be used to help a user recall their passphrase. If the session is authenticated the user ID is not required. If not supplied the authenticated user’s ID will be used.
Throws
AbsioError
Declaration
Swift
public func getReminder(userId: UUID? = nil, completionHandler: @escaping (String) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> Self
Parameters
userId
Optional. The user ID. If not supplied the authenticated user’s ID will be used.
Return Value
The user’s reminder.
-
This will check to see if the KeyFile stored in the OFS differs from the KeyFile stored on the Absio Broker application.
Throws
AbsioError
Declaration
Swift
public func needToSyncAccount(userId: UUID, completionHandler: @escaping (Bool) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> Self
Parameters
userId
The user ID of the account to check.
completionHandler
Completion Handler
errorHandler
Error Handler
queue
Optional. Custom queue to run callback on. If not specified DispatchQueue.main queue will be used
Return Value
True if the KeyFile stored in the OFS differs from the KeyFile stored on the Absio Broker application.
-
This pulls the KeyFile from the Absio Broker application, stores it into the OFS and then updates the KeyRing in use on the ServerProvider and the OfsProvider.
Throws
AbsioError
Declaration
Swift
public func synchronizeAccount(passphrase: String, password: String?, completionHandler: @escaping () -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> Self
Parameters
passphrase
The passphrase used to store the KeyFile on the Absio Broker application.
password
The password used to encrypt the KeyFile on the Absio Broker application.
completionHandler
Completion Handler
errorHandler
Error Handler
queue
Optional. Custom queue to run callback on. If not specified DispatchQueue.main queue will be used