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

square / keywhiz / 4555816003

pending completion
4555816003

Pull #1205

github

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

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

5385 of 7159 relevant lines covered (75.22%)

0.75 hits per line

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

88.0
/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 javax.ws.rs.BadRequestException;
21
import javax.ws.rs.NotFoundException;
22
import keywhiz.cli.configs.UndeleteActionConfig;
23
import keywhiz.client.KeywhizClient;
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
      keywhizClient.undeleteSecret(id);
1✔
60
    } catch (BadRequestException e) {
1✔
61
      throw new AssertionError("Bad Request: " + e.getMessage());
1✔
62
    } catch (NotFoundException e) {
1✔
63
      throw new AssertionError("No soft-deleted secret with the provided ID was found.");
1✔
64
    } catch (IOException e) {
×
65
      throw new RuntimeException(e);
×
66
    }
1✔
67
  }
1✔
68
}
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