Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDDS-3360. Duplicate Ozone Client in renew/cancel token handlers
- Loading branch information
1 parent
1f2255b
commit 480b467
Showing
6 changed files
with
115 additions
and
50 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
hadoop-ozone/dist/src/main/smoketest/security/ozone-secure-token.robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
*** Settings *** | ||
Documentation Test token operations | ||
Library OperatingSystem | ||
Library String | ||
Library BuiltIn | ||
Resource ../commonlib.robot | ||
Test Timeout 5 minutes | ||
|
||
*** Test Cases *** | ||
Get Token | ||
Execute ozone sh token get > /tmp/token.txt | ||
File Should Not Be Empty /tmp/token.txt | ||
|
||
Print Token | ||
${output} = Execute ozone sh token print | ||
Should Not Be Empty ${output} | ||
|
||
Renew Token | ||
${output} = Execute ozone sh token renew | ||
Should contain ${output} Token renewed successfully | ||
|
||
Cancel Token | ||
${output} = Execute ozone sh token cancel | ||
Should contain ${output} Token canceled successfully | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/token/TokenHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.ozone.shell.token; | ||
|
||
import org.apache.hadoop.ozone.client.OzoneClient; | ||
import org.apache.hadoop.ozone.client.OzoneClientFactory; | ||
import org.apache.hadoop.ozone.security.OzoneTokenIdentifier; | ||
import org.apache.hadoop.ozone.shell.Handler; | ||
import org.apache.hadoop.ozone.shell.OzoneAddress; | ||
import org.apache.hadoop.security.token.Token; | ||
import picocli.CommandLine; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Handler for requests with an existing token. | ||
*/ | ||
public abstract class TokenHandler extends Handler { | ||
|
||
@CommandLine.Spec | ||
private CommandLine.Model.CommandSpec spec; | ||
|
||
@CommandLine.Mixin | ||
private TokenOption tokenFile; | ||
private Token<OzoneTokenIdentifier> token; | ||
|
||
@Override | ||
protected boolean isApplicable() { | ||
return securityEnabled(spec.qualifiedName()) && tokenFile.exists(); | ||
} | ||
|
||
@Override | ||
protected OzoneClient createClient(OzoneAddress address) | ||
throws IOException { | ||
token = tokenFile.decode(); | ||
return OzoneClientFactory.getOzoneClient(getConf(), token); | ||
} | ||
|
||
Token<OzoneTokenIdentifier> getToken() { | ||
return token; | ||
} | ||
} |