/// <summary>
        /// Create a new factory using the specified configuration
        /// </summary>
        public LusidApiFactory(ApiConfiguration apiConfiguration)
        {
            if (apiConfiguration == null)
            {
                throw new ArgumentNullException(nameof(apiConfiguration));
            }

            // Validate Uris
            if (!Uri.TryCreate(apiConfiguration.TokenUrl, UriKind.Absolute, out var _))
            {
                throw new UriFormatException($"Invalid Token Uri: {apiConfiguration.TokenUrl}");
            }

            if (!Uri.TryCreate(apiConfiguration.DriveUrl, UriKind.Absolute, out var _))
            {
                throw new UriFormatException($"Invalid LUSID Drive Uri: {apiConfiguration.DriveUrl}");
            }

            // Create configuration
            var tokenProvider = new ClientCredentialsFlowTokenProvider(apiConfiguration);
            var configuration = new TokenProviderConfiguration(tokenProvider)
            {
                BasePath = apiConfiguration.DriveUrl,
            };

            configuration.DefaultHeaders.Add("X-LUSID-Application", apiConfiguration.ApplicationName);

            Init(configuration);
        }
Exemple #2
0
        /// <summary>
        /// Create a new factory using the specified configuration
        /// </summary>
        public LusidApiFactory(ApiConfiguration apiConfiguration)
        {
            if (apiConfiguration == null)
            {
                throw new ArgumentNullException(nameof(apiConfiguration));
            }

            // Validate Uris
            if (!Uri.TryCreate(apiConfiguration.TokenUrl, UriKind.Absolute, out var _))
            {
                throw new UriFormatException($"Invalid Token Uri: {apiConfiguration.TokenUrl}");
            }

            if (!Uri.TryCreate(apiConfiguration.DriveUrl, UriKind.Absolute, out var _))
            {
                if (string.IsNullOrEmpty(apiConfiguration.DriveUrl))
                {
                    throw new ArgumentNullException(
                              nameof(apiConfiguration.DriveUrl),
                              $"Drive Uri missing. Please specify either FBN_DRIVE_API_URL environment variable or driveUrl in secrets.json.");
                }

                throw new UriFormatException($"Invalid LUSID Drive Uri: {apiConfiguration.DriveUrl}");
            }

            // Create configuration
            var tokenProvider = new ClientCredentialsFlowTokenProvider(apiConfiguration);
            var configuration = new TokenProviderConfiguration(tokenProvider)
            {
                BasePath = apiConfiguration.DriveUrl,
            };

            configuration.DefaultHeaders.Add("X-LUSID-Application", apiConfiguration.ApplicationName);

            Init(configuration);
        }