-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#22 Create Openstack config does not work properly since it requires …
…list projects first
- Loading branch information
Victor Getz
authored and
victorgetz
committed
Apr 13, 2023
1 parent
6574982
commit b49d3d6
Showing
5 changed files
with
58 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package iam | ||
|
||
import ( | ||
"fmt" | ||
"github.com/go-http-utils/headers" | ||
"net/http" | ||
"otc-auth/common" | ||
"otc-auth/common/endpoints" | ||
"otc-auth/common/headervalues" | ||
"otc-auth/common/xheaders" | ||
"otc-auth/config" | ||
"strings" | ||
) | ||
|
||
func GetProjectsInActiveCloud() config.Projects { | ||
projectsResponse := getProjectsFromServiceProvider() | ||
var projects config.Projects | ||
for _, project := range projectsResponse.Projects { | ||
projects = append(projects, config.Project{ | ||
NameAndIdResource: config.NameAndIdResource{Name: project.Name, Id: project.Id}, | ||
}) | ||
} | ||
|
||
config.UpdateProjects(projects) | ||
println(fmt.Sprintf("Projects for active cloud:\n%s", strings.Join(projects.GetProjectNames(), ",\n"))) | ||
return projects | ||
} | ||
|
||
func CreateScopedTokenForEveryProject(projectNames []string) { | ||
for _, projectName := range projectNames { | ||
GetScopedToken(projectName) | ||
} | ||
} | ||
|
||
func getProjectsFromServiceProvider() (projectsResponse common.ProjectsResponse) { | ||
cloud := config.GetActiveCloudConfig() | ||
println(fmt.Sprintf("info: fetching projects for cloud %s", cloud.Domain.Name)) | ||
|
||
request := common.GetRequest(http.MethodGet, endpoints.IamProjects, nil) | ||
request.Header.Add(headers.ContentType, headervalues.ApplicationJson) | ||
request.Header.Add(xheaders.XAuthToken, cloud.UnscopedToken.Secret) | ||
|
||
response := common.HttpClientMakeRequest(request) | ||
bodyBytes := common.GetBodyBytesFromResponse(response) | ||
projectsResponse = *common.DeserializeJsonForType[common.ProjectsResponse](bodyBytes) | ||
|
||
return projectsResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters