public class GatewayCmdUtils extends Object
| Constructor and Description |
|---|
GatewayCmdUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
buildProjectName(String knownName)
Build the correct current project directory.
|
static void |
copyAndReplaceFolder(String source,
String destination)
This function deletes the existing destination folder and recursively copy all the sub folder and files from
source to destination file paths.
|
static void |
copyFilesToSources(String sourcePath,
String destinationPath)
Copy files to resources directory
|
static void |
copyFolder(String source,
String destination)
This function recursively copy all the sub folder and files from source to destination file paths
|
static void |
createDeploymentConfig(String projectName,
String deploymentConfPath)
Create initial deployment configuration file.
|
static void |
createPerAPIFolderStructure(String projectName,
String apiId)
Create API-Files Directory for a particular project
|
static void |
createProjectStructure(String projectName)
Create a project structure for a particular project name.
|
static CliLauncherException |
createUsageException(String errorMsg)
Create usage exception
|
static String |
decrypt(String value,
String secret)
Decrypt given value with provided secret
|
static void |
deletePerAPIFolder(String projectName,
String apiId)
Delete the subfolder containing metadata and swagger File
|
static void |
deleteProject(String projectPath)
Delete project folder
|
static String |
encrypt(String value,
String secret)
Encrypt given value with provided secret
|
static String |
findCurrentProject()
Find the working project directory set in the
GatewayCliConstants.PROJECT_FILE_NAME
of MGW_HOME. |
static String |
getAPIMetadataFilePath(String projectName,
String apiId)
Returns the path to the metadata for a defined version of an API
|
static String |
getCLIHome()
Get cli home location
|
static String |
getCLILibHashHolderFileLocation()
Get library zip files hash holder file path with in the CLI tool
|
static String |
getCLILibPath()
Get cli library location
|
static CodeGenerationContext |
getCodeGenerationContext() |
static Config |
getConfig() |
static ContainerConfig |
getContainerConfig() |
static APICorsConfigurationDTO |
getDefaultCorsConfig() |
static String |
getDefinitionsLocation()
Get filters folder location
|
static String |
getDeploymentConfigLocation(String projectName)
Returns location of the deployment configuration file of given project
|
static Etcd |
getEtcd() |
static boolean |
getEtcdEnabled(String projectName) |
static String |
getFiltersFolderLocation()
Get filters folder location
|
static String |
getLoggingPropertiesFileLocation()
Get resources file directory path
|
static String |
getMainConfigLocation()
Returns location of the main configuration file of given project root
|
static String |
getPoliciesFolderLocation()
Get policies folder location
|
static String |
getProjectAPIDefinitionsDirectoryPath(String projectName)
Returns path to the /api-definitions of a given project in the current working directory
|
static String |
getProjectAPIFilesDirectoryPath(String projectName)
Returns path to the /API-Files of a given project in the current working directory
|
static String |
getProjectAppThrottlePoliciesFilePath(String projectName)
Returns the path to the application-throttle-policies.yaml for for a defined version of an API
|
static String |
getProjectClientCertMetadataFilePath(String projectName)
Returns the path to the client-cert-metadata.yaml for a defined version of an API
|
static String |
getProjectDirectoryPath(String projectName)
Returns path to the given project in the current working directory
|
static String |
getProjectExtensionsDirectoryPath(String projectName)
Returns path to the /extensions of a given project in the current working directory
|
static String |
getProjectGenDirectoryPath(String projectName)
Returns path to the /gen of a given project in the current working directory
|
static String |
getProjectGenSrcDirectoryPath(String projectName)
Returns path to the /gen/src of a given project in the current working directory
|
static String |
getProjectGenSrcInterceptorsDirectoryPath(String projectName)
Returns path to the /gen/src/interceptors of a given project in the current working directory
|
static String |
getProjectGenSwaggerPath(String projectName,
String apiId)
Returns path to the /gen/api-definition of a given project in the current working directory
|
static String |
getProjectGrpcDirectoryPath()
Returns path to the /grpc_service/client of a given project in the current working directory
|
static String |
getProjectGrpcSoloDirectoryPath()
Returns path to the /grpc_service of a given project in the current working directory
|
static String |
getProjectInterceptorsDirectoryPath(String projectName)
Returns path to the /interceptors of a given project in the current working directory
|
static String |
getProjectMgwDefinitionFilePath(String projectName)
Returns the path to the microgateway definition file (definition.yaml).
|
static String |
getProjectSubscriptionThrottlePoliciesFilePath(String projectName)
Returns the path to the application-throttle-policies.yaml file for a defined version of an API
|
static String |
getProjectSwaggerFilePath(String projectName,
String apiId)
Returns the path to the swagger for a defined version of an API
|
static String |
getResourceFolderLocation()
Get resources file directory path
|
static String |
getSingleArgument(List<String> mainArgs)
Validate the list of main args and returns the first element.
|
static String |
getUnixPath(String path)
Replace backslashes `\` in windows path string with forward slashes `/`
|
static String |
getUserDir()
Returns current user dir
|
static String |
loadStoredResourceHashes(String projectName)
Load the stored resource hash content from the CLI temp folder
|
static String |
makeFirstLetterLowerCase(String s)
Convert first letter to lower case
|
static void |
printVerbose(String msg)
To print the message if verbose flag is set
|
static String |
promptForTextInput(PrintStream outStream,
String msg)
Prompts for a test input.
|
static String |
readFileAsString(String path,
boolean inResource)
Read file as string
|
static Map<String,String> |
readFileToMap(String filePath)
Read the deserialize file content to map.
|
static void |
saveAPIMetadataFile(String projectName,
String apiId,
String apiMetadataYaml) |
static void |
saveConfig(Config config,
String configPath) |
static void |
saveEtcdEnabled(String projectName,
boolean isEnabled) |
static void |
saveSwaggerDefinition(String projectName,
String apiDefinition,
String apiId)
Save openAPI definition (developer first approach)
|
static void |
saveSwaggerDefinitionForMultipleAPIs(String projectName,
List<ExtendedAPI> apis)
Save swagger definition for multiple APIs.
|
static void |
setCodeGenerationContext(CodeGenerationContext codeGenerationContext) |
static void |
setConfig(Config configFromFile) |
static void |
setContainerConfig(ContainerConfig containerConfig) |
static void |
setEtcd(Etcd etcd) |
static void |
storeResourceHashesFileContent(String content,
String projectName)
Saves the resource hash content to the CLI temp folder
|
static void |
writeContent(String content,
File file)
Write content to a specified file
|
static void |
writeMapToFile(Map<String,String> map,
String filePath)
Writes the map after serializing to given path
|
public static Etcd getEtcd()
public static void setEtcd(Etcd etcd)
public static void saveEtcdEnabled(String projectName, boolean isEnabled)
public static boolean getEtcdEnabled(String projectName)
public static Config getConfig()
public static void setConfig(Config configFromFile)
public static CodeGenerationContext getCodeGenerationContext()
public static void setCodeGenerationContext(CodeGenerationContext codeGenerationContext)
public static String readFileAsString(String path, boolean inResource) throws IOException
path - to the fileinResource - whether file is in resources directory of jar or notIOException - if file read went wrongpublic static CliLauncherException createUsageException(String errorMsg)
errorMsg - error messagepublic static String makeFirstLetterLowerCase(String s)
s - stringpublic static String encrypt(String value, String secret)
value - value to encryptsecret - encryption keypublic static String decrypt(String value, String secret)
value - value to decryptsecret - decryption keypublic static String getUserDir()
public static String getCLIHome()
public static String getCLILibPath()
public static String getResourceFolderLocation()
public static String getLoggingPropertiesFileLocation()
public static String getDefinitionsLocation()
public static String getFiltersFolderLocation()
public static String getPoliciesFolderLocation()
public static void createProjectStructure(String projectName) throws IOException
projectName - name of the projectIOExceptionpublic static void saveSwaggerDefinition(String projectName, String apiDefinition, String apiId)
projectName - project nameapiDefinition - api Definition as Stringpublic static void saveSwaggerDefinitionForMultipleAPIs(String projectName, List<ExtendedAPI> apis)
projectName - project nameapis - API object Listpublic static String loadStoredResourceHashes(String projectName) throws IOException
projectName - name of the projectIOException - error while loading stored resource hash contentpublic static void storeResourceHashesFileContent(String content, String projectName) throws IOException
content - resource hash contentprojectName - name of the projectIOException - error while saving resource hash contentpublic static String getSingleArgument(List<String> mainArgs)
mainArgs - List of main args provided to the commandpublic static String getCLILibHashHolderFileLocation()
public static String getMainConfigLocation()
public static String getDeploymentConfigLocation(String projectName)
projectName - name of the projectpublic static String getProjectDirectoryPath(String projectName)
projectName - name of the projectpublic static String getProjectGenDirectoryPath(String projectName)
projectName - name of the projectpublic static String getProjectGenSrcDirectoryPath(String projectName)
projectName - name of the projectpublic static String getProjectExtensionsDirectoryPath(String projectName)
projectName - name of the projectpublic static String getProjectInterceptorsDirectoryPath(String projectName)
projectName - name of the projectpublic static String getProjectGenSrcInterceptorsDirectoryPath(String projectName)
projectName - name of the projectpublic static String getProjectGenSwaggerPath(String projectName, String apiId)
projectName - name of the projectapiId - md5 hash value of apiName:apiVersion
* @return path to the /gen/api-definition of a given project in the current working directorypublic static String getProjectGrpcDirectoryPath()
public static String getProjectGrpcSoloDirectoryPath()
public static String getProjectAPIDefinitionsDirectoryPath(String projectName)
projectName - name of the projectpublic static String getProjectMgwDefinitionFilePath(String projectName)
projectName - name of the projectpublic static void copyFolder(String source, String destination) throws IOException
source - source locationdestination - destination locationIOException - error while copying folder to destinationpublic static void copyAndReplaceFolder(String source, String destination) throws IOException
source - source locationdestination - destination locationIOException - error while copying folder to destinationpublic static void copyFilesToSources(String sourcePath, String destinationPath) throws IOException
sourcePath - source directory pathdestinationPath - destionation directory pathIOException - if file copy went wrongpublic static void writeContent(String content, File file) throws IOException
content - content to be writtenfile - file object initialized with pathIOException - error while writing content to filepublic static void createDeploymentConfig(String projectName, String deploymentConfPath) throws IOException
projectName - project namedeploymentConfPath - path to deployment configIOException - if file create went wrongpublic static ContainerConfig getContainerConfig()
public static void setContainerConfig(ContainerConfig containerConfig)
public static APICorsConfigurationDTO getDefaultCorsConfig()
public static String getUnixPath(String path)
path - Location of a resource (file or directory)public static void deleteProject(String projectPath)
projectPath - project pathpublic static void writeMapToFile(Map<String,String> map, String filePath) throws IOException
map - resource hash content
* @param filePath file path the map should be written toIOException - error while saving resource hash contentpublic static Map<String,String> readFileToMap(String filePath) throws IOException, ClassNotFoundException
filePath - file path the map should be written toIOException - error while saving resource hash contentClassNotFoundExceptionpublic static String promptForTextInput(PrintStream outStream, String msg)
outStream - Print Streammsg - messagepublic static void deletePerAPIFolder(String projectName, String apiId)
projectName - project nameapiId - API IdIOException - If the directory does not existpublic static String findCurrentProject()
GatewayCliConstants.PROJECT_FILE_NAME
of MGW_HOME.null if unable to read project descriptor
or invalid project dir is detectedpublic static String buildProjectName(String knownName)
knownName is a valid project name
it'll take the priority as the project name. If not GatewayCliConstants.PROJECT_FILE_NAME
file value will be taken as the project path. If both are no available error will be thrown.knownName - known project name to prioritizepublic static String getAPIMetadataFilePath(String projectName, String apiId)
projectName - name of the projectapiId - md5 hash value of apiName:apiVersionpublic static String getProjectAPIFilesDirectoryPath(String projectName)
projectName - name of the projectpublic static void saveAPIMetadataFile(String projectName, String apiId, String apiMetadataYaml)
public static String getProjectAppThrottlePoliciesFilePath(String projectName)
projectName - name of the projectpublic static String getProjectSubscriptionThrottlePoliciesFilePath(String projectName)
projectName - name of the projectpublic static String getProjectClientCertMetadataFilePath(String projectName)
projectName - name of the projectpublic static void createPerAPIFolderStructure(String projectName, String apiId)
projectName - name of the projectapiId - md5 hash value for apiName:versionpublic static String getProjectSwaggerFilePath(String projectName, String apiId)
projectName - name of the projectapiId - md5 hash value of apiName:apiVersionpublic static void printVerbose(String msg)
msg - MessageCopyright © 2019 WSO2. All rights reserved.