Exemplo n.º 1
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonIoTConfig config = new AmazonIoTConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonIoTClient client = new AmazonIoTClient(creds, config);

            ListOutgoingCertificatesResponse resp = new ListOutgoingCertificatesResponse();

            do
            {
                ListOutgoingCertificatesRequest req = new ListOutgoingCertificatesRequest
                {
                    Marker = resp.NextMarker
                    ,
                    PageSize = maxItems
                };

                resp = client.ListOutgoingCertificates(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.OutgoingCertificates)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextMarker));
        }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonIoTConfig config = new AmazonIoTConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonIoTClient client = new AmazonIoTClient(creds, config);

            ListThingTypesResponse resp = new ListThingTypesResponse();

            do
            {
                ListThingTypesRequest req = new ListThingTypesRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.ListThingTypes(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.ThingTypes)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Exemplo n.º 3
0
        public void Setup()
        {
            IAmazonIoT iotClient = new AmazonIoTClient();
            IAmazonS3  s3Client  = new AmazonS3Client();
            IS3CertificateStorageConfigs s3CertificateStorageConfigs = new HardCodedConfigProvider();
            ICertificateStore            certificateStore            = new S3CertificateStorage(s3Client, s3CertificateStorageConfigs);

            _amazonManager = new AwsIotThingManager(iotClient, certificateStore);
        }
Exemplo n.º 4
0
        public AWSClientsService(IConfiguration config)
        {
            _config = config;
            var awsCredentials = new BasicAWSCredentials(_config["AWS:ApiAccessKey"], _config["AWS:ApiSecretKey"]);

            IoTClient     = new AmazonIoTClient(awsCredentials, RegionEndpoint.GetBySystemName(_config["AWS:Region"]));
            IoTDataClient = new AmazonIotDataClient("https://" + _config["AWS:IoTEndpoint"], awsCredentials);
            IoTJobClient  = new AmazonIoTJobsDataPlaneClient("https://" + _config["AWS:IoTEndpoint"], awsCredentials);
            S3Client      = new AmazonS3Client(awsCredentials, RegionEndpoint.GetBySystemName(_config["AWS:Region"]));
        }
Exemplo n.º 5
0
        protected IAmazonIoT CreateClient(AWSCredentials credentials, RegionEndpoint region)
        {
            var config = new AmazonIoTConfig {
                RegionEndpoint = region
            };

            Amazon.PowerShell.Utils.Common.PopulateConfig(this, config);
            this.CustomizeClientConfig(config);
            var client = new AmazonIoTClient(credentials, config);

            client.BeforeRequestEvent += RequestEventHandler;
            client.AfterResponseEvent += ResponseEventHandler;
            return(client);
        }
Exemplo n.º 6
0
        public static void Cleanup()
        {
            if (!string.IsNullOrEmpty(CREATED_THING_NAME))
            {
                using (var iotClient = new AmazonIoTClient())
                {
                    iotClient.DeleteThing(CREATED_THING_NAME);
                }
            }

            if (Client != null)
            {
                Client.Dispose();
            }
        }
Exemplo n.º 7
0
        public static void ClassInitialize(TestContext testContext)
        {
            Client = new AmazonIotDataClient("https://data.iot.us-east-1.amazonaws.com/");

            using (var iotClient = new AmazonIoTClient())
            {
                var things     = iotClient.ListThings().Things;
                var firstThing = things.FirstOrDefault();
                if (firstThing == null)
                {
                    THING_NAME = "dotnettest" + DateTime.UtcNow.ToFileTime();
                    iotClient.CreateThing(new CreateThingRequest
                    {
                        ThingName = THING_NAME
                    });
                    CREATED_THING_NAME = THING_NAME;
                }
                else
                {
                    THING_NAME = firstThing.ThingName;
                }
            }
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Credentials credentials = null;
            string      accountId   = null;
            string      roleName    = null;

            if (args.Length == 2)
            {
                Console.WriteLine("Account ID and role name specified, publishing cross-account");
                accountId   = args[0];
                roleName    = args[1];
                credentials = GetCrossAccountCredentials(accountId, roleName);
            }
            else
            {
                Console.WriteLine("An invalid number of options was specified, cannot continue");
                Environment.Exit(1);
            }

            Console.WriteLine("Setting region to us-east-1");
            var myRegion = Amazon.RegionEndpoint.USEast1;

            Console.WriteLine("Creating IoT client");
            AmazonIoTClient myIotClient = new AmazonIoTClient(credentials, myRegion);

            Console.WriteLine(("Obtaining customer specific endpoint information for publishing messages to IoT Core"));

            try
            {
                var describeEndpointResponse = myIotClient.DescribeEndpointAsync(new DescribeEndpointRequest()).Result;
                var endpointAddress          = "https://" + describeEndpointResponse.EndpointAddress;

                Console.WriteLine("Starting infinite publish loop");

                Console.WriteLine("Creating IoT data client for message publishing");
                AmazonIotDataClient myIotDataClient = new AmazonIotDataClient(endpointAddress, credentials);

                while (true)
                {
                    if (credentials != null)
                    {
                        Console.WriteLine("Refreshing cross-account credentials and IoT data client");
                        credentials     = GetCrossAccountCredentials(accountId, roleName);
                        myIotDataClient = new AmazonIotDataClient(endpointAddress, credentials);
                    }

                    Console.WriteLine("Creating a publish request with a test message");

                    // This is done inside the loop because re-using publish requests does not work on Mono on Linux
                    var publishRequest = new PublishRequest();
                    publishRequest.Qos     = 0;
                    publishRequest.Topic   = Constants.Topic;
                    publishRequest.Payload = new MemoryStream(Encoding.UTF8.GetBytes(Constants.Payload ?? ""));

                    var publishResponse = myIotDataClient.PublishAsync(publishRequest).Result;
                    Console.WriteLine("Published message, sleeping...");
                    Console.WriteLine(publishResponse.HttpStatusCode.ToString());
                    Thread.Sleep(Constants.SleepTime);
                }
            }
            catch (AggregateException e)
            {
                // Simple check to see if the error looks like a missing role
                if (e.Message.Contains("does not indicate success"))
                {
                    Console.WriteLine(
                        "Failed to obtain the customer endpoint information or publish a message, is a role attached to this EC2 instance?");
                }
                else if (e.Message.Contains("is not authorized"))
                {
                    Console.WriteLine(
                        "Access denied when obtaining the customer endpoint information or when publishing a message, does the role attached to this EC2 instance have the correct permissions?");
                }
                else
                {
                    Console.WriteLine("FAIL Main");
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                }

                Environment.Exit(1);
            }
        }