コード例 #1
0
 public Container(AccessDetail access, EndpointDetail endpoint)
 {
     Access       = access;
     Endpoint     = endpoint;
     Client       = new RestClient(Endpoint.PublicUrl);
     ObjectManage = new ContainerObject(access, endpoint);
 }
コード例 #2
0
        // David Fouler would really like us not to do this
        // https://github.com/aspnet/KestrelHttpServer/issues/2306#issuecomment-364478486
        public EndpointDetailsViewModel HackEndpointDetails()
        {
            var model = new EndpointDetailsViewModel();

            try {
                KestrelServer kestrel = server as KestrelServer;
                if (kestrel == null)
                {
                    model.NotKestrel = true;
                    return(model);
                }

                KestrelServerOptions options = kestrel.Options;
                // reflect out the ListenOptions array
                Type                 kestrelServerOptionsType = typeof(KestrelServerOptions);
                PropertyInfo         listenOptionsProp        = kestrelServerOptionsType.GetProperty("ListenOptions", BindingFlags.Instance | BindingFlags.NonPublic);
                List <ListenOptions> listenOptions            = (List <ListenOptions>)listenOptionsProp.GetValue(options);

                foreach (ListenOptions listenOption in listenOptions)
                {
                    if (listenOption.ConnectionAdapters?.Count > 0)
                    {
                        foreach (IConnectionAdapter connectionAdapter in listenOption.ConnectionAdapters)
                        {
                            // Grab all the details for this endpoint
                            EndpointDetail endpointDetail = new EndpointDetail {
                                Address = listenOption.IPEndPoint.Address.ToString(),
                                Port    = listenOption.IPEndPoint.Port,
                                IsHttps = connectionAdapter.IsHttps
                            };
                            if (connectionAdapter is HttpsConnectionAdapter)
                            {
                                endpointDetail.Certificate = typeof(HttpsConnectionAdapter).GetField("_serverCertificate", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(connectionAdapter) as X509Certificate2;
                            }

                            model.EndpointDetails.Add(endpointDetail);
                        }
                    }
                    else
                    {
                        model.EndpointDetails.Add(new EndpointDetail {
                            Address = listenOption.IPEndPoint.Address.ToString(),
                            Port    = listenOption.IPEndPoint.Port,
                            IsHttps = false
                        });
                    }
                }

                // Reflect the dev cert
                model.IsDevCertLoaded    = (bool)(kestrelServerOptionsType.GetProperty("IsDevCertLoaded", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(options));
                model.DefaultCertificate = kestrelServerOptionsType.GetProperty("DefaultCertificate", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(options) as X509Certificate2;
            } catch (Exception ex) {
                // because this is hacky enough that it'll likely fall down easily
                model.Exception = ex.Message;
            }
            return(model);
        }
        // David Fowler would really like us not to do this
        // https://github.com/aspnet/KestrelHttpServer/issues/2306#issuecomment-364478486
        public EndpointDetailsViewModel HackEndpointDetails()
        {
            var model = new EndpointDetailsViewModel();

            try
            {
                KestrelServer kestrel = server as KestrelServer;
                if (kestrel == null)
                {
                    model.NotKestrel = true;
                    return(model);
                }

                KestrelServerOptions options = kestrel.Options;

                // reflection voodoo
                Type                 kestrelServerOptionsType = typeof(KestrelServerOptions);
                PropertyInfo         listenOptionsProp        = kestrelServerOptionsType.GetProperty("ListenOptions", BindingFlags.Instance | BindingFlags.NonPublic);
                PropertyInfo         isTlsProp     = typeof(ListenOptions).GetProperty("IsTls", BindingFlags.Instance | BindingFlags.NonPublic);
                List <ListenOptions> listenOptions = (List <ListenOptions>)listenOptionsProp.GetValue(options);

                foreach (ListenOptions listenOption in listenOptions)
                {
                    bool isTls = (bool)isTlsProp.GetValue(listenOption);

                    // Grab all the details for this endpoint
                    EndpointDetail endpointDetail = new EndpointDetail
                    {
                        Address = listenOption.IPEndPoint.Address.ToString(),
                        Port    = listenOption.IPEndPoint.Port,
                        IsHttps = isTls
                    };
                    model.EndpointDetails.Add(endpointDetail);

                    if (isTls)
                    {
                        // it appears all middleware is configured for all listenOptions even if they aren't https
                        endpointDetail.Certificate = GetCertificateFromOptions(listenOption);
                    }
                }

                // Reflect the dev cert
                model.IsDevCertLoaded    = (bool)(kestrelServerOptionsType.GetProperty("IsDevCertLoaded", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(options));
                model.DefaultCertificate = kestrelServerOptionsType.GetProperty("DefaultCertificate", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(options) as X509Certificate2;
            }
            catch (Exception ex)
            {
                // because this is hacky enough that it'll likely fall down easily
                model.Exception = ex.Message;
            }
            return(model);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <ICommandCreator, CommandCreator>()
                                  .BuildServiceProvider();

            var commandCreator = serviceProvider.GetService <ICommandCreator>();

            var endpoint = new EndpointDetail()
            {
                Description    = "Retrieve a role.",
                HttpAction     = "Get",
                Path           = "/v1/roles/{RoleId}",
                Resource       = "Role",
                PathParameters = new List <PathParameter>()
                {
                    new PathParameter()
                    {
                        Name        = "RoleId",
                        Type        = "string",
                        Format      = "uuid",
                        Required    = true,
                        Description = "Unique ID of the role."
                    }
                }
            };

            // Create a query interface
            var generatedQueryInterface = commandCreator.CreateInterface(new QueryInterfaceDefinition(endpoint));

            Console.WriteLine("generatedQueryInterface:");
            Console.WriteLine(generatedQueryInterface);
            Console.WriteLine();

            // Create a command interface
            var generatedCommandInterface = commandCreator.CreateInterface(new CommandInterfaceDefinition(endpoint));

            Console.WriteLine("generatedCommandInterface:");
            Console.WriteLine(generatedCommandInterface);
            Console.WriteLine();

            // Create a command
            var generatedCommand = commandCreator.CreateClass(new CommandDefinition());

            Console.WriteLine("generatedCommand:");
            Console.WriteLine(generatedCommand);

            // Wait to exit.
            Console.Read();
        }
コード例 #5
0
ファイル: OvhStorage.cs プロジェクト: smietanka/OvhNet
        /// <summary>
        /// Make connection to OpenStack
        /// </summary>
        private void Connection()
        {
            var requestBody = new
            {
                auth = new
                {
                    passwordCredentials = new
                    {
                        username = UserName,
                        password = Password
                    },
                    tenantId = TenantId
                }
            };

            var request = new RestRequest("/tokens", Method.POST);

            request.AddHeader("Accept", "application/json");
            request.AddJsonBody(requestBody);
            var response = Client.Execute(request);

            if (ResponseError(response, true))
            {
                AccessRoot accesTo = JsonConvert.DeserializeObject <AccessRoot>(response.Content);
                Access = accesTo.Access;
                var tempService = Access.ServiceCatalog.Where(z => z.Type.Equals("object-store")).FirstOrDefault();
                if (tempService != null)
                {
                    ObjectStorageService = tempService;
                }
                else
                {
                    throw new System.Exception("Cannot find object storage service in access");
                }
                var tempRegion = ObjectStorageService.Endpoints.Where(z => z.Region.Equals(Region)).FirstOrDefault();
                if (tempRegion != null)
                {
                    CurrentRegionEndpoint = tempRegion;
                }
                else
                {
                    throw new System.Exception("Cannot find endpoint in storage service");
                }
            }

            //Initialize manages
            Container       = new Container(Access, CurrentRegionEndpoint);
            ContainerObject = new ContainerObject(Access, CurrentRegionEndpoint);
        }
コード例 #6
0
        private async Task SetSecretAsync(string secretName, EndpointDetail endpoint)
        {
            if (string.IsNullOrEmpty(secretName))
            {
                secretName = Guid.NewGuid().ToString();
            }

            endpoint.ApplicationSecretId = secretName;

            await vault.SetSecretAsync(
                endpoint.ApplicationSecretId,
                endpoint.ApplicationSecret,
                "text/plain").ConfigureAwait(false);

            endpoint.ApplicationSecret = null;
        }