internal static ODataTypeAttribute GetODataTypeAttribute(this Cmdlet cmdlet) { if (cmdlet == null) { throw new ArgumentNullException(nameof(cmdlet)); } return(cmdlet.GetType().GetCustomAttribute <ODataTypeAttribute>()); }
/// <summary> /// Gets the noun part of a cmdlet's name. /// </summary> /// <param name="cmdlet">The cmdlet</param> /// <returns>The noun part of the cmdlet's name</returns> internal static string GetCmdletNoun(this Cmdlet cmdlet) { if (cmdlet == null) { throw new ArgumentNullException(nameof(cmdlet)); } return(cmdlet.GetType().GetCustomAttribute <CmdletAttribute>()?.NounName); }
public CmdletLogger(Cmdlet cmdlet) { _cmdlet = cmdlet; _name = (from attr in _cmdlet.GetType().GetCustomAttributes(true) let cmdletattr = attr as CmdletAttribute where null != cmdletattr select cmdletattr.NounName + "-" + cmdletattr.VerbName).FirstOrDefault() ?? "Unknown Cmdlet"; }
public static bool HasParameterAttribute(Cmdlet cmdlet, String parameter) { var property = cmdlet.GetType().GetProperty(parameter); if (property == null) { return(false); } else { var hasAttribute = Attribute.IsDefined(property, typeof(ParameterAttribute)); return(hasAttribute); } }
public static void PerformFieldInjection <T>(this Cmdlet cmdlet) where T : Attribute, IShouldInject { List <PropertyInfo> injectableProperties = cmdlet.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance).Where( p => p.CustomAttributes.Any(a => a.AttributeType == typeof(T))).ToList(); if (injectableProperties.Any()) { foreach (var property in injectableProperties) { // ReSharper disable once SuggestVarOrType_BuiltInTypes string resolverName = property.GetCustomAttribute <T>().Name; var targetType = property.PropertyType; var instance = string.IsNullOrWhiteSpace(resolverName) ? InternalContainer.Container.Value.Resolve(targetType) : InternalContainer.Container.Value.Resolve(targetType, resolverName); property.SetValue(cmdlet, instance); } } }
internal override void Execute() { //SeHelper.GetScreenshotOfWebElement( // SeHelper.GetScreenshotOfCmdletInput( // this, // this.Description, // save, // Left, // Top, // Height, // Width, // this.Path + @"\" + this.Name, // this.As); var save = Cmdlet.GetType().Name == "SaveSeScreenshotCommand"; SeHelper.GetScreenshotOfCmdletInput( Cmdlet, ((SaveSeScreenshotCommand)Cmdlet).Description, save, // 20140111 // ((SaveSeScreenshotCommand)this.Cmdlet).Left, // ((SaveSeScreenshotCommand)this.Cmdlet).Top, // ((SaveSeScreenshotCommand)this.Cmdlet).Height, // ((SaveSeScreenshotCommand)this.Cmdlet).Width, new UIAutomation.ScreenshotRect() { Left = ((SaveSeScreenshotCommand)Cmdlet).Left, Top = ((SaveSeScreenshotCommand)Cmdlet).Top, Height = ((SaveSeScreenshotCommand)Cmdlet).Height, Width = ((SaveSeScreenshotCommand)Cmdlet).Width }, ((SaveSeScreenshotCommand)Cmdlet).Path + @"\" + ((SaveSeScreenshotCommand)Cmdlet).Name, ((SaveSeScreenshotCommand)Cmdlet).As); //Tmx. //} else { // UiaHelper.GetControlScreenshot(this.InputObject, this.Description); //} }
internal static async Task <string> GetManagedIdentityTokenAsync(Cmdlet cmdlet, HttpClient httpClient, string defaultResource) { string requiredScope = null; var requiredScopesAttribute = (RequiredMinimalApiPermissions)Attribute.GetCustomAttribute(cmdlet.GetType(), typeof(RequiredMinimalApiPermissions)); if (requiredScopesAttribute != null) { requiredScope = requiredScopesAttribute.PermissionScopes.First(); if (requiredScope.ToLower().StartsWith("https://")) { var uri = new Uri(requiredScope); requiredScope = $"https://{uri.Host}/"; } else { requiredScope = defaultResource; } } else { requiredScope = defaultResource; } var endPoint = Environment.GetEnvironmentVariable("IDENTITY_ENDPOINT"); var identityHeader = Environment.GetEnvironmentVariable("IDENTITY_HEADER"); if (string.IsNullOrEmpty(endPoint)) { endPoint = Environment.GetEnvironmentVariable("MSI_ENDPOINT"); identityHeader = Environment.GetEnvironmentVariable("MSI_SECRET"); } if (!string.IsNullOrEmpty(endPoint)) { using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, $"{endPoint}?resource={requiredScope}&api-version=2019-08-01")) { requestMessage.Headers.Add("Metadata", "true"); if (!string.IsNullOrEmpty(identityHeader)) { requestMessage.Headers.Add("X-IDENTITY-HEADER", identityHeader); } var response = await httpClient.SendAsync(requestMessage).ConfigureAwait(false); if (response.IsSuccessStatusCode) { var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var responseElement = JsonSerializer.Deserialize <JsonElement>(responseContent); if (responseElement.TryGetProperty("access_token", out JsonElement accessTokenElement)) { return(accessTokenElement.GetString()); } } else { var errorMessage = await response.Content.ReadAsStringAsync().ConfigureAwait(false); throw new PSInvalidOperationException(errorMessage); } } } else { throw new PSInvalidOperationException("Cannot determine Managed Identity Endpoint URL to acquire token."); } return(null); }
private void GetStaticParameters() { staticParameters = ReflectionCacheManager.Get(excludeStaticParameters.GetType()).Properties .Where(p => p.GetAttribute <ParameterAttribute>() != null) .Select(p => p.Property.Name).ToArray(); }