Exemple #1
0
        private static ScopeData?ValidateScope(SemanticModel semanticModel, LogInvalidScopeDiagnostic logInvalidScopeFunc, ResourceScope supportedScopes, SyntaxBase bodySyntax, SyntaxBase?scopeValue)
        {
            if (scopeValue is null)
            {
                // no scope provided - use the target scope for the file
                if (!supportedScopes.HasFlag(semanticModel.TargetScope))
                {
                    logInvalidScopeFunc(bodySyntax, semanticModel.TargetScope, supportedScopes);
                    return(null);
                }

                return(null);
            }

            var(scopeSymbol, indexExpression) = scopeValue switch
            {
                // scope indexing can only happen with references to module or resource collections
                ArrayAccessSyntax {
                    BaseExpression : VariableAccessSyntax baseVariableAccess
                } arrayAccess => (semanticModel.GetSymbolInfo(baseVariableAccess), arrayAccess.IndexExpression),
                ArrayAccessSyntax {
                    BaseExpression : ResourceAccessSyntax baseVariableAccess
                } arrayAccess => (semanticModel.GetSymbolInfo(baseVariableAccess), arrayAccess.IndexExpression),

                // all other scope expressions
                _ => (semanticModel.GetSymbolInfo(scopeValue), null)
            };

            var scopeType = semanticModel.GetTypeInfo(scopeValue);

            switch (scopeType)
            {
            case TenantScopeType type:
                if (!supportedScopes.HasFlag(ResourceScope.Tenant))
                {
                    logInvalidScopeFunc(scopeValue, ResourceScope.Tenant, supportedScopes);
                    return(null);
                }

                return(new ScopeData {
                    RequestedScope = ResourceScope.Tenant, IndexExpression = indexExpression
                });

            case ManagementGroupScopeType type:
                if (!supportedScopes.HasFlag(ResourceScope.ManagementGroup))
                {
                    logInvalidScopeFunc(scopeValue, ResourceScope.ManagementGroup, supportedScopes);
                    return(null);
                }

                return(type.Arguments.Length switch
                {
                    0 => new ScopeData {
                        RequestedScope = ResourceScope.ManagementGroup, IndexExpression = indexExpression
                    },
                    _ => new ScopeData {
                        RequestedScope = ResourceScope.ManagementGroup, ManagementGroupNameProperty = type.Arguments[0].Expression, IndexExpression = indexExpression
                    },
                });
Exemple #2
0
        private static ScopeData?ValidateScope(SemanticModel semanticModel, LogInvalidScopeDiagnostic logInvalidScopeFunc, ResourceScope supportedScopes, SyntaxBase bodySyntax, ObjectPropertySyntax?scopeProperty)
        {
            if (scopeProperty is null)
            {
                // no scope provided - use the target scope for the file
                if (!supportedScopes.HasFlag(semanticModel.TargetScope))
                {
                    logInvalidScopeFunc(bodySyntax, semanticModel.TargetScope, supportedScopes);
                    return(null);
                }

                return(null);
            }

            var scopeSymbol = semanticModel.GetSymbolInfo(scopeProperty.Value);
            var scopeType   = semanticModel.GetTypeInfo(scopeProperty.Value);

            switch (scopeType)
            {
            case TenantScopeType type:
                if (!supportedScopes.HasFlag(ResourceScope.Tenant))
                {
                    logInvalidScopeFunc(scopeProperty.Value, ResourceScope.Tenant, supportedScopes);
                    return(null);
                }

                return(new ScopeData {
                    RequestedScope = ResourceScope.Tenant
                });

            case ManagementGroupScopeType type:
                if (!supportedScopes.HasFlag(ResourceScope.ManagementGroup))
                {
                    logInvalidScopeFunc(scopeProperty.Value, ResourceScope.ManagementGroup, supportedScopes);
                    return(null);
                }

                return(type.Arguments.Length switch {
                    0 => new ScopeData {
                        RequestedScope = ResourceScope.ManagementGroup
                    },
                    _ => new ScopeData {
                        RequestedScope = ResourceScope.ManagementGroup, ManagementGroupNameProperty = type.Arguments[0].Expression
                    },
                });
Exemple #3
0
        private static ScopeData?ValidateScope(SemanticModel semanticModel, LogInvalidScopeDiagnostic logInvalidScopeFunc, ResourceScope supportedScopes, SyntaxBase bodySyntax, ObjectPropertySyntax?scopeProperty)
        {
            if (scopeProperty is null)
            {
                // no scope provided - use the target scope for the file
                if (!supportedScopes.HasFlag(semanticModel.TargetScope))
                {
                    logInvalidScopeFunc(bodySyntax, semanticModel.TargetScope, supportedScopes);
                    return(null);
                }

                return(null);
            }

            var scopeSymbol = scopeProperty.Value switch
            {
                // scope indexing can only happen with references to module or resource collections
                ArrayAccessSyntax {
                    BaseExpression : VariableAccessSyntax baseVariableAccess
                } => semanticModel.GetSymbolInfo(baseVariableAccess),