Class AstraRc

java.lang.Object
com.dtsx.astra.sdk.utils.AstraRc

public class AstraRc extends Object
Utility class to load/save .astrarc file. This file is used to store Astra configuration.
Author:
Cedrick LUNVEN (@clunven)
  • Field Details

    • ASTRARC_FILENAME

      public static final String ASTRARC_FILENAME
      Default filename we are looking for.
      See Also:
    • ASTRARC_DEFAULT

      public static final String ASTRARC_DEFAULT
      Default filename we are looking for.
      See Also:
    • ENV_USER_HOME

      public static final String ENV_USER_HOME
      Environment variable coding user home.
      See Also:
    • ENV_LINE_SEPERATOR

      public static final String ENV_LINE_SEPERATOR
      line separator.
      See Also:
    • LINE_SEPARATOR

      public static final String LINE_SEPARATOR
      line separator.
    • ASTRA_DB_APPLICATION_TOKEN

      public static final String ASTRA_DB_APPLICATION_TOKEN
      ENV VAR to get part of the token: application token.
      See Also:
  • Constructor Details

    • AstraRc

      public AstraRc()
      Load from ~/.astrarc
    • AstraRc

      public AstraRc(String fileName)
      Load from specified file
      Parameters:
      fileName - String
  • Method Details

    • isDefaultConfigFileExists

      public static boolean isDefaultConfigFileExists()
      Assess if default config exist.
      Returns:
      if default config exists
    • getDefaultConfigurationFileName

      public static String getDefaultConfigurationFileName()
      Build default configuration filename.
      Returns:
      default configuration file name
    • isSectionExists

      public boolean isSectionExists(String sectionName)
      Test session existence.
      Parameters:
      sectionName - section name
      Returns:
      tell if the section exists
    • getSections

      public Map<String,Map<String,String>> getSections()
      Getter accessor for attribute 'sections'.
      Returns:
      current value of 'sections'
    • getSection

      public Map<String,String> getSection(String sectionName)
      Access a session from its name.
      Parameters:
      sectionName - section name
      Returns:
      keys for this section
    • deleteSection

      public boolean deleteSection(String sectionName)
      Delete a section is exist.
      Parameters:
      sectionName - current name.
      Returns:
      if delete or not
    • getSectionKey

      public Optional<String> getSectionKey(String sectionName, String key)
      Read a key for a section
      Parameters:
      sectionName - String
      key - String
      Returns:
      String
    • updateSectionKey

      public void updateSectionKey(String sectionName, String key, String value)
      Update only one key.
      Parameters:
      sectionName - String
      key - String
      value - String
    • renameSection

      public void renameSection(String sectionOld, String sectionNew)
      Renaming a section (if exist)
      Parameters:
      sectionOld - old name
      sectionNew - new section name
    • copySection

      public void copySection(String sectionOld, String sectionNew)
      Copy a section with all those key in another.
      Parameters:
      sectionOld - old section name
      sectionNew - new section name
    • save

      public void save()
      Create configuration file with current sections.
    • renderSections

      public String renderSections()
      Prepare file content
      Returns:
      sections as a string
    • renderSection

      public String renderSection(String sectionName)
      Display section as a string.
      Parameters:
      sectionName - name of section
      Returns:
      section as a string
    • createSectionWithToken

      public void createSectionWithToken(String sectionName, String token)
      Create a section in the configuration file.
      Parameters:
      sectionName - current section name
      token - token to authenticate
    • getConfigFile

      public File getConfigFile()
      Getter accessor for attribute 'configFile'.
      Returns:
      current value of 'configFile'