예제 #1
0
        public async Task UpdateAcrTagAttributesMR()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(UpdateAcrTagAttributesMR)))
            {
                var updateAttributes = new ChangeableAttributes()
                {
                    DeleteEnabled = true, ListEnabled = true, ReadEnabled = true, WriteEnabled = false
                };
                var tag    = "latest";
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                await client.UpdateAcrTagAttributesAsync(ACRTestUtil.ProdRepository, tag, updateAttributes);

                var tagAttributes = await client.GetAcrTagAttributesAsync(ACRTestUtil.ProdRepository, tag);

                Assert.False(tagAttributes.TagAttributes.ChangeableAttributes.WriteEnabled);

                updateAttributes.WriteEnabled = true;
                await client.UpdateAcrTagAttributesAsync(ACRTestUtil.ProdRepository, tag, updateAttributes);

                tagAttributes = await client.GetAcrTagAttributesAsync(ACRTestUtil.ProdRepository, tag);

                Assert.True(tagAttributes.TagAttributes.ChangeableAttributes.WriteEnabled);
            }
        }
예제 #2
0
        public async Task UpdateAcrManifestAttributesMR()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(UpdateAcrManifestAttributesMR)))
            {
                var updateAttributes = new ChangeableAttributes()
                {
                    DeleteEnabled = true, ListEnabled = true, ReadEnabled = true, WriteEnabled = false
                };
                var digest = "sha256:eabe547f78d4c18c708dd97ec3166cf7464cc651f1cbb67e70d407405b7ad7b6";
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                await client.UpdateAcrManifestAttributesAsync(ACRTestUtil.ProdRepository, digest, updateAttributes);

                var updatedManifest = await client.GetAcrManifestAttributesAsync(ACRTestUtil.ProdRepository, digest);

                Assert.False(updatedManifest.Manifest.ChangeableAttributes.WriteEnabled);

                updateAttributes.WriteEnabled = true;
                await client.UpdateAcrManifestAttributesAsync(ACRTestUtil.ProdRepository, digest, updateAttributes);

                updatedManifest = await client.GetAcrManifestAttributesAsync(ACRTestUtil.ProdRepository, digest);

                Assert.Equal(ExpectedAttributesOfProdRepository.ImageName, updatedManifest.ImageName);
                Assert.Equal(ExpectedAttributesOfProdRepository.Registry, updatedManifest.Registry);
                VerifyAcrManifestAttributesBase(ExpectedAttributesOfProdRepository.Manifest, updatedManifest.Manifest);
            }
        }
예제 #3
0
        public async Task UpdateAcrManifestAttributes()
        {
            using (var context = MockContext.Start(GetType(), nameof(UpdateAcrManifestAttributes)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistryForChanges);

                var updateAttributes = new ChangeableAttributes()
                {
                    DeleteEnabled = true, ListEnabled = true, ReadEnabled = true, WriteEnabled = false
                };
                var digest = "sha256:dbefd3c583a226ddcef02536cd761d2d86dc7e6f21c53f83957736d6246e9ed8";

                //Update attributes
                await client.Manifests.UpdateAttributesAsync(ACRTestUtil.changeableRepository, digest, updateAttributes);

                var updatedManifest = await client.Manifests.GetAttributesAsync(ACRTestUtil.changeableRepository, digest);

                //Check for success
                Assert.False(updatedManifest.Attributes.ChangeableAttributes.WriteEnabled);

                //Return attributes to original
                updateAttributes.WriteEnabled = true;
                await client.Manifests.UpdateAttributesAsync(ACRTestUtil.changeableRepository, digest, updateAttributes);

                updatedManifest = await client.Manifests.GetAttributesAsync(ACRTestUtil.changeableRepository, digest);

                Assert.Equal(ExpectedAttributesChangeableRepository.ImageName, updatedManifest.ImageName);
                Assert.Equal(ExpectedAttributesChangeableRepository.Registry, updatedManifest.Registry);
                VerifyAcrManifestAttributesBase(ExpectedAttributesChangeableRepository.Attributes, updatedManifest.Attributes);
            }
        }
 public PSChangeableAttribute(ChangeableAttributes attribute)
 {
     DeleteEnabled = attribute?.DeleteEnabled;
     WriteEnabled  = attribute?.WriteEnabled;
     ListEnabled   = attribute?.ListEnabled;
     ReadEnabled   = attribute?.ReadEnabled;
 }
예제 #5
0
        public async Task UpdateAcrRepositoryAttributesMR()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(UpdateAcrRepositoryAttributesMR)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var updateAttributes = new ChangeableAttributes()
                {
                    DeleteEnabled = true, ListEnabled = true, ReadEnabled = true, WriteEnabled = false
                };
                await client.UpdateAcrRepositoryAttributesAsync(ACRTestUtil.ProdRepository, updateAttributes);

                var repositoryDetails = await client.GetAcrRepositoryAttributesAsync(ACRTestUtil.ProdRepository);

                Assert.Equal(ACRTestUtil.ManagedTestRegistryFullName, repositoryDetails.Registry);
                Assert.Equal(1, repositoryDetails.TagCount);
                Assert.Equal(1, repositoryDetails.ManifestCount);
                Assert.Equal("2018-09-28T23:37:52.0356217Z", repositoryDetails.LastUpdateTime);
                Assert.Equal("2018-09-28T23:37:51.9668212Z", repositoryDetails.CreatedTime);
                Assert.Equal(ACRTestUtil.ProdRepository, repositoryDetails.ImageName);
                Assert.True(repositoryDetails.ChangeableAttributes.DeleteEnabled);
                Assert.True(repositoryDetails.ChangeableAttributes.ListEnabled);
                Assert.True(repositoryDetails.ChangeableAttributes.ReadEnabled);
                Assert.False(repositoryDetails.ChangeableAttributes.WriteEnabled);

                updateAttributes.WriteEnabled = true;
                await client.UpdateAcrRepositoryAttributesAsync(ACRTestUtil.ProdRepository, updateAttributes);
            }
        }
예제 #6
0
        public async Task UpdateAcrRepositoryAttributes()
        {
            using (var context = MockContext.Start(GetType(), nameof(UpdateAcrRepositoryAttributes)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistryForChanges);

                //Changeable attributes
                var updateAttributes = new ChangeableAttributes()
                {
                    DeleteEnabled = false, ListEnabled = true, ReadEnabled = true, WriteEnabled = false
                };
                await client.Repository.UpdateAttributesAsync(ACRTestUtil.changeableRepository, updateAttributes);

                var repositoryDetails = await client.Repository.GetAttributesAsync(ACRTestUtil.changeableRepository);

                //Undo change in remote (in case this fails)
                updateAttributes.WriteEnabled  = true;
                updateAttributes.DeleteEnabled = true;
                await client.Repository.UpdateAttributesAsync(ACRTestUtil.changeableRepository, updateAttributes);

                //Check success
                Assert.Equal(1, repositoryDetails.TagCount);
                Assert.Equal(1, repositoryDetails.ManifestCount);
                Assert.Equal(ACRTestUtil.changeableRepository, repositoryDetails.ImageName);
                Assert.False(repositoryDetails.ChangeableAttributes.DeleteEnabled);
                Assert.True(repositoryDetails.ChangeableAttributes.ListEnabled);
                Assert.True(repositoryDetails.ChangeableAttributes.ReadEnabled);
                Assert.False(repositoryDetails.ChangeableAttributes.WriteEnabled);
            }
        }
 internal TagAttributesBase(string name, string digest, string createdTime, string lastUpdateTime, bool?signed, ChangeableAttributes changeableAttributes)
 {
     Name                 = name;
     Digest               = digest;
     CreatedTime          = createdTime;
     LastUpdateTime       = lastUpdateTime;
     Signed               = signed;
     ChangeableAttributes = changeableAttributes;
 }
예제 #8
0
 internal RepositoryAttributes(string registry, string imageName, string createdTime, string lastUpdateTime, int?manifestCount, int?tagCount, ChangeableAttributes changeableAttributes)
 {
     Registry             = registry;
     ImageName            = imageName;
     CreatedTime          = createdTime;
     LastUpdateTime       = lastUpdateTime;
     ManifestCount        = manifestCount;
     TagCount             = tagCount;
     ChangeableAttributes = changeableAttributes;
 }
예제 #9
0
 /// <summary>
 /// Update tag attributes
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='name'>
 /// Name of the image (including the namespace)
 /// </param>
 /// <param name='reference'>
 /// Tag name
 /// </param>
 /// <param name='value'>
 /// Repository attribute value
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task UpdateAttributesAsync(this ITagOperations operations, string name, string reference, ChangeableAttributes value = default(ChangeableAttributes), CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.UpdateAttributesWithHttpMessagesAsync(name, reference, value, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
예제 #10
0
 /// <summary>
 /// Update attributes of a repository
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='name'>
 /// Name of the image (including the namespace)
 /// </param>
 /// <param name='value'>
 /// Repository attribute value
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task UpdateAcrRepositoryAttributesAsync(this IAzureContainerRegistryClient operations, string name, ChangeableAttributes value = default(ChangeableAttributes), CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.UpdateAcrRepositoryAttributesWithHttpMessagesAsync(name, value, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
예제 #11
0
        /// <summary>
        /// Update tag attributes
        /// </summary>
        /// <param name='name'>
        /// Name of the image (including the namespace)
        /// </param>
        /// <param name='reference'>
        /// Tag name
        /// </param>
        /// <param name='value'>
        /// Repository attribute value
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <exception cref="AcrErrorsException">
        /// Thrown when the operation returned an invalid status code
        /// </exception>
        /// <exception cref="ValidationException">
        /// Thrown when a required parameter is null
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when a required parameter is null
        /// </exception>
        /// <return>
        /// A response object containing the response body and response headers.
        /// </return>
        public async Task <AzureOperationResponse> UpdateAttributesWithHttpMessagesAsync(string name, string reference, ChangeableAttributes value = default(ChangeableAttributes), Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (Client.LoginUri == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.LoginUri");
            }
            if (name == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "name");
            }
            if (reference == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "reference");
            }
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("name", name);
                tracingParameters.Add("reference", reference);
                tracingParameters.Add("value", value);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "UpdateAttributes", tracingParameters);
            }
            // Construct URL
            var _baseUrl = Client.BaseUri;
            var _url     = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "acr/v1/{name}/_tags/{reference}";

            _url = _url.Replace("{url}", Client.LoginUri);
            _url = _url.Replace("{name}", System.Uri.EscapeDataString(name));
            _url = _url.Replace("{reference}", System.Uri.EscapeDataString(reference));
            List <string> _queryParameters = new List <string>();

            if (_queryParameters.Count > 0)
            {
                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
            }
            // Create HTTP transport objects
            var _httpRequest = new HttpRequestMessage();
            HttpResponseMessage _httpResponse = null;

            _httpRequest.Method     = new HttpMethod("PATCH");
            _httpRequest.RequestUri = new System.Uri(_url);
            // Set Headers
            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
            {
                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString());
            }
            if (Client.AcceptLanguage != null)
            {
                if (_httpRequest.Headers.Contains("accept-language"))
                {
                    _httpRequest.Headers.Remove("accept-language");
                }
                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
            }


            if (customHeaders != null)
            {
                foreach (var _header in customHeaders)
                {
                    if (_httpRequest.Headers.Contains(_header.Key))
                    {
                        _httpRequest.Headers.Remove(_header.Key);
                    }
                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
                }
            }

            // Serialize Request
            string _requestContent = null;

            if (value != null)
            {
                _requestContent      = Rest.Serialization.SafeJsonConvert.SerializeObject(value, Client.SerializationSettings);
                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
                _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
            }
            // Set Credentials
            if (Client.Credentials != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
            }
            // Send Request
            if (_shouldTrace)
            {
                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

            if (_shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
            }
            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string _responseContent = null;

            if ((int)_statusCode != 200)
            {
                var ex = new AcrErrorsException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                try
                {
                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    AcrErrors _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <AcrErrors>(_responseContent, Client.DeserializationSettings);
                    if (_errorBody != null)
                    {
                        ex.Body = _errorBody;
                    }
                }
                catch (JsonException)
                {
                    // Ignore the exception
                }
                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new AzureOperationResponse();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            if (_httpResponse.Headers.Contains("x-ms-request-id"))
            {
                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
            }
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }
 public PSTagAttributeBase(string name = default(string), string digest = default(string), string createdTime = default(string), string lastUpdateTime = default(string), bool?signed = default(bool?), ChangeableAttributes changeableAttributes = default(ChangeableAttributes))
 {
     Name                 = name;
     Digest               = digest;
     CreatedTime          = createdTime;
     LastUpdateTime       = lastUpdateTime;
     Signed               = signed;
     ChangeableAttributes = new PSChangeableAttribute(changeableAttributes);
 }