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

square / keywhiz / 4566387339

pending completion
4566387339

Pull #1205

github

GitHub
Merge 7284079f0 into 2bb01dacb
Pull Request #1205: Chloeb/implement undelete

107 of 107 new or added lines in 8 files covered. (100.0%)

5390 of 7169 relevant lines covered (75.18%)

0.75 hits per line

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

88.89
/cli/src/main/java/keywhiz/cli/commands/UndeleteAction.java
1
/*
2
 * Copyright (C) 2015 Square, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package keywhiz.cli.commands;
18

19
import java.io.IOException;
20
import keywhiz.cli.configs.UndeleteActionConfig;
21
import keywhiz.client.KeywhizClient;
22
import okhttp3.Response;
23
import org.apache.http.HttpStatus;
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

27
public class UndeleteAction implements Runnable {
28
  private static final Logger logger = LoggerFactory.getLogger(UndeleteAction.class);
1✔
29

30
  private final UndeleteActionConfig undeleteActionConfig;
31
  private final KeywhizClient keywhizClient;
32

33
  public UndeleteAction(UndeleteActionConfig undeleteActionConfig, KeywhizClient client) {
1✔
34
    this.undeleteActionConfig = undeleteActionConfig;
1✔
35
    this.keywhizClient = client;
1✔
36
  }
1✔
37

38
  @Override public void run() {
39
    String type = undeleteActionConfig.objectType;
1✔
40
    Long id = undeleteActionConfig.id;
1✔
41

42
    if (type == null || type.isEmpty()) {
1✔
43
      throw new IllegalArgumentException("Must specify a type to delete.");
×
44
    }
45

46
    String trimmedType = type.toLowerCase().trim();
1✔
47
    switch (trimmedType) {
1✔
48
      case "secret":
49
        undeleteSecret(id);
1✔
50
        break;
1✔
51
      default:
52
        throw new IllegalArgumentException("Invalid undelete type specified: " + trimmedType);
1✔
53
    }
54
  }
1✔
55

56
  private void undeleteSecret(Long id) {
57
    logger.info("Undeleting secret '{}'.", id);
1✔
58
    try {
59
      Response response = keywhizClient.undeleteSecret(id);
1✔
60
      switch (response.code()) {
1✔
61
        case HttpStatus.SC_OK:
62
          logger.info("Successfully undeleted secret.", id);
1✔
63
          break;
1✔
64
        default:
65
          logger.error(response.message());
1✔
66
          logger.error(response.body().string());
1✔
67
          throw new AssertionError(response.message());
1✔
68
      }
69
    } catch (IOException e) {
×
70
      throw new RuntimeException(e);
×
71
    }
1✔
72
  }
1✔
73
}
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

© 2026 Coveralls, Inc