Exemple #1
0
        protected override void InitializeQosEvent()
        {
            var commandAlias = this.GetType().Name;

            if (this.MyInvocation != null && this.MyInvocation.MyCommand != null)
            {
                commandAlias = this.MyInvocation.MyCommand.Name;
            }

            _qosEvent = new AzurePSQoSEvent()
            {
                CommandName      = commandAlias,
                ModuleName       = this.GetType().Assembly.GetName().Name,
                ModuleVersion    = this.GetType().Assembly.GetName().Version.ToString(),
                ClientRequestId  = this._clientRequestId,
                SessionId        = _sessionId,
                IsSuccess        = true,
                ParameterSetName = this.ParameterSetName
            };

            if (AzVersion == null)
            {
                AzVersion = this.LoadAzVersion();
                UserAgent = new ProductInfoHeaderValue("AzurePowershell", string.Format("Az{0}", AzVersion)).ToString();
                string hostEnv = Environment.GetEnvironmentVariable("AZUREPS_HOST_ENVIRONMENT");
                if (!String.IsNullOrWhiteSpace(hostEnv))
                {
                    UserAgent += string.Format(";{0}", hostEnv.Trim());
                }
            }
            _qosEvent.AzVersion = AzVersion;
            _qosEvent.UserAgent = UserAgent;

            if (this.MyInvocation != null && !string.IsNullOrWhiteSpace(this.MyInvocation.InvocationName))
            {
                _qosEvent.InvocationName = this.MyInvocation.InvocationName;
            }

            if (this.MyInvocation != null && this.MyInvocation.BoundParameters != null &&
                this.MyInvocation.BoundParameters.Keys != null)
            {
                _qosEvent.Parameters = string.Join(" ",
                                                   this.MyInvocation.BoundParameters.Keys.Select(
                                                       s => string.Format(CultureInfo.InvariantCulture, "-{0} ***", s)));
            }

            IAzureContext context;

            _qosEvent.Uid = "defaultid";
            if (TryGetDefaultContext(out context))
            {
                _qosEvent.SubscriptionId = context.Subscription?.Id;
                _qosEvent.TenantId       = context.Tenant?.Id;
                if (context.Account != null && !String.IsNullOrWhiteSpace(context.Account.Id))
                {
                    _qosEvent.Uid = MetricHelper.GenerateSha256HashString(context.Account.Id.ToString());
                }
            }
        }
Exemple #2
0
        public void HashOfValidValueSucceeds()
        {
            string inputValue = "Sample value to hash of suitable length and complexity.";
            var    hash       = MetricHelper.GenerateSha256HashString(inputValue);

            Assert.NotNull(hash);
            Assert.True(hash.Length > 0);
            Assert.NotEqual <string>(inputValue, hash, StringComparer.OrdinalIgnoreCase);
        }
Exemple #3
0
        protected override void InitializeQosEvent()
        {
            var commandAlias = this.GetType().Name;

            if (this.MyInvocation != null && this.MyInvocation.MyCommand != null)
            {
                commandAlias = this.MyInvocation.MyCommand.Name;
            }

            _qosEvent = new AzurePSQoSEvent()
            {
                CommandName      = commandAlias,
                ModuleName       = this.GetType().Assembly.GetName().Name,
                ModuleVersion    = this.GetType().Assembly.GetName().Version.ToString(),
                ClientRequestId  = this._clientRequestId,
                SessionId        = _sessionId,
                IsSuccess        = true,
                ParameterSetName = this.ParameterSetName
            };

            if (this.MyInvocation != null && !string.IsNullOrWhiteSpace(this.MyInvocation.InvocationName))
            {
                _qosEvent.InvocationName = this.MyInvocation.InvocationName;
            }

            if (this.MyInvocation != null && this.MyInvocation.BoundParameters != null &&
                this.MyInvocation.BoundParameters.Keys != null)
            {
                _qosEvent.Parameters = string.Join(" ",
                                                   this.MyInvocation.BoundParameters.Keys.Select(
                                                       s => string.Format(CultureInfo.InvariantCulture, "-{0} ***", s)));
            }

            IAzureContext context;

            if (TryGetDefaultContext(out context) &&
                context.Account != null &&
                !string.IsNullOrWhiteSpace(context.Account.Id))
            {
                _qosEvent.Uid = MetricHelper.GenerateSha256HashString(context.Account.Id.ToString());
            }
            else
            {
                _qosEvent.Uid = "defaultid";
            }
        }
        protected override void InitializeQosEvent()
        {
            base.InitializeQosEvent();

            IAzureContext context;

            _qosEvent.Uid = "defaultid";
            if (RequireDefaultContext() && TryGetDefaultContext(out context))
            {
                _qosEvent.SubscriptionId = context.Subscription?.Id;
                _qosEvent.TenantId       = context.Tenant?.Id;
                if (context.Account != null && !String.IsNullOrWhiteSpace(context.Account.Id))
                {
                    _qosEvent.Uid = MetricHelper.GenerateSha256HashString(context.Account.Id.ToString());
                }
            }
        }
        protected void InitializeQosEvent()
        {
            QosEvent = new AzurePSQoSEvent()
            {
                CmdletType = this.GetType().Name,
                IsSuccess  = true,
            };

            if (this.Profile != null && this.Profile.DefaultSubscription != null)
            {
                QosEvent.Uid = MetricHelper.GenerateSha256HashString(
                    this.Profile.DefaultSubscription.Id.ToString());
            }
            else
            {
                QosEvent.Uid = "defaultid";
            }
        }
Exemple #6
0
        protected override void InitializeQosEvent()
        {
            var commandAlias = this.GetType().Name;

            if (this.MyInvocation != null && this.MyInvocation.MyCommand != null)
            {
                commandAlias = this.MyInvocation.MyCommand.Name;
            }

            QosEvent = new AzurePSQoSEvent()
            {
                CommandName     = commandAlias,
                ModuleName      = this.GetType().Assembly.GetName().Name,
                ModuleVersion   = this.GetType().Assembly.GetName().Version.ToString(),
                ClientRequestId = this._clientRequestId,
                SessionId       = _sessionId,
                IsSuccess       = true,
            };

            if (this.MyInvocation != null && this.MyInvocation.BoundParameters != null)
            {
                QosEvent.Parameters = string.Join(" ",
                                                  this.MyInvocation.BoundParameters.Keys.Select(
                                                      s => string.Format(CultureInfo.InvariantCulture, "-{0} ***", s)));
            }

            if (this.DefaultProfile != null &&
                this.DefaultProfile.Context != null &&
                this.DefaultProfile.Context.Account != null &&
                this.DefaultProfile.Context.Account.Id != null)
            {
                QosEvent.Uid = MetricHelper.GenerateSha256HashString(
                    this.DefaultProfile.Context.Account.Id.ToString());
            }
            else
            {
                QosEvent.Uid = "defaultid";
            }
        }
Exemple #7
0
 public void HashOfNullOrWhitespaceValueReturnsEmptyString()
 {
     Assert.Equal(string.Empty, MetricHelper.GenerateSha256HashString(null));
     Assert.Equal(string.Empty, MetricHelper.GenerateSha256HashString(string.Empty));
     Assert.Equal(string.Empty, MetricHelper.GenerateSha256HashString(" "));
 }
Exemple #8
0
 public void HashOfNullValueThrowsAppropriateException()
 {
     Assert.Throws <ArgumentNullException>(() => MetricHelper.GenerateSha256HashString(null));
 }
        protected override void InitializeQosEvent()
        {
            if (MetricData == null)
            {
                MetricData = new MetricData();
            }
            this._metricHelper.LogPIIData = MetricData.LogPIIData;

            var commandAlias = this.GetType().Name;

            if (this.MyInvocation != null && this.MyInvocation.MyCommand != null)
            {
                commandAlias = this.MyInvocation.MyCommand.Name;
            }

            _qosEvent = new PSQoSEvent()
            {
                CommandName      = commandAlias,
                Id               = Menu?.Name,
                Name             = Menu?.Name,
                Title            = Menu?.DisplayName,
                ModuleName       = MetricData.ModuleName ?? $"{this.MyInvocation.MyCommand.ModuleName}",
                ModuleVersion    = MetricData.ModuleVersion ?? $"{this.MyInvocation.MyCommand.Version}",
                UserAgent        = MetricData.UserAgent,
                AppVersion       = MetricData.AppVersion,
                RoleName         = MetricData.RoleName,
                AccountId        = MetricData.AccountId,
                ClientRequestId  = this._clientRequestId,
                SessionId        = _sessionId,
                IsSuccess        = true,
                ParameterSetName = this.ParameterSetName
            };

            if (this.MyInvocation != null && !string.IsNullOrWhiteSpace(this.MyInvocation.InvocationName))
            {
                _qosEvent.InvocationName = this.MyInvocation.InvocationName;
            }

            if (this.MyInvocation != null && this.MyInvocation.BoundParameters != null &&
                this.MyInvocation.BoundParameters.Keys != null)
            {
                _qosEvent.Parameters = string.Join(" ",
                                                   this.MyInvocation.BoundParameters.Keys.Select(
                                                       s => string.Format(CultureInfo.InvariantCulture, "-{0} ***", s)));
            }

            if (!string.IsNullOrWhiteSpace(MetricData.AuthenticatedUserId) &&
                this._metricHelper.LogPIIData)
            {
                _qosEvent.AuthenticatedUserId = MetricData.AuthenticatedUserId;
            }
            if (!string.IsNullOrWhiteSpace(MetricData.UserId) &&
                MetricData.UserId != "defaultid")
            {
                if (this._metricHelper.LogPIIData)
                {
                    _qosEvent.Uid = MetricData.UserId;
                }
                else
                {
                    _qosEvent.Uid = MetricHelper.GenerateSha256HashString(MetricData.UserId);
                }
            }
            else
            {
                _qosEvent.Uid = "defaultid";
            }
        }