Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uri in wave inpect json output #70

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@
"name":"io.seqera.wave.cli.json.PathAdapter",
"queryAllDeclaredMethods":true
},
{
"name":"io.seqera.wave.cli.json.LayerRefAdapter",
"queryAllDeclaredMethods":true,
"methods":[{"name":"toJson","parameterTypes":["io.seqera.wave.core.spec.ObjectRef"] }]
},
{
"name":"io.seqera.wave.cli.model.ContainerInspectResponseEx",
"allDeclaredFields":true
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/io/seqera/wave/cli/json/JsonHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class JsonHelper {
.add(new ByteArrayAdapter())
.add(new DateTimeAdapter())
.add(new PathAdapter())
.add(new LayerRefAdapter())
.build();

public static String toJson(SubmitContainerTokenRequest request) {
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/java/io/seqera/wave/cli/json/LayerRefAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2024, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package io.seqera.wave.cli.json;

import com.squareup.moshi.ToJson;
import io.seqera.wave.cli.model.LayerRef;
import io.seqera.wave.core.spec.ObjectRef;
/**
* Layer Ref adapter for Moshi JSON serialisation
*
* @author Munish Chouhan <munish.chouhan@seqera.io>
*/
public class LayerRefAdapter{

@ToJson
public LayerRef toJson(ObjectRef objectRef) {
if(objectRef instanceof LayerRef) {
return (LayerRef) objectRef;
} else{
return new LayerRef(objectRef, null);
}
}
}
33 changes: 31 additions & 2 deletions app/src/test/groovy/io/seqera/wave/cli/json/JsonHelperTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package io.seqera.wave.cli.json
import io.seqera.wave.api.SubmitContainerTokenRequest
import io.seqera.wave.cli.model.ContainerInspectResponseEx
import io.seqera.wave.core.spec.ContainerSpec
import io.seqera.wave.core.spec.ManifestSpec
import io.seqera.wave.core.spec.ObjectRef
import spock.lang.Specification
/**
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
Expand All @@ -46,13 +48,40 @@ class JsonHelperTest extends Specification {

def 'should convert response to json' () {
given:
def spec = new ContainerSpec('docker.io', 'https://docker.io', 'ubuntu', '22.04', 'sha:12345', null, null)
def layers = [new ObjectRef('text', 'sha256:12345', 100, null), new ObjectRef('text', 'sha256:67890', 200, null) ]
def manifest = new ManifestSpec(2, 'some/media', null, layers, [one: '1', two:'2'])
def spec = new ContainerSpec('docker.io', 'https://docker.io', 'ubuntu', '22.04', 'sha:12345', null, manifest)
def resp = new ContainerInspectResponseEx(spec)

when:
def result = JsonHelper.toJson(resp)
then:
result == '{"container":{"digest":"sha:12345","hostName":"https://docker.io","imageName":"ubuntu","reference":"22.04","registry":"docker.io"}}'
result == '''\
{
"container":{
"digest":
"sha:12345","hostName":"https://docker.io",
"imageName":"ubuntu",
"manifest":{
"annotations":{"one":"1","two":"2"},
"layers":[
{"digest":"sha256:12345",
"mediaType":"text",
"size":100,
"uri":"https://docker.io/v2/ubuntu/blobs/sha256:12345"},
{"digest":"sha256:67890",
"mediaType":"text",
"size":200,
"uri":"https://docker.io/v2/ubuntu/blobs/sha256:67890"}
],
"mediaType":"some/media",
"schemaVersion":2
},
"reference":"22.04",
"registry":"docker.io"
}
}
'''.replaceAll("\\s+", "").trim()
}

}