예제 #1
0
        private static string GetLoginToAwsDockerParams(GetAuthorizationTokenResponse authorizationToken)
        {
            // Check if we have any authorization token returned from AWS. We should have at least one.
            if (!authorizationToken.AuthorizationData.Any())
            {
                throw new Exception(
                          "Did not get authorization token from Amazon. " +
                          "Please try again later. If problem persist contact #watch-ops");
            }

            // Get password from authorization token
            var token = authorizationToken.AuthorizationData[0].AuthorizationToken;

            byte[]   data         = Convert.FromBase64String(token);
            string[] decodedToken = Encoding.UTF8.GetString(data)
                                    .Split(':');

            if (decodedToken.Length != 2)
            {
                throw new Exception(
                          "Retrieved wrong AWS authorization token. Cannot log into AWS. Please contact #watch-ops");
            }

            // Create docker loggin with AWS params
            var password      = decodedToken[1];
            var proxyEndpoint = authorizationToken.AuthorizationData[0].ProxyEndpoint;

            return($"login -u AWS -p {password} {proxyEndpoint}");
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetAuthorizationTokenResponse response = new GetAuthorizationTokenResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("authorizationToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.AuthorizationToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("expiration", targetDepth))
                {
                    var unmarshaller = DateTimeUnmarshaller.Instance;
                    response.Expiration = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
예제 #3
0
        public static GetAuthorizationTokenResponse Unmarshall(UnmarshallerContext context)
        {
            GetAuthorizationTokenResponse getAuthorizationTokenResponse = new GetAuthorizationTokenResponse();

            getAuthorizationTokenResponse.HttpResponse = context.HttpResponse;

            return(getAuthorizationTokenResponse);
        }
예제 #4
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetAuthorizationTokenResponse response = new GetAuthorizationTokenResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("authorizationData", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <AuthorizationData, AuthorizationDataUnmarshaller>(AuthorizationDataUnmarshaller.Instance);
                    response.AuthorizationData = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }