Exemple #1
0
        public async Task <Rule> UpdateRuleAsync(string key, string markdownDescription = null, string markdownNote = null, string name = null, IDictionary <string, string> parameters = null,
                                                 string remediationFnBaseEffort         = null, RemediationFunctionTypes?remediationFnType = null, string remediationFyGapMultiplier = null, Severities?severity = null,
                                                 RuleStatuses?status = null, string[] tags = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(key)]            = key,
                ["markdown_description"] = markdownDescription,
                ["markdown_note"]        = markdownNote,
                [nameof(name)]           = name,
                ["params"] = parameters?.Select(x => $"{x.Key}={x.Value}"),
                ["remediation_fn_base_effort"]     = remediationFnBaseEffort,
                ["remediation_fn_type"]            = RemediationFunctionTypesConverter.ToString(remediationFnType),
                ["remediation_fy_gap_multiplier_"] = remediationFyGapMultiplier,
                [nameof(severity)] = SeveritiesConverter.ToString(severity),
                [nameof(status)]   = RuleStatusesConverter.ToString(status),
                [nameof(tags)]     = tags == null ? null : string.Join(",", tags)
            };

            var response = await GetRulesUrl("create")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseFirstNodeAsync <Rule>(response).ConfigureAwait(false));
        }
Exemple #2
0
        public async Task <Issue> SetIssueSeverityAsync(string issue, Severities severity)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(issue)]    = issue,
                [nameof(severity)] = SeveritiesConverter.ToString(severity)
            };

            var response = await GetIssuesUrl("set_severity")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseFirstNodeAsync <Issue>(response).ConfigureAwait(false));
        }
Exemple #3
0
        public async Task <bool> ActivateQualityProfileRuleAsync(string key, string rule, IDictionary <string, string> parameters = null, bool?reset = null, Severities?severity = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(key)]      = key,
                [nameof(rule)]     = rule,
                ["params"]         = parameters,         // XXX
                [nameof(reset)]    = BooleanConverter.ToString(reset),
                [nameof(severity)] = SeveritiesConverter.ToString(severity)
            };

            var response = await GetQualityProfilesUrl("activate_rule")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseAsync(response).ConfigureAwait(false));
        }
Exemple #4
0
        public async Task <bool> ActivateQualityProfileRulesAsync(string targetKey, bool?activation = null, Severities[] activeSeverities = null, bool?asc          = null,
                                                                  DateTime?availableSince           = null, string[] cwe = null, RuleInheritanceTypes[] inheritance = null, bool?isTemplate = null, string[] languages = null,
                                                                  OwaspTop10Types[] owaspTop10      = null, string q     = null, string qprofile = null, string[] repositories              = null, string ruleKey = null, RuleSortFields?s = null,
                                                                  SansTop25Types[] sansTop25        = null, Severities[] severities = null, SonarSourceSecurityTypes[] sonarSourceSecurity = null, RuleStatuses[] statuses = null,
                                                                  string[] tags = null, Severities?targetSeverity                   = null, string templateKey = null, IssueTypes[] types = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(targetKey)]           = targetKey,
                [nameof(activation)]          = BooleanConverter.ToString(activation),
                ["active_severities"]         = activeSeverities,
                [nameof(asc)]                 = BooleanConverter.ToString(asc),
                ["available_since"]           = DateTimeToStringConverter.ToString(availableSince, "yyyy-MM-dd"),
                [nameof(cwe)]                 = cwe == null ? null : string.Join(",", cwe),
                [nameof(inheritance)]         = inheritance == null ? null : string.Join(",", inheritance.Select(RuleInheritanceTypesConverter.ToString)),
                ["is_template"]               = BooleanConverter.ToString(isTemplate),
                [nameof(languages)]           = languages == null ? null : string.Join(",", languages),
                [nameof(owaspTop10)]          = owaspTop10 == null ? null : string.Join(",", owaspTop10.Select(OwaspTop10TypesConverter.ToString)),
                [nameof(q)]                   = q,
                [nameof(qprofile)]            = qprofile,
                [nameof(repositories)]        = repositories == null ? null : string.Join(",", repositories),
                ["rule_key"]                  = ruleKey,
                [nameof(s)]                   = s == null ? null : string.Join(",", s),
                [nameof(sansTop25)]           = sansTop25 == null ? null : string.Join(",", sansTop25.Select(SansTop25TypesConverter.ToString)),
                [nameof(severities)]          = severities == null ? null : string.Join(",", severities.Select(SeveritiesConverter.ToString)),
                [nameof(sonarSourceSecurity)] = sonarSourceSecurity == null ? null : string.Join(",", sonarSourceSecurity.Select(SonarSourceSecurityTypesConverter.ToString)),
                [nameof(statuses)]            = statuses == null ? null : string.Join(",", statuses.Select(RuleStatusesConverter.ToString)),
                [nameof(tags)]                = tags == null ? null : string.Join(",", tags),
                [nameof(targetSeverity)]      = SeveritiesConverter.ToString(targetSeverity),
                ["template_key"]              = templateKey,
                [nameof(types)]               = types == null ? null : string.Join(",", types.Select(IssueTypesConverter.ToString))
            };

            var response = await GetQualityProfilesUrl("activate_rules")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseAsync(response).ConfigureAwait(false));
        }
Exemple #5
0
        public async Task <Rule> CreateRuleAsync(string customKey, string markdownDescription, string name, IDictionary <string, string> parameters = null, bool?preventReactivation = null,
                                                 Severities?severity = null, RuleStatuses?status = null, string templateKey = null, IssueTypes?type = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                ["custom_key"]           = customKey,
                ["markdown_description"] = markdownDescription,
                [nameof(name)]           = name,
                ["params"] = parameters?.Select(x => $"{x.Key}={x.Value}"),
                ["prevent_reactivation"] = BooleanConverter.ToString(preventReactivation),
                [nameof(severity)]       = SeveritiesConverter.ToString(severity),
                [nameof(status)]         = RuleStatusesConverter.ToString(status),
                ["template_key"]         = templateKey,
                [nameof(type)]           = IssueTypesConverter.ToString(type)
            };

            var response = await GetRulesUrl("create")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseFirstNodeAsync <Rule>(response).ConfigureAwait(false));
        }