protected void WriteComponentApiKey(ApplicationInsightsComponentAPIKey apiKey)
 {
     if (apiKey != null)
     {
         WriteObject(new PSApiKey(apiKey));
     }
 }
Exemplo n.º 2
0
 public ApiKey(ApplicationInsightsComponentAPIKey apiKey)
 {
     Name        = apiKey.Name;
     Key         = apiKey.ApiKey;
     Id          = GetApiKeyId(apiKey);
     CreatedDate = apiKey.CreatedDate;
 }
Exemplo n.º 3
0
        private static string GetApiKeyId(ApplicationInsightsComponentAPIKey apiKey)
        {
            var fullId = apiKey.Id;
            var pos    = fullId.LastIndexOf("/", StringComparison.OrdinalIgnoreCase) + 1;
            var id     = fullId.Substring(pos, fullId.Length - pos);

            return(id);
        }
Exemplo n.º 4
0
        private static void AreEqual(APIKeyRequest request, ApplicationInsightsComponentAPIKey response)
        {
            Assert.Equal(request.Name, response.Name, ignoreCase: true);
            Assert.True(response.LinkedReadProperties.Count >= request.LinkedReadProperties.Count);
            Assert.True(response.LinkedWriteProperties.Count >= request.LinkedWriteProperties.Count);
            foreach (var readaccess in request.LinkedReadProperties)
            {
                Assert.Contains(response.LinkedReadProperties, r => r == readaccess);
            }

            foreach (var writeaccess in request.LinkedWriteProperties)
            {
                Assert.Contains(response.LinkedWriteProperties, w => w == writeaccess);
            }
        }
Exemplo n.º 5
0
        public PSApiKey(ApplicationInsightsComponentAPIKey key)
        {
            this.ApiKey      = key.ApiKey;
            this.CreatedDate = key.CreatedDate;
            this.Id          = key.Id.Split('/')[10];
            this.Description = key.Name;

            List <string> accessPermission = new List <string>();

            ApiKeyRole[] roles = new ApiKeyRole[] {
                ReadTelemetry,
                WriteAnnotations,
                ReadAgentConfiguration
            };

            if (key.LinkedReadProperties != null)
            {
                foreach (var readaccess in key.LinkedReadProperties)
                {
                    var role = ExtraRole(roles, readaccess);
                    if (role != null)
                    {
                        accessPermission.Add(role.roleName);
                    }
                }
            }

            if (key.LinkedWriteProperties != null)
            {
                foreach (var writeAccess in key.LinkedWriteProperties)
                {
                    var role = ExtraRole(roles, writeAccess);
                    if (role != null)
                    {
                        accessPermission.Add(role.roleName);
                    }
                }
            }

            this.Permissions = accessPermission.ToArray();
        }
Exemplo n.º 6
0
 public PSApiKeyTableView(ApplicationInsightsComponentAPIKey key)
     : base(key)
 {
 }