(existed, modified *GithubConnection, body map[string]interface{})
| 143 | } |
| 144 | |
| 145 | func (connection *GithubConnection) Merge(existed, modified *GithubConnection, body map[string]interface{}) error { |
| 146 | // There are many kinds of update, we just update all fields simply. |
| 147 | existedTokenStr := existed.Token |
| 148 | existSecretKey := existed.SecretKey |
| 149 | |
| 150 | existed.Name = modified.Name |
| 151 | if _, ok := body["enableGraphql"]; ok { |
| 152 | existed.EnableGraphql = modified.EnableGraphql |
| 153 | } |
| 154 | existed.AppId = modified.AppId |
| 155 | existed.SecretKey = modified.SecretKey |
| 156 | existed.InstallationID = modified.InstallationID |
| 157 | existed.AuthMethod = modified.AuthMethod |
| 158 | existed.Proxy = modified.Proxy |
| 159 | existed.Endpoint = modified.Endpoint |
| 160 | existed.RateLimitPerHour = modified.RateLimitPerHour |
| 161 | |
| 162 | // handle secret |
| 163 | if existSecretKey == "" { |
| 164 | if modified.SecretKey != "" { |
| 165 | // add secret key, store it |
| 166 | existed.SecretKey = modified.SecretKey |
| 167 | } |
| 168 | // doesn't input secret key, pass |
| 169 | } else { |
| 170 | if modified.SecretKey == "" { |
| 171 | // delete secret key |
| 172 | existed.SecretKey = modified.SecretKey |
| 173 | } else { |
| 174 | // update secret key |
| 175 | sanitizeSecretKey := existed.SanitizeSecret().SecretKey |
| 176 | if sanitizeSecretKey == modified.SecretKey { |
| 177 | // change nothing, restore it |
| 178 | existed.SecretKey = existSecretKey |
| 179 | } else { |
| 180 | // has changed, replace it with the new secret key |
| 181 | existed.SecretKey = modified.SecretKey |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // handle tokens |
| 187 | existedTokens := strings.Split(strings.TrimSpace(existedTokenStr), ",") |
| 188 | existedTokenMap := make(map[string]string) // {originalToken:sanitizedToken} |
| 189 | existedSanitizedTokenMap := make(map[string]string) // {sanitizedToken:originalToken} |
| 190 | for _, token := range existedTokens { |
| 191 | existedTokenMap[token] = existed.SanitizeToken(token) |
| 192 | existedSanitizedTokenMap[existed.SanitizeToken(token)] = token |
| 193 | } |
| 194 | |
| 195 | modifiedTokens := strings.Split(strings.TrimSpace(modified.Token), ",") |
| 196 | modifiedTokenMap := make(map[string]string) // {originalToken:sanitizedToken} |
| 197 | for _, token := range modifiedTokens { |
| 198 | modifiedTokenMap[token] = existed.SanitizeToken(token) |
| 199 | } |
| 200 | |
| 201 | var mergedToken []string |
| 202 | mergedTokenMap := make(map[string]struct{}) |
no test coverage detected