01 /*
02 * SPDX-License-Identifier: Apache-2.0
03 *
04 * Copyright 2019-2022 Andres Almiray.
05 *
06 * Licensed under the Apache License, Version 2.0 (the "License");
07 * you may not use this file except in compliance with the License.
08 * You may obtain a copy of the License at
09 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.kordamp.gradle.plugin.oci.tasks.object
19
20
21 import com.oracle.bmc.objectstorage.ObjectStorageClient
22 import com.oracle.bmc.objectstorage.requests.HeadObjectRequest
23 import com.oracle.bmc.objectstorage.responses.HeadObjectResponse
24 import groovy.transform.CompileStatic
25 import org.kordamp.gradle.plugin.oci.tasks.AbstractOCITask
26 import org.kordamp.gradle.plugin.oci.tasks.interfaces.OCITask
27 import org.kordamp.gradle.plugin.oci.tasks.traits.BucketNameAwareTrait
28 import org.kordamp.gradle.plugin.oci.tasks.traits.NamespaceNameAwareTrait
29 import org.kordamp.gradle.plugin.oci.tasks.traits.ObjectNameAwareTrait
30 import org.kordamp.jipsy.annotations.TypeProviderFor
31
32 /**
33 * @author Andres Almiray
34 * @since 0.3.0
35 */
36 @CompileStatic
37 @TypeProviderFor(OCITask)
38 class HeadObjectTask extends AbstractOCITask implements NamespaceNameAwareTrait,
39 BucketNameAwareTrait,
40 ObjectNameAwareTrait {
41 static final String TASK_DESCRIPTION = 'Heads a specific Object.'
42
43 @Override
44 protected void doExecuteTask() {
45 validateNamespaceName()
46 validateBucketName()
47 validateObjectName()
48
49 headObject(this,
50 createObjectStorageClient(),
51 getResolvedNamespaceName().get(),
52 getResolvedBucketName().get(),
53 getResolvedObjectName().get())
54 }
55
56 static HeadObjectResponse headObject(OCITask owner,
57 ObjectStorageClient storageClient,
58 String namespaceName,
59 String bucketName,
60 String objectName) {
61 HeadObjectResponse response = storageClient.headObject(HeadObjectRequest.builder()
62 .namespaceName(namespaceName)
63 .bucketName(bucketName)
64 .objectName(objectName)
65 .build())
66
67 println(objectName + ':')
68 owner.printKeyValue('ETag', response.ETag, 1)
69 owner.printKeyValue('Modified', !response.notModified, 1)
70 owner.printKeyValue('Last Modified', response.lastModified, 1)
71 owner.printKeyValue('Content Length', response.contentLength, 1)
72 owner.printKeyValue('Content Type', response.contentType, 1)
73 owner.printKeyValue('Content MD5', response.contentMd5, 1)
74 owner.printKeyValue('Content Encoding', response.contentEncoding, 1)
75 owner.printKeyValue('Content Language', response.contentLanguage, 1)
76 owner.printKeyValue('Archival State', response.archivalState, 1)
77 owner.printKeyValue('Time of Archival', response.timeOfArchival, 1)
78 }
79 }
|