Skip to content

Commit eb3a558

Browse files
Initial commit
Signed-off-by: Albert Pastrana <albert.pastrana@intenthq.com>
1 parent e35b442 commit eb3a558

File tree

9 files changed

+261
-0
lines changed

9 files changed

+261
-0
lines changed

.github/workflows/build.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
branches:
12+
- main
13+
14+
jobs:
15+
build:
16+
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- uses: coursier/cache-action@v3
22+
- name: Set up JDK 1.8
23+
uses: actions/setup-java@v1
24+
with:
25+
java-version: 1.8
26+
- name: Run tests
27+
env:
28+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
29+
run: sbt test

.github/workflows/publish.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: publish
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish:
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: coursier/cache-action@v3
16+
- name: Set up JDK 1.8
17+
uses: actions/setup-java@v1
18+
with:
19+
java-version: 1.8
20+
- name: Publish library
21+
env:
22+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
23+
run: sbt test publish

.gitignore

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/sbt,intellij,scala,macos
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=sbt,intellij,scala,macos
3+
4+
### Intellij ###
5+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
6+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7+
8+
# User-specific stuff
9+
.idea/**/workspace.xml
10+
.idea/**/tasks.xml
11+
.idea/**/usage.statistics.xml
12+
.idea/**/dictionaries
13+
.idea/**/shelf
14+
15+
# Generated files
16+
.idea/**/contentModel.xml
17+
18+
# Sensitive or high-churn files
19+
.idea/**/dataSources/
20+
.idea/**/dataSources.ids
21+
.idea/**/dataSources.local.xml
22+
.idea/**/sqlDataSources.xml
23+
.idea/**/dynamic.xml
24+
.idea/**/uiDesigner.xml
25+
.idea/**/dbnavigator.xml
26+
27+
# Gradle
28+
.idea/**/gradle.xml
29+
.idea/**/libraries
30+
31+
# Gradle and Maven with auto-import
32+
# When using Gradle or Maven with auto-import, you should exclude module files,
33+
# since they will be recreated, and may cause churn. Uncomment if using
34+
# auto-import.
35+
# .idea/artifacts
36+
# .idea/compiler.xml
37+
# .idea/jarRepositories.xml
38+
# .idea/modules.xml
39+
# .idea/*.iml
40+
# .idea/modules
41+
# *.iml
42+
# *.ipr
43+
44+
# CMake
45+
cmake-build-*/
46+
47+
# Mongo Explorer plugin
48+
.idea/**/mongoSettings.xml
49+
50+
# File-based project format
51+
*.iws
52+
53+
# IntelliJ
54+
out/
55+
56+
# mpeltonen/sbt-idea plugin
57+
.idea_modules/
58+
59+
# JIRA plugin
60+
atlassian-ide-plugin.xml
61+
62+
# Cursive Clojure plugin
63+
.idea/replstate.xml
64+
65+
# Crashlytics plugin (for Android Studio and IntelliJ)
66+
com_crashlytics_export_strings.xml
67+
crashlytics.properties
68+
crashlytics-build.properties
69+
fabric.properties
70+
71+
# Editor-based Rest Client
72+
.idea/httpRequests
73+
74+
# Android studio 3.1+ serialized cache file
75+
.idea/caches/build_file_checksums.ser
76+
77+
### Intellij Patch ###
78+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
79+
80+
# *.iml
81+
# modules.xml
82+
# .idea/misc.xml
83+
# *.ipr
84+
85+
# Sonarlint plugin
86+
# https://plugins.jetbrains.com/plugin/7973-sonarlint
87+
.idea/**/sonarlint/
88+
89+
# SonarQube Plugin
90+
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
91+
.idea/**/sonarIssues.xml
92+
93+
# Markdown Navigator plugin
94+
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
95+
.idea/**/markdown-navigator.xml
96+
.idea/**/markdown-navigator-enh.xml
97+
.idea/**/markdown-navigator/
98+
99+
# Cache file creation bug
100+
# See https://youtrack.jetbrains.com/issue/JBR-2257
101+
.idea/$CACHE_FILE$
102+
103+
# CodeStream plugin
104+
# https://plugins.jetbrains.com/plugin/12206-codestream
105+
.idea/codestream.xml
106+
107+
### macOS ###
108+
# General
109+
.DS_Store
110+
.AppleDouble
111+
.LSOverride
112+
113+
# Icon must end with two \r
114+
Icon
115+
116+
# Thumbnails
117+
._*
118+
119+
# Files that might appear in the root of a volume
120+
.DocumentRevisions-V100
121+
.fseventsd
122+
.Spotlight-V100
123+
.TemporaryItems
124+
.Trashes
125+
.VolumeIcon.icns
126+
.com.apple.timemachine.donotpresent
127+
128+
# Directories potentially created on remote AFP share
129+
.AppleDB
130+
.AppleDesktop
131+
Network Trash Folder
132+
Temporary Items
133+
.apdisk
134+
135+
### SBT ###
136+
# Simple Build Tool
137+
# http://www.scala-sbt.org/release/docs/Getting-Started/Directories.html#configuring-version-control
138+
139+
dist/*
140+
target/
141+
lib_managed/
142+
src_managed/
143+
project/boot/
144+
project/plugins/project/
145+
.history
146+
.cache
147+
.lib/
148+
149+
### Scala ###
150+
*.class
151+
*.log
152+
153+
# End of https://www.toptal.com/developers/gitignore/api/sbt,intellij,scala,macos

build.sbt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ThisBuild / scalaVersion := "2.13.3"
2+
ThisBuild / organization := "com.intenthq"
3+
ThisBuild / organizationName := "Intent HQ"
4+
5+
lazy val root = (project in file("."))
6+
.settings(
7+
name := "scala-secret",
8+
libraryDependencies += Dependencies.weaver
9+
)
10+
11+
testFrameworks += new TestFramework("weaver.framework.TestFramework")
12+
13+
publishTo := Some("GitHub Package Registry" at "https://maven.pkg.github.com/intenthq/scala-secret")
14+
credentials ++= scala.util.Properties
15+
.envOrNone("GITHUB_TOKEN")
16+
.map(githubToken => Credentials("GitHub Package Registry", "maven.pkg.github.com", "_", githubToken))

project/Dependencies.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sbt._
2+
3+
object Dependencies {
4+
lazy val weaver = "com.disneystreaming" %% "weaver-framework" % "0.5.0" % "test"
5+
}

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.3.13

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.intenthq.secret
2+
3+
import java.nio.charset.StandardCharsets
4+
import java.security.MessageDigest
5+
6+
final case class Secret(value: String) {
7+
override val toString: String = s"Secret(${Secret.firstSevenHashChars(value)})"
8+
}
9+
10+
object Secret {
11+
12+
protected def firstSevenHashChars(s: String): String = {
13+
// DO NOT EXTRACT THIS VAL OUT. MessageDigest keeps internal state and if you extract it, things will become flaky
14+
val md: MessageDigest = java.security.MessageDigest.getInstance("SHA-1")
15+
md.digest(s.getBytes(StandardCharsets.UTF_8)).map("%02x".format(_)).mkString.take(7)
16+
}
17+
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.intenthq.secret
2+
3+
import weaver.SimpleIOSuite
4+
5+
object SecretSpec extends SimpleIOSuite {
6+
7+
case class NoSecret(value: String)
8+
9+
pureTest("Secret.toString should hide its value by only showing a few chars of the SHA-1 hash") {
10+
expect(Secret("value").toString == "Secret(f32b67c)") and
11+
expect(Secret("newValue").toString == "Secret(74666ad)") and
12+
expect(Secret("myPassword").toString == "Secret(5413ee2)")
13+
}
14+
15+
}

0 commit comments

Comments
 (0)