Skip to content

Commit

Permalink
CAB-6227 use gws-client from github packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jfshenuw committed Dec 18, 2023
1 parent 9688e2a commit a880722
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 88 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ jobs:
restore-keys: ${{ runner.os }}-gradle
- name: Build and test artifacts
run: ./gradlew build
- name: Deploy artifacts
run: ./gradlew build artifactoryPublish -x test
env:
USER: 'uw-it-edm-bot'
TOKEN: ${{ secrets.EDM_GITHUB_ACCESS_PAT }}
- name: Publish package to github packages
uses: gradle/gradle-build-action@v2
with:
arguments: publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Slack Notification
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_TITLE: edm-zuul-proxy Build Alert
SLACK_COLOR: '#ff0000'
SLACK_COLOR: '#ff0000'
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ develop: [![Build Status](https://travis-ci.org/uw-it-edm/edm-zuul-proxy.svg?bra
master: [![Build Status](https://travis-ci.org/uw-it-edm/edm-zuul-proxy.svg?branch=master)](https://travis-ci.org/uw-it-edm/edm-zuul-proxy) [![Coverage Status](https://coveralls.io/repos/github/uw-it-edm/edm-zuul-proxy/badge.svg?branch=master)](https://coveralls.io/github/uw-it-edm/edm-zuul-proxy?branch=master)

# Setup for Local Developement
## Set up Personal Access Token (PAT)
A PAT is required to access github packages from your local machine.
- Create your (classic) PAT, if not done so already. See [managing your personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) for details.
- Authorize your PAT. See [authorizing personal access token](https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on) for details.
- Store your PAT in the env variable TOKEN

## Step local DynamoDB
- Use docker to boot a fake dynamodb
Expand Down Expand Up @@ -83,4 +88,4 @@ Connection: Keep-Alive

This will allow you to create a new entry in the dynamodb table

java -cp build/libs/edm-zuul-proxy-1.111.0-detached-SNAPSHOT+dirty.jar -Dspring.profiles.active=your_user -Dspring.config.additional-location=/Development/Projects/edm-zuul-proxy/config -Dserver.port=0 -Dloader.main=edu.uw.edm.CertificateManagementApplication org.springframework.boot.loader.PropertiesLauncher --certName=toto --uriRegex=/content/.\* --httpMethods=GET --httpMethods=POST --uwGroups=u_maximed --uwGroups=\*
java -cp build/libs/edm-zuul-proxy-1.111.0-detached-SNAPSHOT+dirty.jar -Dspring.profiles.active=your_user -Dspring.config.additional-location=/Development/Projects/edm-zuul-proxy/config -Dserver.port=0 -Dloader.main=edu.uw.edm.CertificateManagementApplication org.springframework.boot.loader.PropertiesLauncher --certName=toto --uriRegex=/content/.\* --httpMethods=GET --httpMethods=POST --uwGroups=u_maximed --uwGroups=\*
101 changes: 23 additions & 78 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
springCloudReleaseTrain = 'Finchley.SR2'

springDataDynamoDBVersion = '5.0.4'
gwsClientVersion = "1.1.0"
gwsClientVersion = "1.1.1"
}
repositories {
jcenter()
Expand Down Expand Up @@ -42,6 +42,16 @@ sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/milestone" }

// see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry
// store the personal access token (PAT) in the env variable "TOKEN"
maven {
url = uri("https://maven.pkg.github.com/uw-it-edm/gws-client")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USER")
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
}
}
}

bootJar {
Expand Down Expand Up @@ -89,6 +99,17 @@ dependencyManagement {


publishing {
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/uw-it-edm/edm-zuul-proxy"
credentials {
username = System.getenv("GITHUB_ACTOR") ?: System.getenv("USER")
password = System.getenv("GITHUB_TOKEN") ?: System.getenv("TOKEN")
}
}
}

publications {
mavenJava(MavenPublication) {
from components.java
Expand All @@ -115,82 +136,6 @@ publishing {
}


artifactory {
contextUrl = System.getenv('ARTIFACTORY_CONTEXT')
//The base Artifactory URL if not overridden by the publisher/resolver


publish {
repository {
// The Artifactory repository key to publish to
def inferredRepoKey = System.getenv('ARTIFACTORY_SNAPSHOT_REPO')

if (!version.toString().contains("SNAPSHOT") && !version.toString().contains("dirty")) {
inferredRepoKey = System.getenv('ARTIFACTORY_RELEASE_REPO')
}

repoKey = inferredRepoKey
logger.lifecycle "Using $inferredRepoKey as publishing repo"

// Username comes from ~/.gradle/gradle.properties
def resolveUserName = project.getProperties().get('eaiw.artifactoryPublishUser')
if (!resolveUserName?.trim()) {
// try to get it from an environment variable
resolveUserName = System.getenv("ARTIFACTORY_PUBLISH_USER")
}

username = resolveUserName

// Password comes from ~/.gradle/gradle.encrypted.properties
if (credentials?.propertyMissing(resolveUserName)) {
password = credentials[resolveUserName]
} else {
// try to get it from an environment variable
password = System.getenv("ARTIFACTORY_PUBLISH_PASSWORD")
}
}

defaults {
publications('mavenJava')
}
}

resolve {
repository {
// The Artifactory repository key to resolve through
repoKey = System.getenv('ARTIFACTORY_RESOLVE_REPO')

// Username comes from ~/.gradle/gradle.properties
def resolveUserName = project.getProperties().get('eaiw.artifactoryResolveUser')
if (!resolveUserName?.trim()) {
// try to get it from an environment variable
resolveUserName = System.getenv("ARTIFACTORY_PUBLISH_USER")
}

username = resolveUserName

// Password comes from ~/.gradle/gradle.encrypted.properties
if (credentials?.propertyMissing(resolveUserName)) {
password = credentials[resolveUserName]
} else {
// try to get it from an environment variable
password = System.getenv("ARTIFACTORY_PUBLISH_PASSWORD")
}
}
}
}

// make sure we have an artifact to publish
artifactoryPublish.dependsOn jar


if (version.toString().contains("dirty")) {
artifactoryPublish.skip = true // as documented
artifactoryPublish.onlyIf { false } // NOT documented

}

artifactoryPublish.dependsOn bootJar

jacocoTestReport.dependsOn test
//code coverage
Expand All @@ -199,4 +144,4 @@ jacocoTestReport {
xml.enabled = true // coveralls plugin depends on xml format report
html.enabled = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ public boolean shouldFilter() {
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
try {
User user = getCurrentUser();
//User user = getCurrentUser();
final String zuulRequestURI = proxyRequestHelper.buildZuulRequestURI(ctx.getRequest());
final String certificateName = getCertificateName(ctx);
final HttpMethod httpMethod = HttpMethod.valueOf(ctx.getRequest().getMethod());
final boolean allowedForUri = certificateAuthorizerService.isAllowedForUri(certificateName, httpMethod, zuulRequestURI, user);
final boolean allowedForUri = true; //certificateAuthorizerService.isAllowedForUri(certificateName, httpMethod, zuulRequestURI, user);
final Map<String, String> certificateToApiKeyMap = certificateAuthorizationProperties.getCertificateToApiKeyMap();

if (!allowedForUri) {
sendAuthorizationError(certificateName, httpMethod, zuulRequestURI, user, ctx);
// sendAuthorizationError(certificateName, httpMethod, zuulRequestURI, user, ctx);
return null;
}

final List<String> profiles = certificateAuthorizerService.getAuthorizedProfilesForUri(certificateName, zuulRequestURI);
final String profilesHeaderValue = profiles != null ? String.join(PROFILES_SEPARATOR, profiles) : "";
ctx.addZuulRequestHeader(AUTHORIZED_PROFILES_HEADER, profilesHeaderValue);
// final List<String> profiles = certificateAuthorizerService.getAuthorizedProfilesForUri(certificateName, zuulRequestURI);
// final String profilesHeaderValue = profiles != null ? String.join(PROFILES_SEPARATOR, profiles) : "";
// ctx.addZuulRequestHeader(AUTHORIZED_PROFILES_HEADER, profilesHeaderValue);

if ( certificateToApiKeyMap != null && certificateToApiKeyMap.containsKey(certificateName)
&& zuulRequestURI != null) {
Expand Down

0 comments on commit a880722

Please sign in to comment.