• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

trydofor / professional-wings / #125

31 Aug 2024 04:46AM UTC coverage: 63.579% (+0.7%) from 62.919%
#125

push

web-flow
Merge pull request #290 from trydofor/develop

3.2.130

1428 of 2191 new or added lines in 106 files covered. (65.18%)

41 existing lines in 24 files now uncovered.

12923 of 20326 relevant lines covered (63.58%)

0.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.64
/wings/slardar/src/main/java/pro/fessional/wings/slardar/notice/DingTalkConf.java
1
package pro.fessional.wings.slardar.notice;
2

3
import lombok.Data;
4
import org.jetbrains.annotations.NotNull;
5
import org.jetbrains.annotations.Nullable;
6
import pro.fessional.mirana.cond.IfSetter;
7
import pro.fessional.wings.silencer.encrypt.SecretProvider;
8
import pro.fessional.wings.silencer.support.PropHelper;
9
import pro.fessional.wings.slardar.jackson.AesString;
10

11
import java.util.HashMap;
12
import java.util.Map;
13

14
/**
15
 * @author trydofor
16
 * @since 2023-02-21
17
 */
18
@Data
19
public class DingTalkConf {
20

21
    public static final String MsgText = "text";
22
    public static final String MsgMarkdown = "markdown";
23

24
    /**
25
     * the dryrun prefix of subject. merge if null, `empty` means disable.
26
     */
27
    private String dryrun;
28

29
    /**
30
     * template of DingTalk webhook URL.
31
     */
32
    private String webhookUrl = "";
33

34
    /**
35
     * secret of message digest, `empty` means disable.
36
     */
37
    @AesString(SecretProvider.Config)
38
    private String digestSecret = "";
39

40
    /**
41
     * the DingTalk access_token used to send the alert, `empty` means disable.
42
     */
43
    @AesString(SecretProvider.Config)
44
    private String accessToken = "";
45

46
    /**
47
     * custom keywords, to successfully send  message must contain at least 1 keyword.
48
     */
49
    private String noticeKeyword = "";
50

51
    /**
52
     * message type, support `text`|`markdown`
53
     */
54
    private String msgType = MsgMarkdown;
55

56
    /**
57
     * notified person and his phone number, non-member's phone number will be desensitized.
58
     * It is automatically added to the text eg. @155xxxx
59
     */
60
    private Map<String, String> noticeMobiles = new HashMap<>();
61

62
    @Nullable
63
    public String getValidWebhook() {
64
        if (webhookUrl == null || webhookUrl.isEmpty()) return null;
1✔
65

66
        if (webhookUrl.endsWith("=")) {
1✔
67
            return (accessToken == null || accessToken.isEmpty()) ? null : webhookUrl + accessToken;
1✔
68
        }
69
        else {
70
            return webhookUrl;
×
71
        }
72
    }
73

74
    public static final IfSetter<DingTalkConf, DingTalkConf> ConfSetter = (thiz, that, absent, present) -> {
1✔
75
        if (that == null) return thiz;
1✔
76

77
        if (absent == IfSetter.Absent.Invalid) {
1✔
78
            if (thiz.dryrun == null) thiz.dryrun = that.dryrun;
1✔
79
            if (PropHelper.invalid(thiz.webhookUrl)) thiz.webhookUrl = that.webhookUrl;
1✔
80
            if (PropHelper.invalid(thiz.digestSecret)) thiz.digestSecret = that.digestSecret;
1✔
81
            if (PropHelper.invalid(thiz.accessToken)) thiz.accessToken = that.accessToken;
1✔
82
            if (PropHelper.invalid(thiz.noticeKeyword)) thiz.noticeKeyword = that.noticeKeyword;
1✔
83
            if (PropHelper.invalid(thiz.msgType)) thiz.msgType = that.msgType;
1✔
84
            PropHelper.mergeToInvalid(thiz.noticeMobiles, that.noticeMobiles);
1✔
85
        }
86
        else {
NEW
87
            thiz.dryrun = that.dryrun;
×
NEW
88
            thiz.webhookUrl = that.webhookUrl;
×
NEW
89
            thiz.digestSecret = that.digestSecret;
×
NEW
90
            thiz.accessToken = that.accessToken;
×
NEW
91
            thiz.noticeKeyword = that.noticeKeyword;
×
NEW
92
            thiz.msgType = that.msgType;
×
NEW
93
            thiz.noticeMobiles.putAll(that.noticeMobiles);
×
94
        }
95

96
        return thiz;
1✔
97
    };
98

99
    public interface Loader {
100
        /**
101
         * load config by its name (non-empty)
102
         */
103
        @Nullable
104
        DingTalkConf load(@NotNull String name);
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc