Example #1
0
        /// <summary>
        /// Initializes DurableFunctionsMonitor endpoint with some settings
        /// </summary>
        /// <param name="settings">When null, default settings are used</param>
        public static void Setup(DfmSettings settings = null)
        {
            string dfmNonce            = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_NONCE);
            string dfmAllowedUserNames = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_ALLOWED_USER_NAMES);
            string dfmAllowedAppRoles  = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_ALLOWED_APP_ROLES);
            string dfmMode             = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_MODE);

            _settings = settings ?? new DfmSettings()
            {
                DisableAuthentication = dfmNonce == Auth.ISureKnowWhatIAmDoingNonce,
                Mode             = dfmMode == DfmMode.ReadOnly.ToString() ? DfmMode.ReadOnly : DfmMode.Normal,
                AllowedUserNames = dfmAllowedUserNames == null ? null : dfmAllowedUserNames.Split(','),
                AllowedAppRoles  = dfmAllowedAppRoles == null ? null : dfmAllowedAppRoles.Split(',')
            };
        }
Example #2
0
        /// <summary>
        /// Initializes DurableFunctionsMonitor endpoint with some settings
        /// </summary>
        /// <param name="settings">When null, default settings are used</param>
        /// <param name="extensionPoints">Routines, that can be customized by client code. When null, default instance of DfmExtensionPoints is used</param>
        public static void Setup(DfmSettings settings = null, DfmExtensionPoints extensionPoints = null)
        {
            string dfmNonce = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_NONCE);

            _settings = settings;

            if (_settings == null)
            {
                string dfmAllowedUserNames  = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_ALLOWED_USER_NAMES);
                string dfmAllowedAppRoles   = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_ALLOWED_APP_ROLES);
                string dfmMode              = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_MODE);
                string dfmUserNameClaimName = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_USERNAME_CLAIM_NAME);

                _settings = new DfmSettings()
                {
                    // Don't want to move the below initializatin to DfmSettings's ctor. The idea is: either _everything_ comes
                    // from env variables or _everything_ is configured programmatically. To avoid unclarity we shouldn't mix these two approaches.
                    DisableAuthentication = dfmNonce == Auth.ISureKnowWhatIAmDoingNonce,
                    Mode              = dfmMode == DfmMode.ReadOnly.ToString() ? DfmMode.ReadOnly : DfmMode.Normal,
                    AllowedUserNames  = dfmAllowedUserNames == null ? null : dfmAllowedUserNames.Split(','),
                    AllowedAppRoles   = dfmAllowedAppRoles == null ? null : dfmAllowedAppRoles.Split(','),
                    UserNameClaimName = string.IsNullOrEmpty(dfmUserNameClaimName) ? Auth.PreferredUserNameClaim : dfmUserNameClaimName
                };
            }

            if (extensionPoints != null)
            {
                _extensionPoints = extensionPoints;
            }

            // Also initializing CustomUserAgent value based on input parameters
            if (!string.IsNullOrEmpty(dfmNonce) && (dfmNonce != Auth.ISureKnowWhatIAmDoingNonce))
            {
                _customUserAgent = $"DurableFunctionsMonitor-VsCodeExt/{GetVersion()}";
            }
            else
            {
                _customUserAgent = $"DurableFunctionsMonitor-Injected/{GetVersion()}";
            }
        }