Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ManagementApiClient"/> class.
        /// </summary>
        /// <param name="token">A valid Auth0 Management API v2 token.</param>
        /// <param name="baseUri"><see cref="Uri"/> of the tenant to manage.</param>
        /// <param name="managementConnection"><see cref="IManagementConnection"/> to facilitate communication with server.</param>
        public ManagementApiClient(string token, Uri baseUri, IManagementConnection managementConnection = null)
        {
            if (managementConnection == null)
            {
                var ownedManagementConnection = new HttpClientManagementConnection();
                managementConnection = ownedManagementConnection;
                connectionToDispose  = ownedManagementConnection;
            }

            var defaultHeaders = CreateDefaultHeaders(token);

            BlacklistedTokens = new BlacklistedTokensClient(managementConnection, baseUri, defaultHeaders);
            ClientGrants      = new ClientGrantsClient(managementConnection, baseUri, defaultHeaders);
            Clients           = new ClientsClient(managementConnection, baseUri, defaultHeaders);
            Connections       = new ConnectionsClient(managementConnection, baseUri, defaultHeaders);
            CustomDomains     = new CustomDomainsClient(managementConnection, baseUri, defaultHeaders);
            DeviceCredentials = new DeviceCredentialsClient(managementConnection, baseUri, defaultHeaders);
            EmailProvider     = new EmailProviderClient(managementConnection, baseUri, defaultHeaders);
            EmailTemplates    = new EmailTemplatesClient(managementConnection, baseUri, defaultHeaders);
            Guardian          = new GuardianClient(managementConnection, baseUri, defaultHeaders);
            Jobs            = new JobsClient(managementConnection, baseUri, defaultHeaders);
            Logs            = new LogsClient(managementConnection, baseUri, defaultHeaders);
            ResourceServers = new ResourceServersClient(managementConnection, baseUri, defaultHeaders);
            Roles           = new RolesClient(managementConnection, baseUri, defaultHeaders);
            Rules           = new RulesClient(managementConnection, baseUri, defaultHeaders);
            Stats           = new StatsClient(managementConnection, baseUri, defaultHeaders);
            TenantSettings  = new TenantSettingsClient(managementConnection, baseUri, defaultHeaders);
            Tickets         = new TicketsClient(managementConnection, baseUri, defaultHeaders);
            UserBlocks      = new UserBlocksClient(managementConnection, baseUri, defaultHeaders);
            Users           = new UsersClient(managementConnection, baseUri, defaultHeaders);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ManagementApiClient"/> class.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="baseUri">The base URI.</param>
        /// <param name="diagnostics">The diagnostics.</param>
        /// <param name="handler">The <see cref="HttpMessageHandler"/> which is used for HTTP requests</param>
        public ManagementApiClient(string token, Uri baseUri, DiagnosticsHeader diagnostics, HttpMessageHandler handler)
        {
            // If no diagnostics header structure was specified, then revert to the default one
            if (diagnostics == null)
            {
                diagnostics = DiagnosticsHeader.Default;
            }

            apiConnection = new ApiConnection(token, baseUri.AbsoluteUri, diagnostics, handler);

            BlacklistedTokens = new BlacklistedTokensClient(apiConnection);
            ClientGrants      = new ClientGrantsClient(apiConnection);
            Clients           = new ClientsClient(apiConnection);
            Connections       = new ConnectionsClient(apiConnection);
            DeviceCredentials = new DeviceCredentialsClient(apiConnection);
            EmailProvider     = new EmailProviderClient(apiConnection);
            Jobs            = new JobsClient(apiConnection);
            Logs            = new LogsClient(apiConnection);
            ResourceServers = new ResourceServersClient(apiConnection);
            Rules           = new RulesClient(apiConnection);
            Stats           = new StatsClient(apiConnection);
            TenantSettings  = new TentantSettingsClient(apiConnection);
            Tickets         = new TicketsClient(apiConnection);
            UserBlocks      = new UserBlocksClient(apiConnection);
            Users           = new UsersClient(apiConnection);
        }
Пример #3
0
        public async Task JobsClient_WaitFor_Stops_After_MaxWait()
        {
            var i          = 0;
            var j          = 0;
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Get <Job>(ApiUrls.JobsShow("j123abc"), null))
            .ReturnsAsync(() =>
            {
                var json     = System.IO.File.ReadAllText("./Fixtures/Jobs_Show.json");
                var result   = JsonConvert.DeserializeObject <Job>(json);
                result.State = JobState.Pending;
                Thread.Sleep(101);
                i++;
                return(result);
            });

            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            Job job            = null;
            await Assert.ThrowsExceptionAsync <TimeoutException>(async() =>
            {
                await jobsClient.Waitfor("j123abc", JobState.Running, pollIntervalMS: 10, maxWaitMS: 200, (m) =>
                {
                    job = m;
                    j++;
                });
            });

            Assert.AreEqual(JobState.Pending, job.State);
            Assert.AreEqual(2, i);
            Assert.AreEqual(2, j);
        }
Пример #4
0
        public async Task JobsClient_List_With_Filter()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Get <IList <Job> >(ApiUrls.JobsList(), It.IsAny <IDictionary <string, string> >()))
            .ReturnsAsync(() =>
            {
                var json = System.IO.File.ReadAllText("./Fixtures/Jobs_List.json");
                return(JsonConvert.DeserializeObject <IList <Job> >(json));
            });

            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            var result         = await jobsClient.List(new JobFilter()
            {
                Command     = "foo",
                Container   = "bar",
                Dataset     = "foo",
                MachineType = MachineType.Advanced,
                Name        = "foo",
                Project     = "foo",
                ProjectId   = "foobar",
                State       = JobState.Pending,
                Workspace   = "asdf"
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
        }
Пример #5
0
        public async void can_create_job_with_prefill()
        {
            JobsClient jobs = new JobsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);

            JobDetail jobDetail = new JobDetail("TITLE-01");

            jobDetail.key         = "KEY-01";
            jobDetail.description = "DESCRIPTION-01";
            jobDetail.type        = "TYPE-01";

            TestJobPrefillData preFill = new TestJobPrefillData();

            preFill.fieldA = "abc";
            preFill.fieldB = "def";
            preFill.fieldC = "ghi";

            Job newJob = new Job(
                details: jobDetail,
                formId: formId,
                username: "******"
                );

            Job response = await jobs.CreateJob <TestJobPrefillData>(newJob, preFill);

            Assert.NotNull(response);
            Assert.NotNull(response.id);

            await jobs.DeleteJob(response.id);
        }
Пример #6
0
        public void JobsClient_Can_Construct()
        {
            var connection     = new Mock <IConnection>();
            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);

            Assert.IsNotNull(jobsClient);
        }
Пример #7
0
        public async void can_search_by_form_id()
        {
            JobsClient jobs = new JobsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);

            int formId = 476;

            JobsSearchResult response = await jobs.SearchByFormId(formId);

            Assert.NotNull(response);
        }
Пример #8
0
 public async Task JobsClient_WaitFor_Throws_If_Invalid_Target_State()
 {
     var connection     = new Mock <IConnection>();
     var logsConnection = new Mock <IConnection>();
     var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
     await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() =>
     {
         await jobsClient.Waitfor("j123abc", JobState.Cancelled);
     });
 }
Пример #9
0
        public async void can_search_by_external_id()
        {
            JobsClient jobs = new JobsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);

            string externalId = "EXT-01";

            JobsSearchResult response = await jobs.SearchByExternalId(externalId);

            Assert.NotNull(response);
        }
Пример #10
0
        public async void can_search_by_username()
        {
            JobsClient jobs = new JobsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);

            string username = "******";

            JobsSearchResult response = await jobs.SearchByUsername(username);

            Assert.NotNull(response);
        }
Пример #11
0
 public void throws_error_if_keys_empty()
 {
     try
     {
         JobsClient jobs = new JobsClient("", "");
     }
     catch (Exception ex)
     {
         Assert.NotNull(ex);
     }
 }
Пример #12
0
        public async void can_create_job_with_priority()
        {
            JobsClient jobs = new JobsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);

            JobDetail jobDetail = new JobDetail(title: "TITLE-01", priority: 1);

            Job newJob = new Job(details: jobDetail, formId: formId, username: "******");

            Job response = await jobs.CreateJob(newJob);

            Assert.NotNull(response);
            Assert.NotNull(response.id);

            await jobs.DeleteJob(response.id);
        }
Пример #13
0
        public async void can_search_with_multiple_fields()
        {
            JobsClient jobs = new JobsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);

            JobsSearchParameters searchParams = new JobsSearchParameters()
            {
                externalId = "EXT-01",
                username   = "******",
                formId     = 476
            };

            JobsSearchResult response = await jobs.SearchJobs(searchParams);

            Assert.NotNull(response);
        }
Пример #14
0
        public async Task JobsClient_ArtifactsList_HappyPath()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Get <IList <Artifact> >(ApiUrls.JobsArtifactsList("j123abc"), null))
            .ReturnsAsync(() =>
            {
                var json = System.IO.File.ReadAllText("./Fixtures/Jobs_ArtifactsList.json");
                return(JsonConvert.DeserializeObject <IList <Artifact> >(json));
            });
            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            var result         = await jobsClient.ArtifactsList("j123abc");

            Assert.AreEqual(2, result.Count);
        }
Пример #15
0
        public async void can_delete_job()
        {
            JobsClient jobs = new JobsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);

            JobDetail jobDetail = new JobDetail("TITLE-01");

            Job newJob = new Job(
                details: jobDetail,
                formId: formId,
                username: "******"
                );

            Job job = await jobs.CreateJob(newJob);

            await jobs.DeleteJob(job.id);
        }
Пример #16
0
        public async Task JobsClient_Logs_HappyPath()
        {
            var connection     = new Mock <IConnection>();
            var logsConnection = new Mock <IConnection>();

            logsConnection.Setup(c => c.Get <IList <JobLog> >(ApiUrls.JobsLogs("j123abc"), null))
            .ReturnsAsync(() =>
            {
                var json = System.IO.File.ReadAllText("./Fixtures/Jobs_Logs.json");
                return(JsonConvert.DeserializeObject <IList <JobLog> >(json));
            });

            var jobsClient = new JobsClient(connection.Object, logsConnection.Object);
            var logs       = await jobsClient.Logs("j123abc");

            Assert.IsNotNull(logs);
        }
Пример #17
0
        public async Task JobsClient_ArtifactsGet_HappyPath()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Get <JObject>(ApiUrls.JobsArtifactsGet("j123abc"), null))
            .ReturnsAsync(() =>
            {
                var json = System.IO.File.ReadAllText("./Fixtures/Jobs_ArtifactsGet.json");
                return(JObject.Parse(json));
            });

            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            var result         = await jobsClient.ArtifactsGet("j123abc");

            Assert.IsNotNull(result);
        }
Пример #18
0
        public async Task JobsClient_Clone_HappyPath()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Post <Job>(ApiUrls.JobsClone("j123abc"), null, null, null, null))
            .ReturnsAsync(() =>
            {
                var json = System.IO.File.ReadAllText("./Fixtures/Jobs_Show.json");
                return(JsonConvert.DeserializeObject <Job>(json));
            });

            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            var result         = await jobsClient.Clone("j123abc");

            Assert.IsNotNull(result);
        }
Пример #19
0
        public async Task JobsClient_MachineTypes_HappyPath()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Get <IList <JobMachine> >(ApiUrls.JobsMachineTypes(), null))
            .ReturnsAsync(() =>
            {
                var json = System.IO.File.ReadAllText("./Fixtures/Jobs_MachineTypes.json");
                return(JsonConvert.DeserializeObject <IList <JobMachine> >(json));
            });

            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            var result         = await jobsClient.MachineTypes();

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Count);
        }
Пример #20
0
        public async Task JobsClient_ArtifactsGet_With_Parameters()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Get <JObject>(ApiUrls.JobsArtifactsGet("j123abc"), It.IsAny <IDictionary <string, string> >()))
            .ReturnsAsync(() =>
            {
                var json = System.IO.File.ReadAllText("./Fixtures/Jobs_ArtifactsGet.json");
                return(JObject.Parse(json));
            });
            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            var result         = await jobsClient.ArtifactsGet("j123abc", new GetArtifactsParameters()
            {
                Files = "myfiles*"
            });

            Assert.IsNotNull(result);
        }
Пример #21
0
        public async Task JobsClient_Stop_HappyPath()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Post(ApiUrls.JobsStop("j123abc"), null, null))
            .Returns(() =>
            {
                return(Task.CompletedTask);
            });

            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            await jobsClient.Stop("j123abc");

            connection.Verify(
                c => c.Post(ApiUrls.JobsStop("j123abc"), null, null),
                Times.Exactly(1)
                );
        }
Пример #22
0
        public async void throws_error_if_title_empty()
        {
            try
            {
                JobsClient jobs = new JobsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);

                JobDetail jobDetail = new JobDetail("");

                Job newJob = new Job(
                    details: jobDetail,
                    formId: formId,
                    username: "******"
                    );

                Job job = await jobs.CreateJob(newJob);
            }
            catch (Exception ex)
            {
                Assert.NotNull(ex);
            }
        }
Пример #23
0
        public async Task JobsClient_ArtifactsList_With_Parameters()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Get <IList <Artifact> >(ApiUrls.JobsArtifactsList("j123abc"), It.IsAny <IDictionary <string, string> >()))
            .ReturnsAsync(() =>
            {
                var json = System.IO.File.ReadAllText("./Fixtures/Jobs_ArtifactsList.json");
                return(JsonConvert.DeserializeObject <IList <Artifact> >(json));
            });
            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            var result         = await jobsClient.ArtifactsList("j123abc", new ListArtifactsParameters()
            {
                Files = "myfiles*",
                Size  = true,
                Links = true,
            });

            Assert.AreEqual(2, result.Count);
        }
Пример #24
0
        public async Task JobsClient_Create_HappyPath()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Post <Job>(ApiUrls.JobsCreate(), null, It.IsAny <object>(), null, null))
            .ReturnsAsync(() =>
            {
                var json = System.IO.File.ReadAllText("./Fixtures/Jobs_Create.json");
                return(JsonConvert.DeserializeObject <Job>(json));
            });

            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            var result         = await jobsClient.Create(new CreateJobRequest()
            {
                Container   = "http://dockerhub.com/mycontainer",
                MachineType = MachineType.P5000
            });

            Assert.IsNotNull(result);
        }
Пример #25
0
        public async Task JobsClient_WaitFor_HappyPath()
        {
            var i          = 0;
            var j          = 0;
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Get <Job>(ApiUrls.JobsShow("j123abc"), null))
            .ReturnsAsync(() =>
            {
                var json   = System.IO.File.ReadAllText("./Fixtures/Jobs_Show.json");
                var result = JsonConvert.DeserializeObject <Job>(json);

                if (i >= 0 && i < 4)
                {
                    result.State = JobState.Pending;
                }
                else if (i >= 4 && i < 9)
                {
                    result.State = JobState.Running;
                }
                else if (i >= 9)
                {
                    result.State = JobState.Stopped;
                }

                i++;
                return(result);
            });

            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            var machine        = await jobsClient.Waitfor("j123abc", JobState.Stopped, pollIntervalMS : 1, maxWaitMS : 0, (m) =>
            {
                j++;
            });

            Assert.AreEqual(JobState.Stopped, machine.State);
            Assert.AreEqual(10, i);
            Assert.AreEqual(10, j);
        }
Пример #26
0
        private ManagementApiClient(string token, Uri baseUri, DiagnosticsHeader diagnostics,
                                    ApiConnection apiConnection)
        {
            _apiConnection = apiConnection;

            BlacklistedTokens = new BlacklistedTokensClient(_apiConnection);
            ClientGrants      = new ClientGrantsClient(_apiConnection);
            Clients           = new ClientsClient(_apiConnection);
            Connections       = new ConnectionsClient(_apiConnection);
            DeviceCredentials = new DeviceCredentialsClient(_apiConnection);
            EmailProvider     = new EmailProviderClient(_apiConnection);
            EmailTemplates    = new EmailTemplatesClient(_apiConnection);
            Jobs            = new JobsClient(_apiConnection);
            Logs            = new LogsClient(_apiConnection);
            ResourceServers = new ResourceServersClient(_apiConnection);
            Rules           = new RulesClient(_apiConnection);
            Stats           = new StatsClient(_apiConnection);
            TenantSettings  = new TenantSettingsClient(_apiConnection);
            Tickets         = new TicketsClient(_apiConnection);
            UserBlocks      = new UserBlocksClient(_apiConnection);
            Users           = new UsersClient(_apiConnection);
        }
Пример #27
0
        public async void can_create_job_without_prefill()
        {
            JobsClient jobs = new JobsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);

            JobDetail jobDetail = new JobDetail("TITLE-01");

            jobDetail.key         = "KEY-01";
            jobDetail.description = "DESCRIPTION-01";
            jobDetail.type        = "TYPE-01";

            Job newJob = new Job(
                details: jobDetail,
                formId: formId,
                username: "******"
                );
            Job response = await jobs.CreateJob(newJob);

            Assert.NotNull(response);
            Assert.NotNull(response.id);

            await jobs.DeleteJob(response.id);
        }
Пример #28
0
        public async Task JobsClient_ArtifactsDestroy_With_Parameters()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Post(ApiUrls.JobsArtifactsDestroy("j123abc"), It.IsAny <IDictionary <string, string> >(), null))
            .Returns(() =>
            {
                return(Task.CompletedTask);
            });

            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            await jobsClient.ArtifactsDestroy("j123abc", new DestroyArtifactsParameters()
            {
                Files = "myfiles*"
            });

            connection.Verify(
                c => c.Post(ApiUrls.JobsArtifactsDestroy("j123abc"), It.IsAny <IDictionary <string, string> >(), null),
                Times.Exactly(1)
                );
        }
Пример #29
0
        private ManagementApiClient(ApiConnection apiConnection)
        {
            _apiConnection = apiConnection;

            BlacklistedTokens = new BlacklistedTokensClient(_apiConnection);
            ClientGrants      = new ClientGrantsClient(_apiConnection);
            Clients           = new ClientsClient(_apiConnection);
            Connections       = new ConnectionsClient(_apiConnection);
            CustomDomains     = new CustomDomainsClient(_apiConnection);
            DeviceCredentials = new DeviceCredentialsClient(_apiConnection);
            EmailProvider     = new EmailProviderClient(_apiConnection);
            EmailTemplates    = new EmailTemplatesClient(_apiConnection);
            Guardian          = new GuardianClient(_apiConnection);
            Jobs            = new JobsClient(_apiConnection);
            Logs            = new LogsClient(_apiConnection);
            ResourceServers = new ResourceServersClient(_apiConnection);
            Roles           = new RolesClient(_apiConnection);
            Rules           = new RulesClient(_apiConnection);
            Stats           = new StatsClient(_apiConnection);
            TenantSettings  = new TenantSettingsClient(_apiConnection);
            Tickets         = new TicketsClient(_apiConnection);
            UserBlocks      = new UserBlocksClient(_apiConnection);
            Users           = new UsersClient(_apiConnection);
        }
Пример #30
0
        public async Task JobsClient_MachineTypes_With_Filter()
        {
            var connection = new Mock <IConnection>();

            connection.Setup(c => c.Get <IList <JobMachine> >(ApiUrls.JobsMachineTypes(), It.IsAny <IDictionary <string, string> >()))
            .ReturnsAsync(() =>
            {
                var json = System.IO.File.ReadAllText("./Fixtures/Jobs_MachineTypes.json");
                return(JsonConvert.DeserializeObject <IList <JobMachine> >(json));
            });

            var logsConnection = new Mock <IConnection>();
            var jobsClient     = new JobsClient(connection.Object, logsConnection.Object);
            var result         = await jobsClient.MachineTypes(new MachineTypeFilter()
            {
                Cluster     = "1sdf",
                MachineType = MachineType.K80,
                Region      = Region.Europe_AMS1,
                IsBusy      = false
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Count);
        }