Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into batch-writes
Browse files Browse the repository at this point in the history
  • Loading branch information
decentralgabe authored Jan 14, 2023
2 parents c03d99b + 46abf9a commit 71825b5
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 163 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,6 @@ jobs:
- name: Check Vulnerabilities
run: mage -v vuln

generate-spec:
runs-on: ubuntu-latest
steps:
- name: fetch history
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.4
cache: true

- name: Install Mage
run: go install github.com/magefile/mage

- name: Update to latest spec
shell: bash
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go install github.com/swaggo/swag/cmd/[email protected]
mage spec
- name: Push generated spec file
uses: actions/checkout@v3
- run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
if (git diff --shortstat | grep '[0-9]'); then \
git add .; \
git commit -m "gen OpenAPI Spec by github-actions"; \
git push
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
runs-on: ubuntu-latest
steps:
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/swagger-doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: swagger-doc

on:
push:
branches:
- main

jobs:

generate-swagger:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.4
cache: true

- name: Install Mage
run: go install github.com/magefile/mage

- name: Update spec and push generated spec file
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- run: |
export PATH=$PATH:$(go env GOPATH)/bin
mage spec
git config user.name github-actions
git config user.email [email protected]
if (git diff --shortstat | grep '[0-9]'); then \
git checkout -B main_swagger
git add .; \
git commit -m "gen OpenAPI Spec by github-actions"; \
git push --set-upstream origin main_swagger
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 20 additions & 0 deletions integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,23 @@ func ReviewApplication(params reviewApplicationParams) (string, error) {

return output, nil
}

type issuanceTemplateParams struct {
SchemaID string
ManifestID string
IssuerID string
}

func CreateIssuanceTemplate(params issuanceTemplateParams) (string, error) {
logrus.Println("\n\nCreating Issuance Template:")
issuanceTemplateJSON, err := resolveTemplate(params, "issuance-template-input.json")
if err != nil {
return "", err
}
output, err := put(endpoint+version+"issuancetemplates", issuanceTemplateJSON)
if err != nil {
return "", errors.Wrapf(err, "creating issuance template yielded output: %s", output)
}

return output, nil
}
95 changes: 95 additions & 0 deletions integration/steelthread_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,101 @@ func TestCreateCredentialManifestIntegration(t *testing.T) {
assert.NotEmpty(t, manifestID)
}

func TestCreateIssuanceTemplateIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

issuerDID, err := GetValue(steelThreadContext, "issuerDID")
assert.NoError(t, err)
assert.NotEmpty(t, issuerDID)

schemaID, err := GetValue(steelThreadContext, "schemaID")
assert.NoError(t, err)
assert.NotEmpty(t, schemaID)

cmOutput, err := CreateCredentialManifest(credManifestParams{
IssuerID: issuerDID.(string),
SchemaID: schemaID.(string),
})
assert.NoError(t, err)

manifestID, err := getJSONElement(cmOutput, "$.credential_manifest.id")
SetValue(steelThreadContext, "manifestWithIssuanceTemplateID", manifestID)
assert.NoError(t, err)
assert.NotEmpty(t, manifestID)

presentationDefinitionID, err := getJSONElement(cmOutput, "$.credential_manifest.presentation_definition.id")
SetValue(steelThreadContext, "presentationDefinitionWithIssuanceTemplateID", presentationDefinitionID)
assert.NoError(t, err)
assert.NotEmpty(t, presentationDefinitionID)

itOutput, err := CreateIssuanceTemplate(issuanceTemplateParams{
SchemaID: schemaID.(string),
ManifestID: manifestID,
IssuerID: issuerDID.(string),
})
assert.NoError(t, err)

issuanceTemplateID, err := getJSONElement(itOutput, "$.id")
assert.NoError(t, err)
assert.NotEmpty(t, issuanceTemplateID)
SetValue(steelThreadContext, "issuanceTemplateID", issuanceTemplateID)
}

func TestSubmitApplicationWithIssuanceTemplateIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

credentialJWT, err := GetValue(steelThreadContext, "credentialJWT")
assert.NoError(t, err)
assert.NotEmpty(t, credentialJWT)

presentationDefinitionID, err := GetValue(steelThreadContext, "presentationDefinitionWithIssuanceTemplateID")
assert.NoError(t, err)
assert.NotEmpty(t, presentationDefinitionID)

manifestID, err := GetValue(steelThreadContext, "manifestWithIssuanceTemplateID")
assert.NoError(t, err)
assert.NotEmpty(t, manifestID)

aliceDID, err := GetValue(steelThreadContext, "aliceDID")
assert.NoError(t, err)
assert.NotEmpty(t, aliceDID)

aliceDIDPrivateKey, err := GetValue(steelThreadContext, "aliceDIDPrivateKey")
assert.NoError(t, err)
assert.NotEmpty(t, aliceDIDPrivateKey)

credAppJWT, err := CreateCredentialApplicationJWT(credApplicationParams{
DefinitionID: presentationDefinitionID.(string),
ManifestID: manifestID.(string),
}, credentialJWT.(string), aliceDID.(string), aliceDIDPrivateKey.(string))
assert.NoError(t, err)
assert.NotEmpty(t, credAppJWT)

submitApplicationOutput, err := SubmitApplication(applicationParams{
ApplicationJWT: credAppJWT,
})
assert.NoError(t, err)
assert.NotEmpty(t, submitApplicationOutput)

isDone, err := getJSONElement(submitApplicationOutput, "$.done")
assert.NoError(t, err)
assert.Equal(t, "true", isDone)

credentialResponseID, err := getJSONElement(submitApplicationOutput, "$.result.response.credential_response.id")
assert.NoError(t, err)

opCredentialResponse, err := getJSONElement(submitApplicationOutput, "$.result.response")
assert.NoError(t, err)

responsesOutput, err := get(endpoint + version + "manifests/responses/" + credentialResponseID)
assert.NoError(t, err)

assert.JSONEq(t, responsesOutput, opCredentialResponse)
}
func TestSubmitAndReviewApplicationIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
Expand Down
22 changes: 22 additions & 0 deletions integration/testdata/issuance-template-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"credentialManifest": "{{.ManifestID}}",
"issuer": "{{.IssuerID}}",
"credentials": [
{
"id": "kyc_credential",
"schema": "{{.SchemaID}}",
"credentialInputDescriptor": "kyc1",
"data": {
"givenName": "$.credentialSubject.givenName",
"familyName": "$.credentialSubject.familyName",
"postalAddress": {
"addressRegion": "CA"
}
},
"expiry": {
"time": "2022-10-31T00:00:00Z"
},
"revocable": true
}
]
}
6 changes: 5 additions & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ func Integration() error {
// Spec generates an OpenAPI spec yaml based on code annotations.
func Spec() error {
swagCommand := "swag"
if err := installIfNotPresent(swagCommand, "github.com/swaggo/swag/cmd/swag@latest"); err != nil {
if err := installIfNotPresent(swagCommand, "github.com/swaggo/swag/cmd/[email protected]"); err != nil {
logrus.Fatal(err)
return err
}
if err := sh.Run(swagCommand, "fmt", "-d", "pkg/server/router"); err != nil {
logrus.Fatal(err)
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/server/middleware/panics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func Panics() framework.Middleware {
defer func() {
if r := recover(); r != nil {
// log the stack trace for this panic'd goroutine
err = errors.Errorf("%s: \n%s", v.TraceID, debug.Stack())
stack := debug.Stack()
err = errors.Errorf("%s: \n%s", v.TraceID, stack)

logrus.Infof("%s: PANIC :\n%s", v.TraceID, debug.Stack())
logrus.Infof("%s: PANIC : %s : \n%s", r, v.TraceID, stack)
}
}()

Expand Down
11 changes: 7 additions & 4 deletions pkg/server/router/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,10 @@ func (mr ManifestRouter) DeleteApplication(ctx context.Context, w http.ResponseW
}

type GetResponseResponse struct {
ID string `json:"id"`
Response manifestsdk.CredentialResponse `json:"response"`
Response manifestsdk.CredentialResponse `json:"credential_response"`
// this is an interface type to union Data Integrity and JWT style VCs
Credentials any `json:"verifiableCredentials,omitempty"`
ResponseJWT keyaccess.JWT `json:"responseJwt,omitempty"`
}

// GetResponse godoc
Expand Down Expand Up @@ -450,8 +452,9 @@ func (mr ManifestRouter) GetResponse(ctx context.Context, w http.ResponseWriter,
}

resp := GetResponseResponse{
ID: gotResponse.Response.ID,
Response: gotResponse.Response,
Response: gotResponse.Response,
Credentials: gotResponse.Credentials,
ResponseJWT: gotResponse.ResponseJWT,
}
return framework.Respond(ctx, w, resp, http.StatusOK)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/router/presentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ type ReviewSubmissionResponse struct {
}

// ReviewSubmission godoc
// @Summary Review a pending submissions
// @Summary Review a pending submission
// @Description Reviews a pending submission. After this method is called, the operation with `id==presentations/submissions/{submission_id}` will be updated with the result of this invocation.
// @Tags SubmissionAPI
// @Accept json
Expand Down
Loading

0 comments on commit 71825b5

Please sign in to comment.