-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change cleans up core spinwick creation logic in preparation for adding tests.
- Loading branch information
1 parent
2692386
commit 657580d
Showing
5 changed files
with
87 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,34 @@ | ||
package cloudtools | ||
|
||
import ( | ||
"fmt" | ||
|
||
cloudModel "github.com/mattermost/mattermost-cloud/model" | ||
cloud "github.com/mattermost/mattermost-cloud/model" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// GetInstallationIDFromOwnerID returns the ID of an installation that matches | ||
// a given OwnerID. Multiple matches will return an error. No match will return | ||
// GetInstallationIDFromOwnerID returns the installation that matches a given | ||
// OwnerID. Multiple matches will return an error. No match will return | ||
// an empty ID and no error. | ||
func GetInstallationIDFromOwnerID(serverURL, awsAPIKey, ownerID string) (string, string, error) { | ||
func GetInstallationIDFromOwnerID(serverURL, awsAPIKey, ownerID string) (*cloud.InstallationDTO, error) { | ||
headers := map[string]string{ | ||
"x-api-key": awsAPIKey, | ||
} | ||
cloudClient := cloudModel.NewClientWithHeaders(serverURL, headers) | ||
installations, err := cloudClient.GetInstallations(&cloudModel.GetInstallationsRequest{ | ||
OwnerID: ownerID, | ||
Paging: cloudModel.Paging{ | ||
Page: 0, | ||
PerPage: 100, | ||
IncludeDeleted: false, | ||
}, | ||
cloudClient := cloud.NewClientWithHeaders(serverURL, headers) | ||
installations, err := cloudClient.GetInstallations(&cloud.GetInstallationsRequest{ | ||
OwnerID: ownerID, | ||
Paging: cloud.AllPagesNotDeleted(), | ||
IncludeGroupConfig: false, | ||
IncludeGroupConfigOverrides: false, | ||
}) | ||
if err != nil { | ||
return "", "", err | ||
return nil, errors.Wrap(err, "failed to retrieve installations from provisioner") | ||
} | ||
|
||
if len(installations) == 0 { | ||
return "", "", nil | ||
return nil, nil | ||
} | ||
if len(installations) == 1 { | ||
return installations[0].ID, installations[0].Image, nil | ||
return installations[0], nil | ||
} | ||
|
||
return "", "", fmt.Errorf("found %d installations with ownerID %s", len(installations), ownerID) | ||
return nil, errors.Errorf("found %d installations with ownerID %s", len(installations), ownerID) | ||
} |
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
Oops, something went wrong.