/// <param name="body">A valid ServiceManagement v1 body.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Submit(ServiceManagementService service, string serviceName, SubmitConfigSourceRequest body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (serviceName == null)
                {
                    throw new ArgumentNullException(serviceName);
                }

                // Make the request.
                return(service.Configs.Submit(body, serviceName).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Configs.Submit failed.", ex);
            }
        }
        public async Task TestCheckServicesStatusAsyncSinglePage()
        {
            var responses = new[]
            {
                new ListServicesResponse
                {
                    Services = new List <ManagedService>
                    {
                        new ManagedService {
                            ServiceName = Service1
                        },
                        new ManagedService {
                            ServiceName = Service3
                        }
                    }
                }
            };
            ServiceManagementService service = GetMockedService(
                (ServiceManagementService s) => s.Services,
                t => t.List(),
                responses);

            var dataSource    = new ServiceManagementDataSource(service, ProjectName);
            var actualResults = (await dataSource.CheckServicesStatusAsync(new[] { Service1, Service2, Service3 })).ToList();

            var expectedResults = new[]
            {
                new ServiceStatus(Service1, true),
                new ServiceStatus(Service2, false),
                new ServiceStatus(Service3, true)
            };

            Assert.AreEqual(expectedResults.Length, actualResults.Count);
            CollectionAssert.AreEqual(expectedResults, actualResults);
        }
        /// Documentation https://developers.google.com/servicemanagement/v1/reference/operations/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated ServiceManagement service.</param>
        /// <param name="name">The name of the operation resource.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Get(ServiceManagementService service, string name)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (name == null)
                {
                    throw new ArgumentNullException(name);
                }

                // Make the request.
                return(service.Operations.Get(name).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Operations.Get failed.", ex);
            }
        }
Beispiel #4
0
        public IHttpActionResult EnableAPIs(string projectID)
        {
            try
            {
                var service = new ServiceManagementService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = AppFlowMetadata.UserCredential,
                    ApplicationName       = AppFlowMetadata.AppName,
                });

                EnableServiceRequest servReq1 = new EnableServiceRequest()
                {
                    ConsumerId = "project:" + projectID
                };
                var enableReq1 = service.Services.Enable(servReq1, "gmail.googleapis.com");
                var res1       = enableReq1.Execute();

                EnableServiceRequest servReq2 = new EnableServiceRequest()
                {
                    ConsumerId = "project:" + projectID
                };
                var enableReq2 = service.Services.Enable(servReq2, "calendar-json.googleapis.com");
                var res2       = enableReq2.Execute();

                EnableServiceRequest servReq3 = new EnableServiceRequest()
                {
                    ConsumerId = "project:" + projectID
                };
                var enableReq3 = service.Services.Enable(servReq3, "contacts.googleapis.com");
                var res3       = enableReq3.Execute();
            }
            catch (Exception)
            {
            }

            return(Ok());
        }
Beispiel #5
0
        private bool EnableAPIs(UserCredential userCredential, string projectID)
        {
            try
            {
                var service = new ServiceManagementService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = userCredential,
                    ApplicationName       = AppName,
                });

                EnableServiceRequest servReq = new EnableServiceRequest()
                {
                    ConsumerId = "project:" + projectID
                };
                var enableReq = service.Services.Enable(servReq, "gmail.googleapis.com");

                var res = enableReq.Execute();
            }
            catch (Exception)
            {
            }

            return(true);
        }
 public ServiceManagementManager(ServiceManagementService serviceManagementService, UrlValidationService urlValidationService)
 {
     _serviceManagementService = serviceManagementService;
     _urlValidationService     = urlValidationService;
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            /////////////////// MAKING TOKENS /////////////////
            //var jwtService = new JWTService();

            //var token = jwtService.GenerateHmacSignedJWTToken("myClient", "read", Constants.Issuer, DateTime.Now.ToUniversalTime(), DateTime.Now.AddDays(10).ToUniversalTime(),
            //                                        Constants.SigningKey);
            //// now we have string repre of token lets validate it

            //var handler = new JwtSecurityTokenHandler().ReadJwtToken(token);

            //var claims = handler.Claims.Where(x => x.Type == "aud").FirstOrDefault().Value;


            ////foreach (var item in claims)
            ////{
            ////    Console.WriteLine(item);
            ////}
            //Console.WriteLine(claims);
            //// create fake key.

            //Console.WriteLine(token);



            /////////////////////// TESTING TOKEN VALIDITY /////////////////////////
            //var validationReq = new TokenValidationParameters();
            //validationReq.IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("asdasds"));
            //validationReq.ValidAudience = "myClient";
            //validationReq.ValidateAudience = true;
            //validationReq.ValidIssuer = Constants.Issuer;

            //validationReq.ValidateIssuerSigningKey = true;
            //validationReq.RequireSignedTokens = true;
            //validationReq.ValidateIssuer = true;
            //validationReq.ValidateLifetime = true;

            //Console.WriteLine(token);

            //var evilToken = token + "asdasd";


            //var outToken = handler.ReadToken(token);


            //var result = handler.ValidateToken(token, validationReq, out outToken);

            //Console.WriteLine(result);



            //////////////////////// RANDOM TEST /////////////////

            var sms = new ServiceManagementService(new ApiGatewayContext());

            var usernames = sms.GetAllowedConfigurationUsers("panic");

            //var teams = sms.GetTeamsUsername();

            //foreach(var t in teams)
            //{
            //    Console.WriteLine(t);
            //}


            //var configjson = JsonSerializer.Deserialize<ServiceConfiguration>(config);  // system.text

            using var _apiGatewayContext = new ApiGatewayContext();
            var resource   = "asdasda";
            var scopeclaim = "jasonjason";

            var owner = from team in _apiGatewayContext.Team
                        join service in _apiGatewayContext.Service on team.ClientId equals service.Owner
                        where resource == service.Endpoint && scopeclaim == team.Username
                        select team.Username;

            var balh = "asdasd";
        }