11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
3- // Code generated by Microsoft (R) AutoRest Code Generator.
43
54package com .azure .containers .containerregistry ;
65
76import com .azure .containers .containerregistry .implementation .ArtifactManifestPropertiesHelper ;
87import com .azure .containers .containerregistry .implementation .ArtifactTagPropertiesHelper ;
8+ import com .azure .containers .containerregistry .implementation .AzureContainerRegistryImpl ;
9+ import com .azure .containers .containerregistry .implementation .ContainerRegistriesImpl ;
910import com .azure .containers .containerregistry .implementation .UtilsImpl ;
1011import com .azure .containers .containerregistry .implementation .models .AcrErrorsException ;
1112import com .azure .containers .containerregistry .implementation .models .ArtifactManifestPropertiesInternal ;
3233
3334import java .util .Objects ;
3435
35- import static com .azure .containers .containerregistry .implementation .UtilsImpl .enableSync ;
36+ import static com .azure .containers .containerregistry .implementation .UtilsImpl .formatFullyQualifiedReference ;
3637import static com .azure .containers .containerregistry .implementation .UtilsImpl .isDigest ;
38+ import static com .azure .containers .containerregistry .implementation .UtilsImpl .enableSync ;
3739import static com .azure .containers .containerregistry .implementation .UtilsImpl .mapAcrErrorsException ;
3840
3941/**
5254 * <!-- end com.azure.containers.containerregistry.RegistryArtifact.instantiation -->
5355 */
5456@ ServiceClient (builder = ContainerRegistryClientBuilder .class )
55- public final class RegistryArtifact extends RegistryArtifactBase {
57+ public final class RegistryArtifact {
5658 private static final ClientLogger LOGGER = new ClientLogger (RegistryArtifact .class );
59+ private final String fullyQualifiedReference ;
60+ private final String endpoint ;
61+ private final String repositoryName ;
62+ private final String tagOrDigest ;
63+ private final ContainerRegistriesImpl serviceClient ;
64+ private String digest ;
5765
5866 /**
5967 * Creates a RegistryArtifact type that sends requests to the given repository in the container registry service at {@code endpoint}.
@@ -65,7 +73,21 @@ public final class RegistryArtifact extends RegistryArtifactBase {
6573 * @param version {@link ContainerRegistryServiceVersion} of the service to be used when making requests.
6674 */
6775 RegistryArtifact (String repositoryName , String tagOrDigest , HttpPipeline httpPipeline , String endpoint , String version ) {
68- super (repositoryName , tagOrDigest , httpPipeline , endpoint , version );
76+ Objects .requireNonNull (repositoryName , "'repositoryName' cannot be null." );
77+ if (repositoryName .isEmpty ()) {
78+ throw LOGGER .logExceptionAsError (new IllegalArgumentException ("'repositoryName' can't be empty" ));
79+ }
80+
81+ Objects .requireNonNull (tagOrDigest , "'tagOrDigest' cannot be null." );
82+ if (tagOrDigest .isEmpty ()) {
83+ throw LOGGER .logExceptionAsError (new IllegalArgumentException ("'digest' can't be empty" ));
84+ }
85+
86+ this .serviceClient = new AzureContainerRegistryImpl (httpPipeline , endpoint , version ).getContainerRegistries ();
87+ this .fullyQualifiedReference = formatFullyQualifiedReference (endpoint , repositoryName , tagOrDigest );
88+ this .endpoint = endpoint ;
89+ this .repositoryName = repositoryName ;
90+ this .tagOrDigest = tagOrDigest ;
6991 }
7092
7193 /**
@@ -88,9 +110,9 @@ public final class RegistryArtifact extends RegistryArtifactBase {
88110 */
89111 @ ServiceMethod (returns = ReturnType .SINGLE )
90112 public Response <Void > deleteWithResponse (Context context ) {
91- String res = this . getDigest ();
113+ String res = getDigest ();
92114 try {
93- Response <Void > response = this . serviceClient .deleteManifestWithResponse (getRepositoryName (), res , enableSync (context ));
115+ Response <Void > response = serviceClient .deleteManifestWithResponse (getRepositoryName (), res , enableSync (context ));
94116
95117 return UtilsImpl .deleteResponseToSuccess (response );
96118 } catch (AcrErrorsException exception ) {
@@ -99,15 +121,12 @@ public Response<Void> deleteWithResponse(Context context) {
99121 }
100122
101123 private String getDigest () {
102- if (this .digest != null ) {
103- return digest ;
124+ if (digest == null ) {
125+ digest = isDigest (tagOrDigest )
126+ ? tagOrDigest
127+ : getTagProperties (tagOrDigest ).getDigest ();
104128 }
105-
106- String res = isDigest (tagOrDigest )
107- ? tagOrDigest
108- : this .getTagProperties (tagOrDigest ).getDigest ();
109- this .digest = res ;
110- return res ;
129+ return digest ;
111130 }
112131
113132 /**
@@ -128,7 +147,7 @@ private String getDigest() {
128147 */
129148 @ ServiceMethod (returns = ReturnType .SINGLE )
130149 public void delete () {
131- this . deleteWithResponse (Context .NONE ).getValue ();
150+ deleteWithResponse (Context .NONE ).getValue ();
132151 }
133152
134153 /**
@@ -160,7 +179,7 @@ public Response<Void> deleteTagWithResponse(String tag, Context context) {
160179 throw LOGGER .logExceptionAsError (new IllegalArgumentException ("'tag' cannot be empty." ));
161180 }
162181 try {
163- Response <Void > response = this . serviceClient .deleteTagWithResponse (getRepositoryName (), tag , enableSync (context ));
182+ Response <Void > response = serviceClient .deleteTagWithResponse (getRepositoryName (), tag , enableSync (context ));
164183
165184 return UtilsImpl .deleteResponseToSuccess (response );
166185 } catch (AcrErrorsException exception ) {
@@ -190,10 +209,9 @@ public Response<Void> deleteTagWithResponse(String tag, Context context) {
190209 */
191210 @ ServiceMethod (returns = ReturnType .SINGLE )
192211 public void deleteTag (String tag ) {
193- this . deleteTagWithResponse (tag , Context .NONE ).getValue ();
212+ deleteTagWithResponse (tag , Context .NONE ).getValue ();
194213 }
195214
196-
197215 /**
198216 * Gets the {@link ArtifactManifestProperties properties} associated with an artifact in given {@link #getRepositoryName() repository}.
199217 *
@@ -221,7 +239,7 @@ public void deleteTag(String tag) {
221239 */
222240 @ ServiceMethod (returns = ReturnType .SINGLE )
223241 public Response <ArtifactManifestProperties > getManifestPropertiesWithResponse (Context context ) {
224- String res = this . getDigest ();
242+ String res = getDigest ();
225243 try {
226244 Response <ArtifactManifestPropertiesInternal > internalResponse = this .serviceClient
227245 .getManifestPropertiesWithResponse (getRepositoryName (), res , enableSync (context ));
@@ -257,7 +275,7 @@ public Response<ArtifactManifestProperties> getManifestPropertiesWithResponse(Co
257275 */
258276 @ ServiceMethod (returns = ReturnType .SINGLE )
259277 public ArtifactManifestProperties getManifestProperties () {
260- return this . getManifestPropertiesWithResponse (Context .NONE ).getValue ();
278+ return getManifestPropertiesWithResponse (Context .NONE ).getValue ();
261279 }
262280
263281 /**
@@ -392,7 +410,7 @@ public PagedIterable<ArtifactTagProperties> listTagProperties() {
392410 */
393411 @ ServiceMethod (returns = ReturnType .COLLECTION )
394412 public PagedIterable <ArtifactTagProperties > listTagProperties (ArtifactTagOrder order ) {
395- return this . listTagProperties (order , Context .NONE );
413+ return listTagProperties (order , Context .NONE );
396414 }
397415
398416 /**
@@ -430,35 +448,9 @@ public PagedIterable<ArtifactTagProperties> listTagProperties(ArtifactTagOrder o
430448 return listTagPropertiesSync (order , context );
431449 }
432450
433- private PagedIterable <ArtifactTagProperties > listTagPropertiesSync (ArtifactTagOrder order , Context context ) {
434- return new PagedIterable <>(
435- (pageSize ) -> listTagPropertiesSinglePageSync (pageSize , order , context ),
436- (token , pageSize ) -> listTagPropertiesNextSinglePageSync (token , context ));
437- }
438-
439- private PagedResponse <ArtifactTagProperties > listTagPropertiesSinglePageSync (Integer pageSize , ArtifactTagOrder order , Context context ) {
440- if (pageSize != null && pageSize < 0 ) {
441- throw LOGGER .logExceptionAsError (new IllegalArgumentException ("'pageSize' cannot be negative." ));
442- }
443-
444- final String orderString = order .equals (ArtifactTagOrder .NONE ) ? null : order .toString ();
445-
446- String res = this .getDigest ();
447- try {
448- PagedResponse <TagAttributesBase > response =
449- this .serviceClient .getTagsSinglePage (getRepositoryName (), null , pageSize , orderString , res ,
450- enableSync (context ));
451-
452- return UtilsImpl .getPagedResponseWithContinuationToken (response ,
453- baseValues -> UtilsImpl .getTagProperties (baseValues , getRepositoryName ()));
454- } catch (AcrErrorsException exception ) {
455- throw LOGGER .logExceptionAsError (mapAcrErrorsException (exception ));
456- }
457- }
458-
459451 private PagedResponse <ArtifactTagProperties > listTagPropertiesNextSinglePageSync (String nextLink , Context context ) {
460452 try {
461- PagedResponse <TagAttributesBase > res = this . serviceClient .getTagsNextSinglePage (nextLink ,
453+ PagedResponse <TagAttributesBase > res = serviceClient .getTagsNextSinglePage (nextLink ,
462454 enableSync (context ));
463455
464456 return UtilsImpl .getPagedResponseWithContinuationToken (res ,
@@ -520,7 +512,6 @@ public Response<ArtifactTagProperties> updateTagPropertiesWithResponse(String ta
520512 }
521513 }
522514
523-
524515 /**
525516 * Update the properties {@link ArtifactTagProperties} of the given {@code tag}.
526517 * These properties set whether the given tag can be updated, deleted and retrieved.
@@ -548,7 +539,7 @@ public Response<ArtifactTagProperties> updateTagPropertiesWithResponse(String ta
548539 */
549540 @ ServiceMethod (returns = ReturnType .SINGLE )
550541 public ArtifactTagProperties updateTagProperties (String tag , ArtifactTagProperties tagProperties ) {
551- return this . updateTagPropertiesWithResponse (tag , tagProperties , Context .NONE ).getValue ();
542+ return updateTagPropertiesWithResponse (tag , tagProperties , Context .NONE ).getValue ();
552543 }
553544
554545 /**
@@ -597,7 +588,6 @@ public Response<ArtifactManifestProperties> updateManifestPropertiesWithResponse
597588 }
598589 }
599590
600-
601591 /**
602592 * Update the writeable properties {@link ArtifactTagProperties} of the artifact with the given {@code digest}.
603593 * These properties set whether the given manifest can be updated, deleted and retrieved.
@@ -621,6 +611,61 @@ public Response<ArtifactManifestProperties> updateManifestPropertiesWithResponse
621611 */
622612 @ ServiceMethod (returns = ReturnType .SINGLE )
623613 public ArtifactManifestProperties updateManifestProperties (ArtifactManifestProperties manifestProperties ) {
624- return this .updateManifestPropertiesWithResponse (manifestProperties , Context .NONE ).getValue ();
614+ return updateManifestPropertiesWithResponse (manifestProperties , Context .NONE ).getValue ();
615+ }
616+
617+ /**
618+ * Gets the Azure Container Registry service endpoint for the current instance.
619+ * @return The service endpoint for the current instance.
620+ */
621+ public String getRegistryEndpoint () {
622+ return endpoint ;
623+ }
624+
625+ /**
626+ * Gets the fully qualified reference for the current instance.
627+ * The fully qualifiedName is of the form 'registryName/repositoryName@digest'
628+ * or 'registryName/repositoryName:tag' based on the docker naming convention and whether
629+ * tag or digest was supplied to the constructor.
630+ * @return Fully qualified reference of the current instance.
631+ * */
632+ public String getFullyQualifiedReference () {
633+ return fullyQualifiedReference ;
634+ }
635+
636+ /**
637+ * Gets the repository name for the current instance.
638+ * Gets the repository name for the current instance.
639+ * @return Name of the repository for the current instance.
640+ * */
641+ public String getRepositoryName () {
642+ return repositoryName ;
643+ }
644+
645+
646+ private PagedIterable <ArtifactTagProperties > listTagPropertiesSync (ArtifactTagOrder order , Context context ) {
647+ return new PagedIterable <>(
648+ (pageSize ) -> listTagPropertiesSinglePageSync (pageSize , order , context ),
649+ (token , pageSize ) -> listTagPropertiesNextSinglePageSync (token , context ));
650+ }
651+
652+ private PagedResponse <ArtifactTagProperties > listTagPropertiesSinglePageSync (Integer pageSize , ArtifactTagOrder order , Context context ) {
653+ if (pageSize != null && pageSize < 0 ) {
654+ throw LOGGER .logExceptionAsError (new IllegalArgumentException ("'pageSize' cannot be negative." ));
655+ }
656+
657+ final String orderString = order .equals (ArtifactTagOrder .NONE ) ? null : order .toString ();
658+
659+ String res = getDigest ();
660+ try {
661+ PagedResponse <TagAttributesBase > response =
662+ serviceClient .getTagsSinglePage (getRepositoryName (), null , pageSize , orderString , res ,
663+ enableSync (context ));
664+
665+ return UtilsImpl .getPagedResponseWithContinuationToken (response ,
666+ baseValues -> UtilsImpl .getTagProperties (baseValues , getRepositoryName ()));
667+ } catch (AcrErrorsException exception ) {
668+ throw LOGGER .logExceptionAsError (mapAcrErrorsException (exception ));
669+ }
625670 }
626671}
0 commit comments