Skip to content

Commit 74cffde

Browse files
committed
Updates to KMS integration
1 parent c76e7bd commit 74cffde

File tree

11 files changed

+171
-140
lines changed

11 files changed

+171
-140
lines changed

src/main/java/com/godiddy/cli/commands/config/ConfigKmsCommand.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@CommandLine.Command(
1212
name = "kms",
13-
description = "Get or set the key interface for client-managed secret mode. Default value: " + Kms.DEFAULT_KMS + ".",
13+
description = "Get or set the KMS for client-managed secret mode. Default value: " + Kms.DEFAULT_KMS + ".",
1414
mixinStandardHelpOptions = true
1515
)
1616
public class ConfigKmsCommand extends ConfigAbstractCommand implements Callable<Integer> {
@@ -19,34 +19,34 @@ public class ConfigKmsCommand extends ConfigAbstractCommand implements Callable<
1919

2020
@CommandLine.Parameters(
2121
index = "0",
22-
description = "The key interface for client-managed secret mode. Valid values: ${COMPLETION-CANDIDATES}. Default value: " + Kms.DEFAULT_KMS + ".",
22+
description = "The KMS for client-managed secret mode. Valid values: ${COMPLETION-CANDIDATES}. Default value: " + Kms.DEFAULT_KMS + ".",
2323
arity = "0..1"
2424
)
25-
Kms.Value keyInterface;
25+
Kms.Value kms;
2626

2727
@Override
2828
public Integer call() throws Exception {
29-
log.trace("Parameter 'keyInterface': " + this.keyInterface);
29+
log.trace("Parameter 'kms': " + this.kms);
3030
if (Boolean.TRUE.equals(this.delete)) {
3131
CLIConfig.setKms(null);
32-
System.out.println("Key interface setting successfully deleted.");
32+
System.out.println("KMS setting successfully deleted.");
3333
} else {
34-
if (this.keyInterface == null) {
35-
Kms.Value keyInterface = CLIConfig.getKms();
36-
if (keyInterface == null) {
37-
System.out.println("No key interface set.");
34+
if (this.kms == null) {
35+
Kms.Value kms = CLIConfig.getKms();
36+
if (kms == null) {
37+
System.out.println("No KMS set.");
3838
} else {
39-
System.out.println("Key interface: " + keyInterface);
39+
System.out.println("KMS: " + kms);
4040
}
4141
} else {
42-
Kms.Value keyInterface = this.keyInterface;
43-
Kms.Value predefinedKeyInterface = Kms.PREDEFINED_KMS.get(keyInterface.name());
44-
if (predefinedKeyInterface != null) {
45-
System.out.println("Using predefined key interface value '" + predefinedKeyInterface + "' for parameter value '" + keyInterface + "'.");
46-
keyInterface = predefinedKeyInterface;
42+
Kms.Value kms = this.kms;
43+
Kms.Value predefinedKms = Kms.PREDEFINED_KMS.get(kms.name());
44+
if (predefinedKms != null) {
45+
System.out.println("Using predefined KMS value '" + predefinedKms + "' for parameter value '" + kms + "'.");
46+
kms = predefinedKms;
4747
}
48-
CLIConfig.setKms(keyInterface);
49-
System.out.println("Key interface successfully set: " + keyInterface);
48+
CLIConfig.setKms(kms);
49+
System.out.println("KMS successfully set: " + kms);
5050
}
5151
}
5252
return 0;

src/main/java/com/godiddy/cli/commands/registrar/ContinueCommand.java

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,49 +36,6 @@ public Integer call() throws Exception {
3636

3737
// continue
3838

39-
return doContinue(interactive);
40-
}
41-
42-
public static Integer doContinue(boolean interactive) throws Exception {
43-
44-
// request and execute
45-
46-
String method = CLIState.getMethod();
47-
RegistrarRequest nextRequest = CLIState.getNextRequest();
48-
if (nextRequest == null) {
49-
System.err.println("No next request to continue with. Try running \"godiddy-cli state process\" first.");
50-
return 1;
51-
}
52-
53-
Object state;
54-
switch (nextRequest) {
55-
case CreateRequest createRequest -> state = Api.execute(() -> Api.universalRegistrarApi().createWithHttpInfo(method, createRequest));
56-
case UpdateRequest updateRequest -> state = Api.execute(() -> Api.universalRegistrarApi().updateWithHttpInfo(updateRequest));
57-
case DeactivateRequest deactivateRequest -> state = Api.execute(() -> Api.universalRegistrarApi().deactivateWithHttpInfo(deactivateRequest));
58-
case ExecuteRequest executeRequest -> state = Api.execute(() -> Api.universalRegistrarApi().executeWithHttpInfo(executeRequest));
59-
case CreateResourceRequest createResourceRequest -> state = Api.execute(() -> Api.universalRegistrarApi().createResourceWithHttpInfo(createResourceRequest));
60-
case UpdateResourceRequest updateResourceRequest -> state = Api.execute(() -> Api.universalRegistrarApi().updateResourceWithHttpInfo(updateResourceRequest));
61-
case DeactivateResourceRequest deactivateResourceRequest -> state = Api.execute(() -> Api.universalRegistrarApi().deactivateResourceWithHttpInfo(deactivateResourceRequest));
62-
default -> throw new IllegalStateException("Unexpected request class: " + nextRequest.getClass().getName());
63-
}
64-
65-
// store state
66-
67-
CLIState.setMethod(method);
68-
CLIState.setState(state);
69-
CLIState.setPrevRequest(nextRequest);
70-
CLIState.setNextRequest(null);
71-
72-
// interactive?
73-
74-
if (interactive) {
75-
System.out.println();
76-
System.out.println("Interactive mode on. Execute 'godiddy-cli state process' to process the state and prepare the next request.");
77-
return 0;
78-
}
79-
80-
// process state
81-
82-
return StateProcessCommand.doProcess(interactive);
39+
return DoContinue.doContinue(interactive);
8340
}
8441
}

src/main/java/com/godiddy/cli/commands/registrar/CreateCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,6 @@ public Integer call() throws Exception {
151151

152152
// continue
153153

154-
return ContinueCommand.doContinue(interactive);
154+
return DoContinue.doContinue(interactive);
155155
}
156156
}

src/main/java/com/godiddy/cli/commands/registrar/DeactivateCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ public Integer call() throws Exception {
133133

134134
// continue
135135

136-
return ContinueCommand.doContinue(interactive);
136+
return DoContinue.doContinue(interactive);
137137
}
138138
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.godiddy.cli.commands.registrar;
2+
3+
import com.godiddy.api.client.openapi.model.*;
4+
import com.godiddy.cli.clistorage.clistate.CLIState;
5+
import com.godiddy.cli.commands.state.DoProcess;
6+
import com.godiddy.cli.commands.state.StateProcessCommand;
7+
import com.godiddy.cli.config.Api;
8+
9+
public class DoContinue {
10+
11+
public static Integer doContinue(boolean interactive) throws Exception {
12+
13+
// request and execute
14+
15+
String method = CLIState.getMethod();
16+
RegistrarRequest nextRequest = CLIState.getNextRequest();
17+
if (nextRequest == null) {
18+
System.err.println("No next request to continue with. Try running \"godiddy-cli state process\" first.");
19+
return 1;
20+
}
21+
22+
Object state;
23+
switch (nextRequest) {
24+
case CreateRequest createRequest -> state = Api.execute(() -> Api.universalRegistrarApi().createWithHttpInfo(method, createRequest));
25+
case UpdateRequest updateRequest -> state = Api.execute(() -> Api.universalRegistrarApi().updateWithHttpInfo(updateRequest));
26+
case DeactivateRequest deactivateRequest -> state = Api.execute(() -> Api.universalRegistrarApi().deactivateWithHttpInfo(deactivateRequest));
27+
case ExecuteRequest executeRequest -> state = Api.execute(() -> Api.universalRegistrarApi().executeWithHttpInfo(executeRequest));
28+
case CreateResourceRequest createResourceRequest -> state = Api.execute(() -> Api.universalRegistrarApi().createResourceWithHttpInfo(createResourceRequest));
29+
case UpdateResourceRequest updateResourceRequest -> state = Api.execute(() -> Api.universalRegistrarApi().updateResourceWithHttpInfo(updateResourceRequest));
30+
case DeactivateResourceRequest deactivateResourceRequest -> state = Api.execute(() -> Api.universalRegistrarApi().deactivateResourceWithHttpInfo(deactivateResourceRequest));
31+
default -> throw new IllegalStateException("Unexpected request class: " + nextRequest.getClass().getName());
32+
}
33+
34+
// store state
35+
36+
CLIState.setMethod(method);
37+
CLIState.setState(state);
38+
CLIState.setPrevRequest(nextRequest);
39+
CLIState.setNextRequest(null);
40+
41+
// interactive?
42+
43+
if (interactive) {
44+
System.out.println();
45+
System.out.println("Interactive mode on. Execute 'godiddy-cli state process' to process the state and prepare the next request.");
46+
return 0;
47+
}
48+
49+
// process state
50+
51+
return DoProcess.doProcess(interactive);
52+
}
53+
}

src/main/java/com/godiddy/cli/commands/registrar/ExecuteCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ public Integer call() throws Exception {
120120

121121
// continue
122122

123-
return ContinueCommand.doContinue(interactive);
123+
return DoContinue.doContinue(interactive);
124124
}
125125
}

src/main/java/com/godiddy/cli/commands/registrar/UpdateCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,6 @@ public Integer call() throws Exception {
162162

163163
// continue
164164

165-
return ContinueCommand.doContinue(interactive);
165+
return DoContinue.doContinue(interactive);
166166
}
167167
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.godiddy.cli.commands.state;
2+
3+
import com.danubetech.kms.clientkeyinterface.ClientKeyInterface;
4+
import com.danubetech.kms.clientstateinterface.ClientStateInterface;
5+
import com.danubetech.uniregistrar.local.extensions.handlers.HandleStateUpdateTempKeys;
6+
import com.danubetech.uniregistrar.local.extensions.handlers.HandleStateUpdateVerificationMethods;
7+
import com.danubetech.uniregistrar.local.extensions.handlers.action.HandleActionState;
8+
import com.danubetech.uniregistrar.local.extensions.handlers.finished.HandleFinishedStateImportSecretJsonWebKeys;
9+
import com.danubetech.uniregistrar.local.extensions.handlers.finished.HandleFinishedStateImportSecretVerificationMethods;
10+
import com.godiddy.api.client.openapi.model.RegistrarRequest;
11+
import com.godiddy.api.client.openapi.model.RegistrarResourceState;
12+
import com.godiddy.api.client.openapi.model.RegistrarState;
13+
import com.godiddy.cli.clistorage.clistate.CLIState;
14+
import com.godiddy.cli.commands.registrar.ContinueCommand;
15+
import com.godiddy.cli.commands.registrar.DoContinue;
16+
import com.godiddy.cli.config.Api;
17+
import com.godiddy.cli.interfaces.Interfaces;
18+
import com.godiddy.cli.util.MappingUtil;
19+
20+
public class DoProcess {
21+
22+
public static Integer doProcess(boolean interactive) throws Exception {
23+
24+
// load state and next request
25+
26+
Object state = CLIState.getState();
27+
if (state == null) {
28+
System.err.println("No current state for preparing next command.");
29+
return 1;
30+
}
31+
RegistrarRequest prevRequest = CLIState.getPrevRequest();
32+
if (prevRequest == null) {
33+
System.err.println("No previous request for preparing next command.");
34+
return 1;
35+
}
36+
37+
// instantiate client interfaces
38+
39+
ClientKeyInterface<?> clientKeyInterface = Interfaces.instantiateClientKeyInterface();
40+
ClientStateInterface clientStateInterface = Interfaces.instantiateClientStateInterface();
41+
42+
// handle
43+
44+
RegistrarRequest nextRequest = null;
45+
46+
if (state instanceof RegistrarState registrarState) {
47+
uniregistrar.openapi.model.RegistrarState handleState = MappingUtil.map(registrarState);
48+
uniregistrar.openapi.model.RegistrarRequest handlePrevRequest = MappingUtil.map(prevRequest);
49+
50+
HandleStateUpdateVerificationMethods.handleState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
51+
HandleStateUpdateTempKeys.handleState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
52+
HandleFinishedStateImportSecretJsonWebKeys.handleFinishedState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
53+
HandleFinishedStateImportSecretVerificationMethods.handleFinishedState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
54+
uniregistrar.openapi.model.RegistrarRequest handleNextRequest = HandleActionState.handleActionState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
55+
56+
nextRequest = MappingUtil.map(handleNextRequest);
57+
} else if (state instanceof RegistrarResourceState registrarResourceState) {
58+
uniregistrar.openapi.model.RegistrarResourceState handleState = MappingUtil.map(registrarResourceState);
59+
uniregistrar.openapi.model.RegistrarRequest handlePrevRequest = MappingUtil.map(prevRequest);
60+
61+
HandleStateUpdateVerificationMethods.handleState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
62+
HandleStateUpdateTempKeys.handleState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
63+
HandleFinishedStateImportSecretJsonWebKeys.handleFinishedState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
64+
HandleFinishedStateImportSecretVerificationMethods.handleFinishedState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
65+
uniregistrar.openapi.model.RegistrarRequest handleNextRequest = HandleActionState.handleActionState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
66+
67+
nextRequest = MappingUtil.map(handleNextRequest);
68+
}
69+
70+
// save next request
71+
72+
CLIState.setNextRequest(nextRequest);
73+
74+
// state not handled?
75+
76+
if (nextRequest == null) {
77+
return 0;
78+
}
79+
80+
// interactive?
81+
82+
if (interactive) {
83+
Api.print(nextRequest);
84+
System.out.println();
85+
System.out.println("Interactive mode on. Execute 'godiddy-cli continue' to send the next request, or execute 'godiddy-cli state edit-next' to edit it.");
86+
return 0;
87+
}
88+
89+
// continue
90+
91+
return DoContinue.doContinue(interactive);
92+
}
93+
}

src/main/java/com/godiddy/cli/commands/state/StateProcessCommand.java

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -34,78 +34,6 @@ public class StateProcessCommand extends GodiddyAbstractCommand implements Calla
3434
@Override
3535
public Integer call() throws Exception {
3636

37-
return doProcess(true);
38-
}
39-
40-
public static Integer doProcess(boolean interactive) throws Exception {
41-
42-
// load state and next request
43-
44-
Object state = CLIState.getState();
45-
if (state == null) {
46-
System.err.println("No current state for preparing next command.");
47-
return 1;
48-
}
49-
RegistrarRequest prevRequest = CLIState.getPrevRequest();
50-
if (prevRequest == null) {
51-
System.err.println("No previous request for preparing next command.");
52-
return 1;
53-
}
54-
55-
// instantiate client interfaces
56-
57-
ClientKeyInterface<?> clientKeyInterface = Interfaces.instantiateClientKeyInterface();
58-
ClientStateInterface clientStateInterface = Interfaces.instantiateClientStateInterface();
59-
60-
// handle
61-
62-
RegistrarRequest nextRequest = null;
63-
64-
if (state instanceof RegistrarState registrarState) {
65-
uniregistrar.openapi.model.RegistrarState handleState = MappingUtil.map(registrarState);
66-
uniregistrar.openapi.model.RegistrarRequest handlePrevRequest = MappingUtil.map(prevRequest);
67-
68-
HandleStateUpdateVerificationMethods.handleState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
69-
HandleStateUpdateTempKeys.handleState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
70-
HandleFinishedStateImportSecretJsonWebKeys.handleFinishedState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
71-
HandleFinishedStateImportSecretVerificationMethods.handleFinishedState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
72-
uniregistrar.openapi.model.RegistrarRequest handleNextRequest = HandleActionState.handleActionState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
73-
74-
nextRequest = MappingUtil.map(handleNextRequest);
75-
} else if (state instanceof RegistrarResourceState registrarResourceState) {
76-
uniregistrar.openapi.model.RegistrarResourceState handleState = MappingUtil.map(registrarResourceState);
77-
uniregistrar.openapi.model.RegistrarRequest handlePrevRequest = MappingUtil.map(prevRequest);
78-
79-
HandleStateUpdateVerificationMethods.handleState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
80-
HandleStateUpdateTempKeys.handleState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
81-
HandleFinishedStateImportSecretJsonWebKeys.handleFinishedState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
82-
HandleFinishedStateImportSecretVerificationMethods.handleFinishedState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
83-
uniregistrar.openapi.model.RegistrarRequest handleNextRequest = HandleActionState.handleActionState(handlePrevRequest, handleState, clientKeyInterface, clientStateInterface);
84-
85-
nextRequest = MappingUtil.map(handleNextRequest);
86-
}
87-
88-
// save next request
89-
90-
CLIState.setNextRequest(nextRequest);
91-
92-
// state not handled?
93-
94-
if (nextRequest == null) {
95-
return 0;
96-
}
97-
98-
// interactive?
99-
100-
if (interactive) {
101-
Api.print(nextRequest);
102-
System.out.println();
103-
System.out.println("Interactive mode on. Execute 'godiddy-cli continue' to send the next request, or execute 'godiddy-cli state edit-next' to edit it.");
104-
return 0;
105-
}
106-
107-
// continue
108-
109-
return ContinueCommand.doContinue(interactive);
37+
return DoProcess.doProcess(true);
11038
}
11139
}

src/main/java/com/godiddy/cli/config/Kms.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum Value {
2424
"def", Value.valueOf(DEFAULT_KMS)
2525
);
2626

27-
public static Value getKeyInterface() {
27+
public static Value getKms() {
2828
Value kms = Objects.requireNonNullElse(CLIConfig.getKms(), Value.valueOf(DEFAULT_KMS));
2929
if (Value.valueOf(DEFAULT_KMS).equals(kms)) {
3030
log.debug("Using default KMS: " + DEFAULT_KMS);

0 commit comments

Comments
 (0)