Class ScriptRepository

java.lang.Object
com.illumon.iris.db.util.scripts.ScriptRepository
All Implemented Interfaces:
ScriptPathLoader

public class ScriptRepository extends Object implements ScriptPathLoader

A ScriptPathLoader that loads scripts from a git repository.

If this class is created with updateEnabled = false it loads scripts as if no git repository was present.

  • Method Details

    • getName

      public String getName()
      Get the name of this repository defined by the iris.scripts.repos property.
      Returns:
      The name of this repo.
    • getGroupNames

      public Set<String> getGroupNames()
      Get the users allowed to access this repo, defined by the iris.scripts.repo.[name].users property.
      Returns:
      The names of all users allowed to access the repo.
    • getState

      public ScriptPathLoaderState getState()
      Get a state object that represents the current branch HEAD commit.
      Specified by:
      getState in interface ScriptPathLoader
      Returns:
      The current branch HEAD or null if updates were disabled.
    • makeState

      public ScriptPathLoaderState makeState(@NotNull String stateJSON)
      Description copied from interface: ScriptPathLoader
      Create a stat object from the serialized JSON String provided by ScriptPathLoaderState.encodeJSON()
      Specified by:
      makeState in interface ScriptPathLoader
      Parameters:
      stateJSON - the JSON state
      Returns:
      the deserialized object from the JSON state
    • lock

      public void lock()
      Description copied from interface: ScriptPathLoader
      Acquire a read lock. Use before invoking any of the get* methods, and hold for as long as consistency is required for this loader.
      Specified by:
      lock in interface ScriptPathLoader
    • unlock

      public void unlock()
      Description copied from interface: ScriptPathLoader
      Release a previously acquired read lock.
      Specified by:
      unlock in interface ScriptPathLoader
    • getAvailableScriptDisplayPaths

      public Set<String> getAvailableScriptDisplayPaths()
      Specified by:
      getAvailableScriptDisplayPaths in interface ScriptPathLoader
      Returns:
      The display paths currently available from this loader.
    • getScriptBodyByDisplayPath

      public String getScriptBodyByDisplayPath(@NotNull String displayPath) throws IOException
      Get the body of a script file via the display path.
      Specified by:
      getScriptBodyByDisplayPath in interface ScriptPathLoader
      Parameters:
      displayPath - The display path to load a script for.
      Returns:
      A String representing the body of the script.
      Throws:
      IOException - If the file is not accessible.
    • getScriptBodyByRelativePath

      public String getScriptBodyByRelativePath(@NotNull String relativePath) throws IOException
      Get the body of a script file via the relative path.
      Specified by:
      getScriptBodyByRelativePath in interface ScriptPathLoader
      Parameters:
      relativePath - The relative path to load a script for.
      Returns:
      A String representing the body of the script
      Throws:
      IOException - If the file is not accessible
    • getAvailableScriptDisplayPaths

      public Set<String> getAvailableScriptDisplayPaths(ScriptPathLoaderState state) throws IOException
      Description copied from interface: ScriptPathLoader
      Gets the display paths available from this loader when it was in the specified state.
      Specified by:
      getAvailableScriptDisplayPaths in interface ScriptPathLoader
      Parameters:
      state - The state of the loader to use when retrieving the list.
      Returns:
      A list of all display paths available when the loader was in the specified state.
      Throws:
      IOException - If a problem occurred loading the script.
    • getScriptBodyByRelativePath

      public String getScriptBodyByRelativePath(String relativePath, ScriptPathLoaderState state) throws IOException
      Description copied from interface: ScriptPathLoader
      Get the specified script at the specified state.
      Specified by:
      getScriptBodyByRelativePath in interface ScriptPathLoader
      Parameters:
      relativePath - The relative path to the script.
      state - The state of the loader.
      Returns:
      The script at relativePath at the specified state.
      Throws:
      IOException - If a problem occurred loading the script.
    • getScriptBodyByDisplayPath

      public String getScriptBodyByDisplayPath(String displayPath, ScriptPathLoaderState state) throws IOException
      Description copied from interface: ScriptPathLoader
      Get the specified script at the specified state.
      Specified by:
      getScriptBodyByDisplayPath in interface ScriptPathLoader
      Parameters:
      displayPath - The display path to the script.
      state - The state of the loader.
      Returns:
      The script at displayPath at the specified state.
      Throws:
      IOException - If a problem occurred loading the script.
    • refresh

      public void refresh()
      Description copied from interface: ScriptPathLoader
      Refresh the loader internally. Will respect existing read locks.
      Specified by:
      refresh in interface ScriptPathLoader
    • close

      public void close()
      Description copied from interface: ScriptPathLoader
      Free resources associated with this loader.
      Specified by:
      close in interface ScriptPathLoader
    • readRepoConfigs

      public static List<ScriptRepository> readRepoConfigs(@NotNull com.fishlib.configuration.Configuration config, @NotNull String propertyPrefix, @NotNull com.fishlib.io.logger.Logger log, boolean globalUpdateEnabled, boolean globalGcEnabled, @Nullable String defaultBranch, boolean resetGitLockFiles)
    • readRepoConfigsForUser

      public static List<ScriptRepository> readRepoConfigsForUser(@NotNull com.fishlib.configuration.Configuration config, @NotNull String propertyPrefix, @NotNull com.fishlib.io.logger.Logger log, @NotNull String userName, @NotNull IrisGroupProvider groupProvider)
    • readRepoConfigsForUser

      public static List<ScriptRepository> readRepoConfigsForUser(@NotNull com.fishlib.configuration.Configuration config, @NotNull String propertyPrefix, @NotNull com.fishlib.io.logger.Logger log, @NotNull String userName)