Skip to content

Commit

Permalink
Merge pull request #99 from stewartbryson/stewart
Browse files Browse the repository at this point in the history
Fixes #98. Dependency bumps.
  • Loading branch information
stewartbryson authored Jul 5, 2023
2 parents 3ed58b6 + c19bbbe commit 43111a2
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 153 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/gradle-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
env:
GRADLE_PROPERTIES: ${{secrets.GRADLE_PROPERTIES}}

- id: snowsql_config
- id: credentials_file
run: |
mkdir -p $HOME/.snowsql
echo "$SNOW_CONFIG" > $HOME/.snowsql/config
name: 'Write .snowsql/config file'
mkdir -p $HOME/.snowflake
echo "$SNOW_CONFIG" > $HOME/.snowflake/config.toml
name: 'Write .snowflake/config.toml file'
shell: bash
env:
SNOW_CONFIG: ${{secrets.SNOW_CONFIG}}
Expand Down Expand Up @@ -79,11 +79,11 @@ jobs:
env:
GRADLE_PROPERTIES: ${{secrets.GRADLE_PROPERTIES}}

- id: snowsql_config
- id: credentials_file
run: |
mkdir -p $HOME/.snowsql
echo "$SNOW_CONFIG" > $HOME/.snowsql/config
name: 'Write .snowsql/config file'
mkdir -p $HOME/.snowflake
echo "$SNOW_CONFIG" > $HOME/.snowflake/config.toml
name: 'Write .snowflake/config.toml file'
shell: bash
env:
SNOW_CONFIG: ${{secrets.SNOW_CONFIG}}
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
GRADLE_PROPERTIES: ${{secrets.GRADLE_PROPERTIES}}
- run: |
mkdir -p $HOME/.snowsql
echo "$SNOW_CONFIG" > $HOME/.snowsql/config
name: 'Write .snowsql/config file'
mkdir -p $HOME/.snowflake
echo "$SNOW_CONFIG" > $HOME/.snowflake/config.toml
name: 'Write .snowflake/config.toml file'
shell: bash
env:
SNOW_CONFIG: ${{secrets.SNOW_CONFIG}}
Expand Down Expand Up @@ -93,11 +93,11 @@ jobs:
env:
GRADLE_PROPERTIES: ${{secrets.GRADLE_PROPERTIES}}

- id: snowsql_config
- id: credentials_file
run: |
mkdir -p $HOME/.snowsql
echo "$SNOW_CONFIG" > $HOME/.snowsql/config
name: 'Write .snowsql/config file'
mkdir -p $HOME/.snowflake
echo "$SNOW_CONFIG" > $HOME/.snowflake/config.toml
name: 'Write .snowflake/config.toml file'
shell: bash
env:
SNOW_CONFIG: ${{secrets.SNOW_CONFIG}}
Expand Down
2 changes: 1 addition & 1 deletion examples/groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
}

dependencies {
implementation 'org.codehaus.groovy:groovy:3.0.17'
implementation 'org.codehaus.groovy:groovy:3.0.18'
}

java {
Expand Down
2 changes: 1 addition & 1 deletion examples/java-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ testing {
}
testTask.configure {
failFast true
// which SnowSQL connection to use
// which credentials connection to use
systemProperty 'connection', snowflake.connection
// if this is ephemeral, the test spec needs the name to connect to
if (snowflake.useEphemeral) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ java {
}

dependencies {
implementation 'org.codehaus.groovy:groovy:3.0.17'
implementation 'org.codehaus.groovy:groovy:3.0.18'
implementation 'org.slf4j:slf4j-simple:2.0.7'
implementation 'com.snowflake:snowpark:1.8.0'
implementation 'gradle.plugin.com.redpillanalytics:gradle-properties:1.0.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SnowflakeTest extends Specification {
@Shared
Snowflake snowflake

def "parse snowsql config"() {
def "parse credentials config"() {
given: "a Snowflake class"
snowflake = new Snowflake('gradle_plugin')

Expand Down
161 changes: 83 additions & 78 deletions plugin/src/main/groovy/io/github/stewartbryson/SnowConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,96 @@ import groovy.util.logging.Slf4j
import org.ini4j.Ini

/**
* A class for parsing a SnowSQL config file.
* A class for parsing a credentials config file.
*/
@Slf4j
class SnowConfig {
/**
* The snowsql config file.
*/
File config
/**
* The credentials config file.
*/
File config

/**
* The SnowSQL connection to use.
*/
String connection
/**
* The credentials connection to use.
*/
String connection

/**
* Constructor using auto-detected SnowSQL config file.
*
* @return Snowflake class.
*/
SnowConfig(String connection) {
this.connection = connection
// first look for ~/.snowsql/config
def homeConfig = new File(System.getProperty("user.home").toString() + "/.snowsql/config")
// then look for ./snowconfig
def projectConfig = new File('snow-config')
if (homeConfig.exists()) {
config = homeConfig
} else if (projectConfig.exists()) {
config = projectConfig
} else {
throw new Exception("Unable to find a SnowSQL config file.")
}
log.warn "Using snowsql config file: ${config.absolutePath}"
}
/**
* Constructor using auto-detected credentials config file.
*
* @return Snowflake class.
*/
SnowConfig(String connection) {
this.connection = connection
// first look for ~/.snowflake/config.toml
def snowcli = new File(System.getProperty("user.home").toString() + "/.snowflake/config.toml")
// second look for ./config.toml
def projectConfig = new File('config.toml')
// third look for ~/.snowsql/config
def snowsql = new File(System.getProperty("user.home").toString() + "/.snowsql/config")

/**
* Constructor using explicit SnowSQL config file as a File object.
*
* @return Snowflake class.
*/
SnowConfig(File config, String connection) {
this.connection = connection
this.config = config
}
if (snowcli.exists()) {
config = snowcli
} else if (projectConfig.exists()) {
config = projectConfig
} else if (snowsql.exists()) {
config = snowsql
} else {
throw new Exception("Unable to find a credentials config file.")
}
log.warn "Using credentials config file: ${config.absolutePath}"
}

/**
* Constructor using explicit SnowSQL config file as a String path.
*
* @return Snowflake class.
*/
SnowConfig(String config, String connection) {
this.connection = connection
this.config = new File(config)
}
/**
* Constructor using explicit credentials config file as a File object.
*
* @return Snowflake class.
*/
SnowConfig(File config, String connection) {
this.connection = connection
this.config = config
}

/**
* Build a Map of connection properties for making a Snowflake connection.
*
* @return Snowflake connection properties.
*/
Map getConnectionsProps() {
//Map props1 = [account: "account", user: "user", password: "password"]
Map props = [:]
Ini ini = new Ini(config)
// first get all the connection defaults
ini.get("connections").each { key, value ->
props."${key.replaceAll(/name$/, '')}" = value
}
// now replace defaults with the connection props
String connectionName = "connections" + '.' + connection
ini.get(connectionName).each { key, value ->
props."${key.replaceAll(/name$/, '')}" = value
}
// construct url from account
props.url = "https://" + props.account + ".snowflakecomputing.com"
props.remove("account")
// special password handling to support quoted values
props.password = props.password.toString().replaceAll(/("*)([^"$]+)("*)/) {all, q1, pwd, q2 ->
pwd
}
/**
* Constructor using explicit credentials config file as a String path.
*
* @return Snowflake class.
*/
SnowConfig(String config, String connection) {
this.connection = connection
this.config = new File(config)
}

// we need at least these three to make a connection
if (!props.url || !props.user || !props.password) {
throw new Exception("'url', 'user', or 'password' is not configured.")
}
return props
}
/**
* Build a Map of connection properties for making a Snowflake connection.
*
* @return Snowflake connection properties.
*/
Map getConnectionsProps() {
//Map props1 = [account: "account", user: "user", password: "password"]
Map props = [:]
Ini ini = new Ini(config)
// first get all the connection defaults
ini.get("connections").each { key, value ->
props."${key.replaceAll(/name$/, '')}" = value
}
// now replace defaults with the connection props
String connectionName = "connections" + '.' + connection
ini.get(connectionName).each { key, value ->
props."${key.replaceAll(/name$/, '')}" = value
}
// construct url from account
props.url = "https://" + props.account + ".snowflakecomputing.com"
props.remove("account")
// special password handling to support quoted values
props.password = props.password.toString().replaceAll(/("*)([^"$]+)("*)/) { all, q1, pwd, q2 ->
pwd
}

// we need at least these three to make a connection
if (!props.url || !props.user || !props.password) {
throw new Exception("'url', 'user', or 'password' is not configured.")
}
return props
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Snowflake {
Snowflake() {}

/**
* Constructor using autodetected SnowSQL config file.
* Constructor using auto-detected credentials config file.
*
* @return Snowflake class.
*/
Expand All @@ -84,7 +84,7 @@ class Snowflake {
}

/**
* Constructor using explicit SnowSQL config file as a File object.
* Constructor using explicit credentials config file as a File object.
*
* @return Snowflake class.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SnowflakeExtension {
}

/**
* The SnowSQL connection to use. Default: use the base connection info in SnowSQL config.
* The credentials connection to use. Default: use the base connection info in credentials config.
*/
String connection

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ abstract class SnowflakeTask extends DefaultTask {
}

/**
* The SnowSQL config file to use. Default: Looks first for '~/.snowsql/config' followed by './snow-config'.
* The credentials config file to use. Default: Looks first for '~/.snowflake/config.toml' followed by '~/.snowsql/config'.
*/
@Input
@Optional
@Option(option = "snow-config",
description = "Custom SnowSQL config file."
@Option(option = "config",
description = "Custom credentials config file."
)
String snowConfig

/**
* Override the SnowSQL connection to use. Default: use the base connection info in SnowSQL config.
* Override the credentials connection to use. Default: use the base connection info in credentials config.
*/
@Input
@Option(option = "connection",
description = "Override the SnowSQL connection to use. Default: use the base connection info in SnowSQL config."
description = "Override the credentials connection to use. Default: use the base connection info in credentials config."
)
String connection = extension.connection

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SnowConfigTest extends Specification {
snow = new SnowConfig(config, "example")
}

def "Parse snowsql default connection"() {
def "Parse credentials default connection"() {
when:
def props = snow.getConnectionsProps()

Expand All @@ -46,7 +46,7 @@ class SnowConfigTest extends Specification {
props.password == 'defaultpassword'
}

def "Parse snowsql connection with quoted password"() {
def "Parse credentials connection with quoted password"() {
given:
config.append("""
|
Expand Down
2 changes: 1 addition & 1 deletion src/examples/groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
}

dependencies {
implementation 'org.codehaus.groovy:groovy:3.0.17'
implementation 'org.codehaus.groovy:groovy:3.0.18'
}

java {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/java-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ testing {
}
testTask.configure {
failFast true
// which SnowSQL connection to use
// which credentials connection to use
systemProperty 'connection', snowflake.connection
// if this is ephemeral, the test spec needs the name to connect to
if (snowflake.useEphemeral) {
Expand Down
Loading

0 comments on commit 43111a2

Please sign in to comment.