Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
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
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
@@ -0,0 +1,83 @@ | ||
package org.apache.airavata.mft.command.line.sub.swift; | ||
|
||
import org.apache.airavata.mft.api.client.MFTApiClient; | ||
import org.apache.airavata.mft.common.AuthToken; | ||
import org.apache.airavata.mft.credential.stubs.swift.SwiftPasswordSecret; | ||
import org.apache.airavata.mft.credential.stubs.swift.SwiftSecret; | ||
import org.apache.airavata.mft.credential.stubs.swift.SwiftSecretCreateRequest; | ||
import org.apache.airavata.mft.resource.stubs.swift.storage.SwiftStorage; | ||
import org.apache.airavata.mft.resource.stubs.swift.storage.SwiftStorageCreateRequest; | ||
import org.apache.airavata.mft.storage.stubs.storagesecret.StorageSecret; | ||
import org.apache.airavata.mft.storage.stubs.storagesecret.StorageSecretCreateRequest; | ||
import org.apache.airavata.mft.storage.stubs.storagesecret.StorageSecretServiceGrpc; | ||
import picocli.CommandLine; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
@CommandLine.Command(name = "add") | ||
public class SwiftAddSubCommand implements Callable<Integer> { | ||
|
||
@CommandLine.Option(names = {"-n", "--name"}, description = "Storage Name") | ||
private String remoteName; | ||
|
||
@CommandLine.Option(names = {"-c", "--container"}, description = "Swift Container Name") | ||
private String container; | ||
|
||
@CommandLine.Option(names = {"-e", "--endpoint"}, description = "Endpoint Name") | ||
private String endpoint; | ||
|
||
@CommandLine.Option(names = {"-r", "--region"}, description = "Region") | ||
private String region; | ||
|
||
@CommandLine.Option(names = {"-v", "--keystoneversion"}, description = "Keystone Version") | ||
private int keystoneVersion; | ||
|
||
@CommandLine.Option(names = {"-u", "--user"}, description = "User Name (Password Credentials") | ||
private String userName; | ||
|
||
@CommandLine.Option(names = {"-p", "--password"}, description = "Password (Password Credentials") | ||
private String password; | ||
|
||
@CommandLine.Option(names = {"-p", "--projectId"}, description = "Project Id (Password Credentials") | ||
private String projectId; | ||
|
||
@CommandLine.Option(names = {"-d", "--domainId"}, description = "Domain Id (Password Credentials") | ||
private String domainId; | ||
|
||
|
||
@Override | ||
public Integer call() throws Exception { | ||
AuthToken authToken = AuthToken.newBuilder().build(); | ||
|
||
MFTApiClient mftApiClient = MFTApiClient.MFTApiClientBuilder.newBuilder().build(); | ||
|
||
SwiftSecret swiftSecret = mftApiClient.getSecretServiceClient().swift().createSwiftSecret(SwiftSecretCreateRequest.newBuilder() | ||
.setAuthzToken(authToken).setPasswordSecret(SwiftPasswordSecret.newBuilder() | ||
.setUserName(userName) | ||
.setPassword(password) | ||
.setProjectId(projectId) | ||
.setDomainId(domainId).build()).build()); | ||
|
||
System.out.println("Created the swift secret " + swiftSecret.getSecretId()); | ||
|
||
SwiftStorage swiftStorage = mftApiClient.getStorageServiceClient().swift().createSwiftStorage(SwiftStorageCreateRequest.newBuilder() | ||
.setName(remoteName) | ||
.setContainer(container) | ||
.setEndpoint(endpoint) | ||
.setKeystoneVersion(keystoneVersion) | ||
.setRegion(region).build()); | ||
|
||
System.out.println("Created swift storage " + swiftStorage.getStorageId()); | ||
|
||
StorageSecretServiceGrpc.StorageSecretServiceBlockingStub storageSecretClient = mftApiClient.getStorageServiceClient().storageSecret(); | ||
|
||
StorageSecret storageSecret = storageSecretClient.createStorageSecret(StorageSecretCreateRequest.newBuilder() | ||
.setStorageId(swiftStorage.getStorageId()) | ||
.setSecretId(swiftSecret.getSecretId()) | ||
.setType(StorageSecret.StorageType.SWIFT).build()); | ||
|
||
System.out.println("Successfully added Swift remote endpoint"); | ||
|
||
return 0; | ||
} | ||
} |
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
@@ -0,0 +1,7 @@ | ||
package org.apache.airavata.mft.command.line.sub.swift; | ||
|
||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command(name = "remote", subcommands = {SwiftAddSubCommand.class}) | ||
public class SwiftRemoteSubCommand { | ||
} |
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
@@ -0,0 +1,8 @@ | ||
package org.apache.airavata.mft.command.line.sub.swift; | ||
|
||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command(name = "swift", description = "Manage Swift resources and credentials", | ||
subcommands = {SwiftRemoteSubCommand.class}) | ||
public class SwiftSubCommand { | ||
} |
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
@@ -35,6 +35,7 @@ message StorageSecret { | ||
DROPBOX = 5; | ||
GCS = 6; | ||
AZURE = 7; | ||
SWIFT = 8; | ||
} | ||
StorageType type = 4; | ||
} | ||