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

square / keywhiz / 4568744565

pending completion
4568744565

push

github

GitHub
Merge pull request #1205 from square/chloeb/implement-undelete

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 javax.ws.rs.NotSupportedException;
21
import keywhiz.cli.configs.UndeleteActionConfig;
22
import keywhiz.client.KeywhizClient;
23
import okhttp3.Response;
24
import org.apache.http.HttpStatus;
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

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

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

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

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

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

47
    String trimmedType = type.toLowerCase().trim();
1✔
48
    switch (trimmedType) {
1✔
49
      case "secret":
50
        undeleteSecret(id);
1✔
51
        break;
1✔
52
      case "group":
53
      case "client":
54
        throw new UnsupportedOperationException(
1✔
55
            "Undeletion is not supported for object type: " + trimmedType);
56
      default:
57
        throw new IllegalArgumentException("Invalid undelete type specified: " + trimmedType);
1✔
58
    }
59
  }
1✔
60

61
  private void undeleteSecret(Long id) {
62
    logger.info("Undeleting secret '{}'.", id);
1✔
63
    try {
64
      Response response = keywhizClient.undeleteSecret(id);
1✔
65
      if (response.code() == HttpStatus.SC_OK) {
1✔
66
        logger.info("Successfully undeleted secret '{}'.", id);
1✔
67
      } else {
68
        logger.error("Failed to undelete secret '{}'. Message: \"{}\". Body: {}", id,
1✔
69
            response.message(), response.body().string());
1✔
70
        throw new AssertionError(response.message());
1✔
71
      }
72
    } catch (IOException e) {
×
73
      throw new RuntimeException(e);
×
74
    }
1✔
75
  }
1✔
76
}
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