diff --git a/CarbonQueryDatabase_Adapter/CRUD/Read.cs b/CarbonQueryDatabase_Adapter/CRUD/Read.cs index 780d125..76959e8 100644 --- a/CarbonQueryDatabase_Adapter/CRUD/Read.cs +++ b/CarbonQueryDatabase_Adapter/CRUD/Read.cs @@ -71,11 +71,11 @@ private List ReadEnvironmentalProductDeclaratio GetRequest epdGetRequest; if (id == null) { - epdGetRequest = BH.Engine.Adapters.CarbonQueryDatabase.Create.CarbonQueryDatabaseRequest("epds", m_bearerToken, config); + epdGetRequest = BH.Engine.Adapters.CarbonQueryDatabase.Create.CarbonQueryDatabaseRequest("epds", m_apiToken, config); } else { - epdGetRequest = BH.Engine.Adapters.CarbonQueryDatabase.Create.CarbonQueryDatabaseRequest("epds/" + id, m_bearerToken, config); + epdGetRequest = BH.Engine.Adapters.CarbonQueryDatabase.Create.CarbonQueryDatabaseRequest("epds/" + id, m_apiToken, config); } string reqString = epdGetRequest.ToUrlString(); @@ -84,7 +84,7 @@ private List ReadEnvironmentalProductDeclaratio if (response == null) { - BH.Engine.Base.Compute.RecordWarning("No response received, check bearer token and connection."); + BH.Engine.Base.Compute.RecordWarning("No response received, API token and connection."); return null; } //Check if the response is a valid json diff --git a/CarbonQueryDatabase_Adapter/CarbonQueryDatabase_Adapter.cs b/CarbonQueryDatabase_Adapter/CarbonQueryDatabase_Adapter.cs index 619ad77..8621409 100644 --- a/CarbonQueryDatabase_Adapter/CarbonQueryDatabase_Adapter.cs +++ b/CarbonQueryDatabase_Adapter/CarbonQueryDatabase_Adapter.cs @@ -41,15 +41,15 @@ public partial class CarbonQueryDatabaseAdapter : BHoMAdapter /**** Constructors ****/ /***************************************************/ + [PreviousVersion("6.2", "BH.Adapter.CarbonQueryDatabaseAdapter(System.String, System.String, System.Bool)")] [Description("Adapter to connect to CarbonQueryDatabase.")] - [Input("username", "Provide EC3 Username")] - [Input("password", "Provide EC3 Password")] + [Input("apiToken", "Provide EC3 API Token")] [Output("adapter", "Adapter results")] - public CarbonQueryDatabaseAdapter(string username = "", string password = "", bool active = false) + public CarbonQueryDatabaseAdapter(string apiToken = "", bool active = false) { if (active) { - m_bearerToken = Compute.CQDBearerToken(username, password); + m_apiToken = apiToken; } } @@ -57,7 +57,7 @@ public CarbonQueryDatabaseAdapter(string username = "", string password = "", bo /*** Private Fields ***/ /***************************************************/ - private static string m_bearerToken = null; + private static string m_apiToken = null; } } diff --git a/CarbonQueryDatabase_Adapter/CarbonQueryDatabase_Adapter.csproj b/CarbonQueryDatabase_Adapter/CarbonQueryDatabase_Adapter.csproj index 9e9649f..75d4bab 100644 --- a/CarbonQueryDatabase_Adapter/CarbonQueryDatabase_Adapter.csproj +++ b/CarbonQueryDatabase_Adapter/CarbonQueryDatabase_Adapter.csproj @@ -1,4 +1,4 @@ - + @@ -125,4 +125,4 @@ xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y - + \ No newline at end of file diff --git a/CarbonQueryDatabase_Adapter/Convert/ToBHoM.cs b/CarbonQueryDatabase_Adapter/Convert/ToBHoM.cs index 68d2302..a2bbd5a 100644 --- a/CarbonQueryDatabase_Adapter/Convert/ToBHoM.cs +++ b/CarbonQueryDatabase_Adapter/Convert/ToBHoM.cs @@ -87,12 +87,9 @@ public static EnvironmentalProductDeclaration ToEnvironmentalProductDeclaration( jurisdictionNames = jurisdictionNames.Trim(); } - EnvironmentalMetric metric = new EnvironmentalMetric - { - Field = EnvironmentalProductDeclarationField.GlobalWarmingPotential, - Phases = new List() { LifeCycleAssessmentPhases.A1, LifeCycleAssessmentPhases.A2, LifeCycleAssessmentPhases.A3}, - Quantity = gwpVal, - }; + double nan = double.NaN; + + ClimateChangeTotalMetric metric = new ClimateChangeTotalMetric(nan, nan, nan, gwpVal, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan); AdditionalEPDData data = new AdditionalEPDData { @@ -117,9 +114,8 @@ public static EnvironmentalProductDeclaration ToEnvironmentalProductDeclaration( EnvironmentalProductDeclaration epd = new EnvironmentalProductDeclaration { Type = config.Type, - EnvironmentalMetric = new List { metric }, + EnvironmentalMetrics = new List { metric }, QuantityType = quantityType, - QuantityTypeValue = 1, Name = obj.PropertyValue("name")?.ToString() ?? "", }; diff --git a/CarbonQueryDatabase_Adapter/Properties/AssemblyInfo.cs b/CarbonQueryDatabase_Adapter/Properties/AssemblyInfo.cs index af12ba1..8e8ecb8 100644 --- a/CarbonQueryDatabase_Adapter/Properties/AssemblyInfo.cs +++ b/CarbonQueryDatabase_Adapter/Properties/AssemblyInfo.cs @@ -55,7 +55,7 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyFileVersion("6.1.0.0")] +[assembly: AssemblyFileVersion("6.2.0.0")] diff --git a/CarbonQueryDatabase_Engine/CarbonQueryDatabase_Engine.csproj b/CarbonQueryDatabase_Engine/CarbonQueryDatabase_Engine.csproj index 3fcc743..27a1033 100644 --- a/CarbonQueryDatabase_Engine/CarbonQueryDatabase_Engine.csproj +++ b/CarbonQueryDatabase_Engine/CarbonQueryDatabase_Engine.csproj @@ -32,37 +32,37 @@ - C:\ProgramData\BHoM\Assemblies\Adapter_oM.dll + $(ProgramData)\BHoM\Assemblies\Adapter_oM.dll False False - C:\ProgramData\BHoM\Assemblies\BHoM.dll + $(ProgramData)\BHoM\Assemblies\BHoM.dll False False False - C:\ProgramData\BHoM\Assemblies\BHoM_Engine.dll + $(ProgramData)\BHoM\Assemblies\BHoM_Engine.dll False - C:\ProgramData\BHoM\Assemblies\Data_oM.dll + $(ProgramData)\BHoM\Assemblies\Data_oM.dll False False - C:\ProgramData\BHoM\Assemblies\HTTP_oM.dll + $(ProgramData)\BHoM\Assemblies\HTTP_oM.dll False False - C:\ProgramData\BHoM\Assemblies\LifeCycleAssessment_oM.dll + $(ProgramData)\BHoM\Assemblies\LifeCycleAssessment_oM.dll False False - C:\ProgramData\BHoM\Assemblies\Reflection_Engine.dll + $(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll False False @@ -76,11 +76,11 @@ - + diff --git a/CarbonQueryDatabase_Engine/Compute/BearerToken.cs b/CarbonQueryDatabase_Engine/Compute/BearerToken.cs deleted file mode 100644 index 909353e..0000000 --- a/CarbonQueryDatabase_Engine/Compute/BearerToken.cs +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net; -using System.Net.Http; -using System.ComponentModel; -using BH.oM.Base.Attributes; - -namespace BH.Engine.Adapters.CarbonQueryDatabase -{ - public static partial class Compute - { - [Description("Returns a bearer token for the CarbonQueryDatabase system from the provided username and password")] - [Input("username", "Your username for the system")] - [Input("password", "Your password for the system - case sensitive, do not share scripts with this saved")] - [Output("bearerToken", "The bearer token to use the database system or the full response string if there was an error")] - public static string CQDBearerToken(string username, string password) - { - string apiAddress = "https://etl-api.cqd.io/api/rest-auth/login"; - - System.Net.ServicePointManager.SecurityProtocol = - SecurityProtocolType.Ssl3 | - SecurityProtocolType.Tls12 | - SecurityProtocolType.Tls11 | - SecurityProtocolType.Tls; - - HttpClient client = new HttpClient(); - - //Add headers per api auth requirements - client.DefaultRequestHeaders.Add("accept", "application/json"); - - //Post login auth request and return token to m_bearerKey - HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, apiAddress); - - string loginString = "{\"username\":\"" + username + "\",\"password\":\"" + password + "\"}"; - request.Content = new StringContent(loginString, Encoding.UTF8, "application/json"); - - HttpResponseMessage response = client.SendAsync(request).Result; - if (response.IsSuccessStatusCode) - { - - string responseAuthString = response.Content.ReadAsStringAsync().Result; - if (responseAuthString.Split('"').Length >= 3) - return responseAuthString.Split('"')[3]; - else - { - BH.Engine.Base.Compute.RecordError("We did not receive the response we expected. The response was '" + responseAuthString + "'"); - return null; - } - } - else - { - BH.Engine.Base.Compute.RecordError("Request failed with code '" + response.StatusCode.ToString() + "'. Please check credentials and try again."); - return null; - } - } - } -} - - - diff --git a/CarbonQueryDatabase_Engine/Create/GetRequest.cs b/CarbonQueryDatabase_Engine/Create/GetRequest.cs index a72b96e..c9d614c 100644 --- a/CarbonQueryDatabase_Engine/Create/GetRequest.cs +++ b/CarbonQueryDatabase_Engine/Create/GetRequest.cs @@ -34,12 +34,13 @@ public static partial class Create /***************************************************/ /**** Public Method ****/ /***************************************************/ + [Description("Create a GetRequest for the CarbonQueryDatabase")] - [Input("apiCommand", "The CarbonQueryDatabase REST API command to create a GetRequest with")] - [Input("bearerToken", "The CarbonQueryDatabase bearerToken (this can be acquired using Compute BearerToken with your EC3 username and password)")] + [Input("apiCommand", "The CarbonQueryDatabase API command to create a GetRequest with")] + [Input("apiToken", "The user's CarbonQueryDatabase APIToken")] [Input("parameters", "An optional config object with properties representing parameters to create the GetRequest with (ie count, name_like, etc)")] [Output("GetRequest", "A GetRequest with CarbonQueryDatabase specific headers and uri")] - public static GetRequest CarbonQueryDatabaseRequest(string apiCommand, string bearerToken, CQDConfig parameters = null) + public static GetRequest CarbonQueryDatabaseRequest(string apiCommand, string apiToken, CQDConfig parameters = null) { Dictionary param = new Dictionary(); if(parameters.Count > 0) @@ -50,10 +51,10 @@ public static GetRequest CarbonQueryDatabaseRequest(string apiCommand, string be return new BH.oM.Adapters.HTTP.GetRequest { - BaseUrl = "https://etl-api.cqd.io/api/" + apiCommand, + BaseUrl = "https://buildingtransparency.org/api/" + apiCommand, Headers = new Dictionary() { - { "Authorization", "Bearer " + bearerToken } + { "Authorization", "Bearer " + apiToken } }, Parameters = param }; diff --git a/CarbonQueryDatabase_Engine/Properties/AssemblyInfo.cs b/CarbonQueryDatabase_Engine/Properties/AssemblyInfo.cs index 5a2593f..836902c 100644 --- a/CarbonQueryDatabase_Engine/Properties/AssemblyInfo.cs +++ b/CarbonQueryDatabase_Engine/Properties/AssemblyInfo.cs @@ -55,7 +55,7 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyFileVersion("6.1.0.0")] +[assembly: AssemblyFileVersion("6.2.0.0")] diff --git a/CarbonQueryDatabase_Engine/Versioning_62.json b/CarbonQueryDatabase_Engine/Versioning_62.json new file mode 100644 index 0000000..090e47f --- /dev/null +++ b/CarbonQueryDatabase_Engine/Versioning_62.json @@ -0,0 +1,36 @@ +{ + "Namespace": { + "ToNew": { + }, + "ToOld": { + } + }, + "Type": { + "ToNew": { + + }, + "ToOld": { + + } + }, + "Method": { + "ToNew": { + + }, + "ToOld": { + } + }, + "Property": { + "ToNew": { + + }, + "ToOld": { + + } + }, + "MessageForDeleted": { + "BH.Engine.Adapters.CarbonQueryDatabase.Compute.CQDBearerToken(System.String, System.String)" : "This method has been removed following a refactor to utilise API keys rather than usernames and passwords for security purposes. Please obtain an API key from the provider and plug that into the Adapter to use this toolkit.",}, + "MessageForNoUpgrade": { + + } +} \ No newline at end of file diff --git a/CarbonQueryDatabase_Toolkit.sln b/CarbonQueryDatabase_Toolkit.sln index e7642e0..3917977 100644 --- a/CarbonQueryDatabase_Toolkit.sln +++ b/CarbonQueryDatabase_Toolkit.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 14 for Windows Desktop -VisualStudioVersion = 14.0.25420.1 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33627.172 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarbonQueryDatabase_Adapter", "CarbonQueryDatabase_Adapter\CarbonQueryDatabase_Adapter.csproj", "{C265DA93-8AAB-4B9A-865B-2AA764EB291F}" ProjectSection(ProjectDependencies) = postProject diff --git a/CarbonQueryDatabase_oM/Properties/AssemblyInfo.cs b/CarbonQueryDatabase_oM/Properties/AssemblyInfo.cs index 20649bb..d3fedd4 100644 --- a/CarbonQueryDatabase_oM/Properties/AssemblyInfo.cs +++ b/CarbonQueryDatabase_oM/Properties/AssemblyInfo.cs @@ -55,7 +55,7 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyFileVersion("6.1.0.0")] +[assembly: AssemblyFileVersion("6.2.0.0")]